Inheritance: SolutionMaker.Core.SolutionOptions
        public static CommandLineOptions Parse(string[] args)
        {
            var options = new CommandLineOptions();
            options.SolutionFile = string.Empty;
            var optionType = OptionType.None;

            foreach (string arg in args)
            {
                if (arg.StartsWith("-") || arg.StartsWith("/"))
                {
                    optionType = options.ParseOptionType(arg.Substring(1));
                }
                else
                {
                    try
                    {
                        options.ParseOptionArgument(optionType, arg);
                        optionType = OptionType.None;
                    }
                    catch (CommandLineOptionException)
                    {
                        throw;
                    }
                    catch (Exception ex)
                    {
                        throw new CommandLineOptionException("Invalid command line option: {0}: {1}", arg, ex.Message);
                    }
                }
            }

            if (!string.IsNullOrEmpty(options.SolutionFile))
                options.SolutionFolderPath = Path.GetDirectoryName(options.SolutionFile);

            return options;
        }
Exemple #2
0
        private static void GenerateSolutionFile(CommandLineOptions options)
        {
            if (!Directory.Exists(options.ProjectRootFolderPath))
            {
                throw new SolutionFileGenerationException("Invalid directory: " + options.ProjectRootFolderPath);
            }
            else if (File.Exists(options.SolutionFile) && ((File.GetAttributes(options.SolutionFile) & FileAttributes.ReadOnly) != 0) && !options.OverwriteReadOnlyFile)
            {
                throw new SolutionFileGenerationException("Solution file is read-only. Use /r option to overwrite read-only solution file.");
            }
            else
            {
                if (File.Exists(options.SolutionFile))
                {
                    var fileAttributes = File.GetAttributes(options.SolutionFile);
                    if ((fileAttributes & FileAttributes.ReadOnly) != 0 && options.OverwriteReadOnlyFile)
                    {
                        File.SetAttributes(options.SolutionFile, fileAttributes ^ FileAttributes.ReadOnly);
                    }
                }

                SolutionGenerator generator = new SolutionGenerator(new ConsoleLogger());
                generator.GenerateSolution(options.SolutionFile, options);

                string message;
                if (generator.NumberOfProjectsFound > 0)
                {
                    message = string.Format("Solution file is generated\r\n{0} projects found\r\n{1} projects skipped\r\n{2} projects added\r\n{3} projects removed",
                        generator.NumberOfProjectsFound, generator.NumberOfProjectsSkipped, generator.NumberOfProjectsAdded, generator.NumberOfProjectsRemoved);
                }
                else
                {
                    message = string.Format("No project files found in the specified location\r\nSolution file is not generated");
                }
                Console.WriteLine();
                Console.WriteLine(message);
            }
        }