Exemplo n.º 1
0
 /// <inheritdoc />
 protected override void ExecuteCore(TextReader input, TextWriter output, TextWriter error, ArgumentEnumerator args)
 {
     if (args.MoveNext() && string.CompareOrdinal(args.CurrentName, "?") == 0)
     {
         ExecuteHelp(output, args);
     }
     else
     {
         ExecuteMethod(input, output, error, args);
     }
 }
Exemplo n.º 2
0
        private void WriteExamples(TextWriter output, char namePrefix)
        {
            Attribute[] eas = Attribute.GetCustomAttributes(_method.Method, typeof(ExampleAttribute));

            if (eas.Length == 0)
            {
                return;
            }

            output.WriteLine();
            output.WriteLine(Resources.ExamplesSection);

            foreach (ExampleAttribute ea in eas)
            {
                output.WriteLine();

                string description = ea.Description;

                if (description != null && description.Length > 0)
                {
                    output.WriteLine(description);
                    output.WriteLine();
                }

                output.WriteIndent(ExampleIndent);
                output.Write(Name);

                ArgumentEnumerator args = new ArgumentEnumerator(ea.NamePrefix, ea.Example);

                while (args.MoveNext())
                {
                    output.Write(' ');
                    output.Write(namePrefix);
                    output.Write(args.CurrentName);

                    if (args.CurrentValue != bool.FalseString &&
                        args.CurrentValue != bool.TrueString)
                    {
                        output.Write(':');
                        output.Write(args.CurrentValue);
                    }
                }

                output.WriteLine();
            }
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        protected override void ExecuteCore(TextReader input, TextWriter output, TextWriter error, ArgumentEnumerator args)
        {
            Command        commandBase    = null;
            CommandContext commandContext = this;

            if (!args.MoveNext())
            {
                return;
            }

            CommandContextScope executionScope = CommandContextScope.Current;

            if (executionScope != null && executionScope.CurrentContext != this)
            {
                ThrowHelper.ThrowNotCurrentCommandContextException(Name);
            }

            if (args.CurrentName == string.Empty)
            {
                while (string.CompareOrdinal(args.CurrentValue, "..") == 0)
                {
                    if (executionScope == null)
                    {
                        ThrowHelper.ThrowNoCommandContextExecutionScope(Name);
                    }

                    commandContext = executionScope.PopContext();

                    if (!args.MoveNext())
                    {
                        return;
                    }
                }
            }

            do
            {
                if (args.CurrentName == string.Empty)
                {
                    if (string.Compare(args.CurrentValue, "help", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        commandContext.ExecuteHelp(output, executionScope);
                        return;
                    }

                    commandContext._commands.TryGetCommand(args.CurrentValue, out commandBase);
                    commandContext = commandBase as CommandContext;

                    if (commandContext == null)
                    {
                        break;
                    }

                    if (executionScope != null)
                    {
                        executionScope.PushContext(commandContext);
                    }
                }
                else
                {
                    if (string.CompareOrdinal(args.CurrentName, "?") == 0)
                    {
                        commandContext.ExecuteHelp(output, executionScope); return;
                    }
                    else
                    {
                        ThrowHelper.ThrowUnknownArgumentException(Name, args.CurrentName);
                    }
                }
            }while (args.MoveNext());

            if (commandBase == null)
            {
                if (executionScope == null || executionScope.CurrentContext == this)
                {
                    ThrowHelper.ThrowUnknownCommandException(args.CurrentValue);
                }
            }
            else
            {
                args.MoveNext();
                commandBase.Execute(input, output, error, args.ContinueFromCurrent());
            }
        }