Esempio n. 1
0
 /// <summary>
 ///     Directly bind a function to a verb.
 /// </summary>
 /// <param name="verb">The Verb</param>
 /// <param name="func">
 ///     The function that is executed when the verbs passed in the
 ///     command-line (<see cref="CommandLineArguments.VerbPath" /> are equal to the <paramref name="verb" />.
 /// </param>
 /// <param name="commandDescription"></param>
 /// <example>
 ///     <code>
 /// string COMMAND_LINE = "word1 text2 verb3";
 /// // Arguments.VerbPath is executed
 /// var commander = new Commander(new Settings { AutoResolveCommands = false });
 /// commander.RegisterFunction("word1", word);
 /// commander.RegisterFunction("word1.text2", text);
 /// commander.RegisterFunction("word1.text2.verb3", verb);
 /// commander.ExecuteCommand(args);
 /// </code>
 /// </example>
 /// <exception cref="ArgumentNullException">In case <paramref name="verb" /> is null.</exception>
 /// <seealso cref="CommandLineArguments.VerbPath " />
 /// <seealso cref="Settings.AutoResolveCommands" />
 public void RegisterFunction([NotNull] string verb, [NotNull] Action <CommandLineArguments> func,
                              string commandDescription = null)
 {
     if (string.IsNullOrEmpty(verb))
     {
         throw new ArgumentNullException(nameof(verb));
     }
     _commandDescriptors[verb] = new CommandDescriptor(verb, () => new CommandWrapper(func), commandDescription);
 }
Esempio n. 2
0
 /// <summary>
 ///     Register a command.
 /// </summary>
 /// <param name="commandDescriptor"></param>
 public void RegisterCommand(CommandDescriptor commandDescriptor)
 => _commandDescriptors[commandDescriptor.Verb] = commandDescriptor;