public ConsoleModeCommand( TextWriter outputStream = null, TextReader inputStream = null, HideableOptionSet options = null) : this(() => new ConsoleCommand[0], outputStream, inputStream, null, options) { _commandSource = () => new ConsoleCommand[0]; }
public OverwriteCommand() { this.IsCommand("foo", "bar"); this.HasOption<int>("A=", "first value", v => A = v); this.SkipsCommandSummaryBeforeRunning(); var optionSet = new HideableOptionSet(); this.Options = optionSet; optionSet.Add<int>("B=", "second option", v => B = v); }
public CoordinateCommand(TextWriter recorder) { _recorder = recorder; this.IsCommand("move"); Options = new HideableOptionSet { {"x=", "Coordinate along the x axis.", v => X = int.Parse(v)}, {"y=", "Coordinate along the y axis.", v => Y = int.Parse(v)}, }; }
/// <summary> /// Configure command options and describe details in the class contructor /// </summary> /// <example> /// Example usage: /// /// SampleConsole.exe example "option one" two -b -o "optional argument" -l=first -l=second -l "the third option" /// /// Expected output: /// /// Executing Example (Example implementation of a ManyConsole command-line argument /// parser Command): /// Argument1 : option one /// Argument2 : two /// BooleanOption : True /// OptionalArgument1 : optional argument /// OptionalArgumentList : System.Collections.Generic.List`1[System.String] /// ///Called Example command - Argument1 = "option one" Argument2 = "two" BooleanOptio ///n: True ///List Item 0 = "first" ///List Item 1 = "second" ///List Item 2 = "the third option" /// </example> public ExampleCommand() { this.IsCommand("Example", "Example implementation of a ManyConsole command-line argument parser Command"); this.HasOption("b|booleanOption", "Boolean flag option", b => BooleanOption = true); // Setting .Options directly is the old way to do this, you may prefer to call the helper // method HasOption/HasRequiredOption. Options = new HideableOptionSet { {"l|list=", "Values to add to list", v => OptionalArgumentList.Add(v)}, {"r|requiredArguments=", "Optional string argument requiring a value be specified afterwards", s => OptionalArgument1 = s}, {"o|optionalArgument:", "Optional String argument which is null if no value follow is specified", s => OptionalArgument2 = s ?? "<no argument specified>"} }; this.HasRequiredOption("requiredOption=", "Required string argument also requiring a value.", s => { }); this.HasOption("anotherOptional=", "Another way to specify optional arguments", s => {}); HasAdditionalArguments(2, "<Argument1> <Argument2>"); }
public ConsoleModeCommand( Func<IEnumerable<IConsoleCommand>> commandSource, TextWriter outputStream = null, TextReader inputStream = null, string friendlyContinueText = null, HideableOptionSet options = null) { _inputStream = inputStream ?? Console.In; _outputStream = outputStream ?? Console.Out; this.IsCommand("run-console", "Run in console mode, treating each line of console input as a command."); this.Options = options ?? this.Options; // added per request from https://github.com/fschwiet/ManyConsole/issues/7 _commandSource = () => { var commands = commandSource(); return commands.Where(c => !(c is ConsoleModeCommand)); // don't cross the beams }; _continuePrompt = friendlyContinueText ?? FriendlyContinuePrompt; }