Esempio n. 1
0
        public void PrintCommandDescription(string command)
        {
            var phaseSequence = PhaseListProvider.GetPhaseSequence(command);

            var parameterDescriptions = new Dictionary <string, string>();
            var requiredParameters    = new HashSet <string>();
            var secureParameters      = new HashSet <string>();

            foreach (var phase in phaseSequence)
            {
                phase.Parameters.ToList().ForEach(p => {
                    if (p.Required)
                    {
                        requiredParameters.Add(p.Name);
                    }

                    if (p.Secure)
                    {
                        secureParameters.Add(p.Name);
                    }

                    if (p.Description != null)
                    {
                        parameterDescriptions.Add(p.Name, p.Description);
                    }
                });
            }
            Console.WriteLine(this.MakeSentence(phaseSequence.Last().Description));
            Console.WriteLine($"Parameters for the `{command}` command: \n");

            foreach (var kvp in parameterDescriptions)
            {
                var name = kvp.Key;
                Console.WriteLine($"-{name}");
                Console.Write($"\t{kvp.Value} ");

                if (requiredParameters.Contains(name) && !this.parameterPool.ContainsKey(name))
                {
                    Console.WriteLine("(required)");
                }
                else
                {
                    if (this.parameterPool.ContainsKey(name))
                    {
                        var defaultValue = parameterPool[name];

                        if (secureParameters.Contains(name))
                        {
                            defaultValue = this.SanitizeSecureString(defaultValue);
                        }

                        Console.WriteLine($"[{defaultValue}]");
                    }
                    else
                    {
                        Console.WriteLine("(optional)");
                    }
                }
            }
        }
Esempio n. 2
0
        static int Main(string[] args)
        {
            var parameterPool = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                { Constants.SolutionsDirectoryParameterName, Constants.SolutionsDirectory },
                { Constants.PackagesDirectoryParameterName, Constants.PackagesDirectory },
                { Constants.SolutionStorageConnectionStringParameterName, Constants.SolutionStorageConnectionString }
            };

            InformationPrinter info = new InformationPrinter(parameterPool);

            if (args.Length == 0)
            {
                info.PrintUsage();
                return(1);
            }

            if (args[0].Equals("help", StringComparison.InvariantCultureIgnoreCase))
            {
                if (args.Length == 2)
                {
                    info.PrintCommandDescription(args[1]);
                }
                else
                {
                    info.PrintAvailableCommands();
                }

                return(0);
            }

            var clArgsParser  = new CommandLineArgumentsParser(args);
            var command       = clArgsParser.Command;
            var phaseSequence = PhaseListProvider.GetPhaseSequence(command);

            clArgsParser.Parameters.ToList().ForEach(p => parameterPool[p.Key] = p.Value);

            var phaseSequenceExecutor = new PhaseSequenceExecutor(phaseSequence, parameterPool);

            phaseSequenceExecutor.Run();

            return(0);
        }