/// <summary> /// Adds the default command (implied if program arguments don't begin with a configured command key). /// </summary> /// <typeparam name="TRunInfo">The run info Type this command is mapped to.</typeparam> /// <param name="defaultCommand">The default command configuration object.</param> /// <param name="postBuildCallback">An optional callback that's invoked with the built TRunInfo run info object.</param> /// <returns>The CommandStore instance.</returns> public CommandStore AddDefault <TRunInfo>(DefaultCommand <TRunInfo> defaultCommand, Action <TRunInfo> postBuildCallback = null) where TRunInfo : class { if (defaultCommand == null) { throw new CommandValidationException( "Command must be provided.", CommandValidationError.NullObject, commandLevel: -1); } if (IsCommand(CommandStore.DefaultKey)) { throw new CommandValidationException( "Default command has already been configured.", CommandValidationError.DuplicateKey, commandLevel: -1); } DefaultCommandValidator.Validate(defaultCommand); Func <string[], Pipeline <TRunInfo> > pipelineFactory = args => { Queue <Stage <TRunInfo> > stages = _stagesFactory.Create <TRunInfo>(defaultCommand, postBuildCallback); return(new Pipeline <TRunInfo>(stages, args, defaultCommand, _parser, globalOptions: null)); }; _pipelineFactoryMap.Add(CommandStore.DefaultKey, pipelineFactory); _helpManager.ConfigureForDefaultCommand(defaultCommand); return(this); }
internal void ConfigureForDefaultCommand <TRunInfo>(DefaultCommand <TRunInfo> defaultCommand) where TRunInfo : class { string helpText = HelpBuilder.BuildFor(defaultCommand, _programName); _defaultCommandInfo = helpText; }