Пример #1
0
 public void ShowUsage()
 {
     foreach (var par in parameters)
     {
         Cout.Write(" " + par.Name);
     }
 }
Пример #2
0
        public void ShowUsage()
        {
            Cout.Write("Usage: " + path);

            foreach (var opt in options)
            {
                Cout.Write(" [-" + opt.Key);
                opt.Value.ShowUsage();
                Cout.Write("]");
            }

            Cout.WriteLine();
        }
Пример #3
0
            public void ShowHelp()
            {
                if (parameters.Count > 0)
                {
                    foreach (var par in parameters)
                    {
                        Cout.Write(" " + par.Name + "\t");
                    }
                }
                else
                {
                    Cout.Write("\t\t");
                }

                Cout.Write(comment);
            }
Пример #4
0
        public bool Process(string[] args)
        {
            Queue <string> arguments = new Queue <string>(args.Length);

            foreach (var arg in args)
            {
                arguments.Enqueue(arg);
            }

            while (arguments.Count > 0)
            {
                string arg = arguments.Dequeue();

                if ((arg.Length != 2) || (arg[0] != '-'))
                {
                    Cout.WriteLine($"Unknown command line parameter: \"{arg}\"");
                    continue;
                }

                char key = arg[1];

                if (!options.ContainsKey(key))
                {
                    ShowHelp();
                    return(false);
                }

                Option opt = options[key];

                List <string> parameters = new List <string>();

                while (arguments.Count > 0 && (arguments.Peek()[0] != '-'))
                {
                    parameters.Add(arguments.Dequeue());
                }

                if (!opt.Process(parameters))
                {
                    ShowHelp();
                    return(false);
                }
            }

            return(true);
        }
Пример #5
0
        public void ShowHelp()
        {
            ShowUsage();

            Cout.WriteLine();

            foreach (var opt in options)
            {
                Cout.Write("\t-" + opt.Key);
                opt.Value.ShowHelp();
                Cout.WriteLine();
            }

            if (!string.IsNullOrWhiteSpace(comment))
            {
                Cout.WriteLine();
                Cout.WriteLine(comment);
            }
        }
Пример #6
0
            public void ShowHelp()
            {
                string possibleValues = "";

                if (parameters.Count > 0)
                {
                    int length = 0;

                    foreach (var par in parameters)
                    {
                        Cout.Write(" " + par.Name);
                        length += par.Name.Length + 1;

                        if (par.PossibleValues != null)
                        {
                            possibleValues += SplitToLines("  " + par.Name + ": " + par.PossibleValues, 2 + CommentRowOffset, par.Name.Length + 2) + Environment.NewLine;
                        }
                    }

                    if (length < CommentRowOffset)
                    {
                        Cout.Write(new string(' ', CommentRowOffset - length));
                    }
                    else
                    {
                        Cout.Write(" ");
                    }
                }
                else
                {
                    Cout.Write(new string(' ', CommentRowOffset));
                }

                Cout.Write(SplitToLines(comment, 2 + CommentRowOffset).TrimEnd());

                if (possibleValues.Length > 0)
                {
                    Cout.Write(Environment.NewLine + "\t" + new string(' ', CommentRowOffset) + possibleValues.TrimEnd());
                }
            }