/// <summary>
        /// This is the default description provider which will enumerate the options.
        /// </summary>
        /// <param name="obj">Not used main instance.</param>
        private void ProvideDescriptionWhenNoOpsDone(CommandLineManager obj)
        {
            StringBuilder sb = new StringBuilder();

            var PrimaryOptions = Options.Where(opt => opt.AssociatedWithOptions != null)
                                 .ToList();

            if (PrimaryOptions.Any() == false) // Just show all options, there is not enough info to format with suboptions
            {
                Options.ForEach(opt =>
                {
                    //  if (opt.IsOptional)
                    //       sb.Append("\t");

                    sb.AppendLine(opt.ToString());
                });
            }
            else
            {
                // Find any options that don't have siblings nor are associated with a parent option and add them to the primary list to be displayed.
                Options.Where(opt => opt.AssociatedWithOptions == null && PrimaryOptions.All(prim => prim.AssociatedWithOptions.Contains(opt.Letter) == false))
                .ToList()
                .ForEach(solo => PrimaryOptions.Add(solo));

                PrimaryOptions.Select(prime => new
                {
                    Prime      = prime,
                    SubOptions = Options.Where(opt => prime.AssociatedWithOptions?.Contains(opt.Letter) ?? false)
                                 .ToList()
                })
                .ToList()
                .ForEach(optimus =>
                {
                    sb.AppendLine($"{optimus.Prime.ToString()} using");
                    optimus.SubOptions?.ForEach(sub => sb.AppendLine($"\t{sub.ToString()}"));
                    sb.AppendLine(string.Empty);
                });
            }

            Console.WriteLine(sb.ToString());
        }
Ejemplo n.º 2
0
 /// <summary>
 /// If a dash is not required, the an option can be designated without the dash such as `-L` can also be `L`. Hence it is "FreeForm".
 /// </summary>
 public static CommandLineManager AllowFreeForm(this CommandLineManager manager)
 {
     return(manager?.AllowFreeForm());
 }
Ejemplo n.º 3
0
 public static CommandLineManager Parse(this CommandLineManager manager, string[] args)
 {
     return(manager.Parse(args));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Execute the arguments, pass in arguments if <see cref="Parse"/> has not been called with arguments.
 /// </summary>
 /// <param name="manager">Target manager for the fluent chaining flow.</param>
 /// <param name="args">Optionals arguments when arguments have not been passed in.</param>
 public static void Execute(this CommandLineManager manager, string[] args = null)
 {
     manager.ExecuteOperation(args);
 }