예제 #1
0
 /// <summary>
 ///  Prints help about a certain configuration field
 /// </summary>
 /// <param name="fieldAttribute">The field attribute to print help for</param>
 /// <param name="width">The width of the console</param>
 /// <param name="indent">The indent to use</param>
 /// <param name="tw">The Textwriter to write the help to</param>
 public static void ConfigurationFieldHelp(CmdConfigurationFieldAttribute fieldAttribute, int width, int indent = 3,
                                           TextWriter tw = null)
 {
     tw = tw ?? Console.Out;
     tw.Write(CommandlineMethods.PadCentered(
                  $"{fieldAttribute.Name} (R{(fieldAttribute.IsReadonly ? "W" : "O")},{fieldAttribute.UnderlyingPropertyOrFieldInfo.ValueType})",
                  width));
     if (fieldAttribute.LongDescription is null)
     {
         if (fieldAttribute.Description is null)
         {
             tw.WriteLine("This value has no further description");
         }
         else
         {
             CommandlineMethods.PrintWithPotentialIndent(fieldAttribute.Description, width, indent, tw);
         }
     }
     else
     {
         foreach (string s in fieldAttribute.LongDescription)
         {
             CommandlineMethods.PrintWithPotentialIndent(s, width, 0, tw);
         }
     }
 }
예제 #2
0
        /// <summary>
        ///  Prints help for a configurationNamespace
        /// </summary>
        /// <param name="namespaceAttribute">The configurationNamespace to print help for</param>
        /// <param name="width">The width of the console</param>
        /// <param name="indent">The indent to use</param>
        /// <param name="tw">The Textwriter to write the help to</param>
        public static void ConfigurationNamespaceHelp(CmdConfigurationNamespaceAttribute namespaceAttribute, int width, int indent = 3,
                                                      TextWriter tw = null)
        {
            tw = tw ?? Console.Out;

            tw.Write(
                CommandlineMethods.PadCentered($"{namespaceAttribute.Name}{(namespaceAttribute.IsReadonly ? " (RW)" : "")}", width));
            if (!(namespaceAttribute.LongDescription is null))
            {
                foreach (string s in namespaceAttribute.LongDescription)
                {
                    CommandlineMethods.PrintWithPotentialIndent(s, width, 0, tw);
                }
            }

            tw.Write(CommandlineMethods.PadCentered("Values", width));
            foreach (CmdConfigurationFieldAttribute valueAttribute in namespaceAttribute.ConfigurationFields)
            {
                if (valueAttribute.Description is null)
                {
                    tw.WriteLine(valueAttribute.Name);
                }
                else
                {
                    CommandlineMethods.PrintWithPotentialIndent(
                        $"{valueAttribute.Name}: {valueAttribute.Description}", width, indent, tw);
                }
            }
        }
예제 #3
0
        /// <summary>
        ///  Prints generic help about the configuration
        /// </summary>
        /// <param name="interpreter">The current interpreter</param>
        /// <param name="width">The width of the console</param>
        /// <param name="indent">The indent to use</param>
        /// <param name="tw">The Textwriter to write the help to</param>
        public static void ConfigurationGenericHelp(BaseInterpreter interpreter, int width, int indent = 3, TextWriter tw = null)
        {
            tw = tw ?? Console.Out;
            string indentString = new string(' ', indent);

            tw.Write(CommandlineMethods.PadCentered($"Usage of {interpreter.Name}", width));
            string interpreterStringPath = string.Join(" --", interpreter.Path.Select(x => x.Name));     //TODO Clean up this hacky line

            tw.WriteLine($"{interpreterStringPath} NameOfValue help");
            tw.WriteLine(indentString + "Prints help for the field");
            tw.WriteLine($"{interpreterStringPath} NameOfValue get");
            tw.WriteLine(indentString + "Reads the field");
            tw.WriteLine($"{interpreterStringPath} NameOfValue set NewValue");
            tw.WriteLine(indentString + "Sets the field to the value provided");
            //TODO Add add&remove when implemented
        }
        /// <summary>
        ///  Writes the help for a context to a textwriter
        /// </summary>
        /// <param name="context">The context to provide help</param>
        /// <param name="width">The width of the console</param>
        /// <param name="indent">The indent to use for splitted lines</param>
        /// <param name="tw">The textwriter to output to (defaults to <see cref="Console.Out" /></param>
        private static void ContextHelp([NotNull] CmdContextAttribute context, int width, int indent = 3, TextWriter tw = null)
        {
            tw = tw ?? Console.Out;
            context.Load();
            tw.Write(CommandlineMethods.PadCentered(context.Name, width));
            if (context.LongDescription is null)
            {
                if (!(context.Description is null))
                {
                    CommandlineMethods.PrintWithPotentialIndent(context.Description, width, indent, tw);
                }
            }
            else
            {
                foreach (string s in context.LongDescription)
                {
                    CommandlineMethods.PrintWithPotentialIndent(s, width, 0, tw);
                }
            }

            if (context.SubCtx.Count != 0)
            {
                tw.Write(CommandlineMethods.PadCentered("Contexts", width));
                foreach (CmdContextAttribute subCtx in context.SubCtx)
                {
                    CommandlineMethods.PrintWithPotentialIndent(
                        $"{(subCtx.ShortForm is null ? "" : "-" + subCtx.ShortForm + " | ")}--{subCtx.Name}{(subCtx.Description is null ? "" : $": {subCtx.Description}")}",
                        width, indent, tw);
                }
            }

            if (context.CtxActions.Count != 0)
            {
                tw.Write(CommandlineMethods.PadCentered("Actions", width));
                foreach (CmdActionAttribute action in context.CtxActions)
                {
                    CommandlineMethods.PrintWithPotentialIndent(
                        $"{(action.ShortForm is null ? "" : $"-{action.ShortForm} | ")}--{action.Name}{(action.Description is null ? "" : $": {action.Description}")}",
                        width, indent, tw);
                }
            }
        /// <summary>
        ///  Writes the help for a action to a textwriter
        /// </summary>
        /// <param name="action">The action to provide help</param>
        /// <param name="width">The width of the console</param>
        /// <param name="indent">The indent to use for splitted lines</param>
        /// <param name="tw">The textwriter to output to (defaults to <see cref="Console.Out" /></param>
        private static void ActionHelp([NotNull] CmdActionAttribute action, int width, int indent = 3, TextWriter tw = null)
        {
            tw = tw ?? Console.Out;
            action.LoadParametersAndAlias();
            tw.Write(CommandlineMethods.PadCentered(action.Name, width));
            if (!(action.LongDescription is null))
            {
                foreach (string s in action.LongDescription)
                {
                    CommandlineMethods.PrintWithPotentialIndent(s, width, 0, tw);
                }
            }

            if (action.Parameters.Count != 0)
            {
                tw.Write(CommandlineMethods.PadCentered("Parameters", width));
            }

            foreach (CmdParameterAttribute parameter in action.Parameters)
            {
                if (parameter.Usage.HasFlag(CmdParameterUsage.SupportDeclaredRaw))
                {
                    if (parameter.Description is null)
                    {
                        tw.WriteLine((parameter.ShortForm is null ? "--" : "-" + parameter.ShortForm + " | --") + parameter.Name);
                    }
                    else
                    {
                        CommandlineMethods.PrintWithPotentialIndent(
                            $"{(parameter.ShortForm is null ? "" : "-" + parameter.ShortForm + " | ")}--{parameter.Name}: {parameter.Description}",
                            width, indent, tw);
                    }
                }

//TODO Differentiate directs
                if (parameter.Usage.HasFlag(CmdParameterUsage.SupportDirectAlias) ||
                    parameter.Usage.HasFlag(CmdParameterUsage.SupportDeclaredAlias))
                {
                    foreach (CmdParameterAliasAttribute alias in parameter.ParameterAliases)
                    {
                        if (alias.Description is null)
                        {
                            tw.WriteLine((alias.ShortForm is null ? "--" : "-" + alias.ShortForm + " | --") + alias.Name);
                        }
                        else
                        {
                            CommandlineMethods.PrintWithPotentialIndent(
                                $"{(alias.ShortForm is null ? "" : "-" + alias.ShortForm + " | ")}--{alias.Name}: {alias.Description}",
                                width, indent, tw);
                        }
                    }
                }
            }

            if (!(action.UsageExamples is null))
            {
                tw.Write(CommandlineMethods.PadCentered("Examples", width));
                foreach (string s in action.UsageExamples)
                {
                    CommandlineMethods.PrintWithPotentialIndent(s, width, indent, tw);
                }
            }
        }