示例#1
0
        public void DefinedCommand_GetUsageDocumentationWithoutDescription()
        {
            // ARRANGE
            var application = FluentConsoleApplication.Create("Application")
                              .DefineCommand("add", "Add two numbers")
                              .WithParameter <int>("X", "First operand")
                              .WithParameter <int>("Y", "Second operand")
                              .Does(args => Console.WriteLine("Total is " + (args.X + args.Y)));

            IDefinedCommand definedCommad = application.RunnableCommands.First().DefinedCommand;

            // ACT
            string documentation = definedCommad.GetUsageDocumentation(includeDescription: false);

            // ASSERT
            documentation.Should().BeEquivalentTo("add [X] [Y]");
        }
示例#2
0
 public DefinedCommand(IDefinedCommand definedCommand, IDefinedParameter definedParameter)
     : this(definedCommand.Application, definedCommand.Name, definedCommand.Description)
 {
     Parameters = definedCommand.Parameters.Concat(new[] { definedParameter });
 }
示例#3
0
        /// <summary>
        /// Link an action to a <see cref="IDefinedCommand"/>
        /// </summary>
        /// <param name="definedCommand"></param>
        /// <param name="commandAction"></param>
        /// <returns></returns>
        public static IFluentConsoleApplication Does(this IDefinedCommand definedCommand, Action <dynamic> commandAction)
        {
            IRunnableCommand runnableCommand = new RunnableCommand(definedCommand, commandAction);

            return(new FluentConsoleApplication(runnableCommand));
        }
示例#4
0
        /// <summary>
        /// Define a parameter for a <see cref="IDefinedCommand"/> with optional description and implicit value conversion.
        /// </summary>
        /// <typeparam name="T">Type that the user's argument shall be parsed to.</typeparam>
        /// <param name="definedCommand"><see cref="IDefinedCommand"/> that will have the parameter being created</param>
        /// <param name="parameterName">Name of the parameter to be created</param>
        /// <param name="valueType">Optional parameter to get the type, not intended to be used directly by the user</param>
        /// <returns></returns>
        public static IDefinedCommand WithParameter <T>(this IDefinedCommand definedCommand, string parameterName, string parameterDescription = null, T valueType = default(T))
        {
            var type = typeof(T);

            return(WithParameter(definedCommand, parameterName, parameterDescription, input => (T)Convert.ChangeType(input, typeof(T))));
        }
示例#5
0
 /// <summary>
 /// Define a parameter for a <see cref="IDefinedCommand"/> without any parsing delegate or type.
 /// </summary>
 /// <param name="definedCommand"><see cref="IDefinedCommand"/> that will have the parameter being created</param>
 /// <param name="parameterName">Name of the parameter to be created</param>
 /// <param name="parameterDescription">Description of the parameter to be created</param>
 /// <returns></returns>
 public static IDefinedCommand WithParameter(this IDefinedCommand definedCommand, string parameterName, string parameterDescription = null)
 {
     return(WithParameter(definedCommand, parameterName, parameterDescription, input => input));
 }
示例#6
0
        /// <summary>
        /// Define a parameter for a <see cref="IDefinedCommand"/> without any description.
        /// </summary>
        /// <typeparam name="T">Type that the user's argument shall be parsed to.</typeparam>
        /// <param name="definedCommand"><see cref="IDefinedCommand"/> that will have the parameter being created</param>
        /// <param name="parameterName">Name of the parameter to be created</param>
        /// <param name="parameterParser">Logic to convert a <see cref="string"/>
        /// as input argument into <typeparamref name="T"/></param>
        /// <returns></returns>
        public static IDefinedCommand WithParameter <T>(this IDefinedCommand definedCommand, string parameterName, Func <string, T> parameterParser)
        {
            var definedParameter = new DefinedParameter <T>(parameterName, null, parameterParser);

            return(new DefinedCommand(definedCommand, definedParameter));
        }
示例#7
0
 public RunnableCommand(IDefinedCommand definedCommand, Action <dynamic> commandAction)
 {
     DefinedCommand = definedCommand;
     Action         = commandAction;
 }