示例#1
0
        public Analyser(Options opts)
        {
            OctopusProjectsSection octopusConfig = System.Configuration.ConfigurationManager.GetSection("OctopusProjects") as OctopusProjectsSection;

            var octopusHost = string.IsNullOrEmpty(opts.OctopusUrl) ? octopusConfig.Host : opts.OctopusUrl;
            var apiKey      = string.IsNullOrEmpty(opts.ApiKey) ? octopusConfig.ApiKey : opts.ApiKey;

            this.Options = opts;

            if (string.IsNullOrWhiteSpace(octopusHost))
            {
                throw new ArgumentException("Octopus URL should be provided. See help (--help)");
            }

            if (string.IsNullOrWhiteSpace(apiKey))
            {
                throw new ArgumentException("ApiKey should be provided. See help (--help)");
            }

            var endpoint = new OctopusServerEndpoint(octopusHost, apiKey);

            this.OctopusRepository = new OctopusRepository(endpoint);
        }
示例#2
0
        static void Main(string[] args)
        {
            Console.Clear();

            CommandLine.Parser.Default.ParseArguments <Options>(args)
            .WithParsed(opts =>
            {
                IEnumerable <OctopusProject> projects = new List <OctopusProject>();

                if (!string.IsNullOrWhiteSpace(opts.OctopusProjectName))
                {
                    if (string.IsNullOrEmpty(opts.ConfigFilePath))
                    {
                        throw new ArgumentException("--octopus-project-name should be used in combination with --config-file-path");
                    }

                    projects = new List <OctopusProject>
                    {
                        new OctopusProject
                        {
                            Name = opts.OctopusProjectName,
                            Path = opts.ConfigFilePath
                        }
                    };
                }
                else
                {
                    OctopusProjectsSection octopusConfig = System.Configuration.ConfigurationManager.GetSection("OctopusProjects") as OctopusProjectsSection;

                    projects = octopusConfig.Projects;
                }

                if (!projects.Any())
                {
                    Console.WriteLine("No project to analyse. Please add at least one");
                    return;
                }

                var analyser = new Analyser(opts);

                try
                {
                    projects.ToList().ForEach(project =>
                    {
                        AnalysisResult result = analyser.Run(project);
                        Display(result, opts, project);

                        if (opts.PaginateResults && !projects.Last().Equals(project))
                        {
                            Console.WriteLine("Press enter to display next page...");
                            Console.ReadLine();
                            Console.Clear();
                        }
                    });
                }
                catch (Exception e)
                {
                    Console.WriteLine("An error occured");
                }
            });
        }