private CommandConfigurator RegisterNewCommand(string name, string description, Action <CommandConfigurator> configureCommand) { var commandConfigurator = new CommandConfigurator(name, GetCommandParents(), description, _cliConfig); configureCommand(commandConfigurator); _commands.Add(commandConfigurator); return(commandConfigurator); }
/// <summary> /// Register sub command for the command and set it as default. /// </summary> /// <param name="name">Command name</param> /// <param name="description">Command description for help.</param> /// <param name="configureCommand">Command configuration callback</param> /// <returns>Self instance</returns> public CommandConfigurator RegisterDefaultCommand(string name, string description, Action <CommandConfigurator> configureCommand) { if (_defaultCommand != null) { throw new TooManyDefaultCommandsException(); } var commandConfigurator = RegisterNewCommand(name, description, configureCommand); _defaultCommand = commandConfigurator; return(this); }
/// <summary> /// Creates new instance of command configuration. /// </summary> /// <param name="name">Command name</param> /// <param name="printHelpOnExecute">If True command will print help instead of running execute method</param> /// <param name="parents">Command parents list</param> /// <param name="commands">List of registered commands</param> /// <param name="defaultCommand">Default command to run where subcommand is not defined in params</param> /// <param name="options">List of registered options</param> /// <param name="parameters">List of registered parameters</param> /// <param name="parameterSeries">Registered parameter series</param> /// <param name="execute">Function to execute when command is called</param> public CommandConfig( string name, bool printHelpOnExecute, List <string> parents, List <CommandConfigurator> commands, CommandConfigurator defaultCommand, List <PrefixedDefaultValueArgument> options, List <Parameter> parameters, ParameterSeries parameterSeries, Func <CommandArgs, IOutput, int> execute) { Name = name; Parents = parents; Options = options; Parameters = parameters; ParameterSeries = parameterSeries; Execute = execute; PrintHelpOnExecute = printHelpOnExecute; DefaultCommand = defaultCommand; Commands = commands; }