protected override void OnExecute() { if (this.CommandNames.Length == 0) { this.PrintList(); } else { var argList = new List <string>(this.CommandNames); var command = CommandContextBase.GetCommand(this.CommandContext.Node, argList); if (command != null && argList.Any() == false) { if (command is ICommandUsage usage) { usage.Print(this.Usage); } else { throw new InvalidOperationException(Resources.Exception_NotProvideHelp); } } else { var commandName = CommandStringUtility.Join(this.CommandNames); throw new InvalidOperationException(string.Format(Resources.Exception_CommandDoesNotExists_Format, commandName)); } } }
public void Execute(string argumentLine) { var args = CommandStringUtility.Split(argumentLine); this.ExecuteInternal(args); this.OnExecuted(EventArgs.Empty); }
public async Task ExecuteAsync(string argumentLine, CancellationToken cancellationToken) { var args = CommandStringUtility.Split(argumentLine); await this.ExecuteInternalAsync(args, cancellationToken); this.OnExecuted(EventArgs.Empty); }
public void ExecuteCommandLine(string commandLine) { var(name, args) = CommandStringUtility.SplitCommandLine(commandLine); if (this.VerifyName(name) == false) { throw new ArgumentException(string.Format(Resources.Exception_InvalidCommandName_Format, name)); } this.Execute(args); }
public ICommand GetCommandByCommandLine(string commandLine) { var(name, args) = CommandStringUtility.SplitCommandLine(commandLine); if (this.VerifyName(name) == false) { return(null); } return(this.GetCommand(args)); }
public Task ExecuteCommandLineAsync(string commandLine, CancellationToken cancellationToken) { var(name, args) = CommandStringUtility.SplitCommandLine(commandLine); if (this.VerifyName(name) == false) { throw new ArgumentException(string.Format(Resources.Exception_InvalidCommandName_Format, name)); } return(this.ExecuteAsync(args, cancellationToken)); }
public bool TryParseCommandLine(string commandLine) { var(name, args) = CommandStringUtility.SplitCommandLine(commandLine); if (this.VerifyName(name) == false) { throw new ArgumentException(string.Format(Resources.Exception_InvalidCommandName_Format, name)); } return(this.TryParse(args)); }
private static void InputEnter(Terminal terminal) { if (CommandStringUtility.Verify(terminal.Command) == true) { terminal.EndInput(); } else { terminal.InsertNewLine(); } }
private async Task ExecuteInternalAsync(string[] args, CancellationToken cancellationToken) { if (args.Any() == false) { this.BaseUsage?.Invoke(this); } else { var argList = new List <string>(args); var command = GetCommand(this.commandNode, argList); if (command != null) { var parser = new CommandLineParser(command.Name, command); await parser.InvokeAsync(argList.ToArray(), cancellationToken); } else { throw new ArgumentException(string.Format(Resources.Exception_CommandDoesNotExists_Format, CommandStringUtility.Join(args))); } } }
protected CommandBase(string[] aliases) { this.Name = CommandStringUtility.ToSpinalCase(this.GetType()); this.Aliases = aliases ?? throw new ArgumentNullException(nameof(aliases)); }
public bool TryInvoke(string argumentLine) { var args = CommandStringUtility.Split(argumentLine); return(this.TryInvoke(args)); }
public void Parse(string argumentLine) { var args = CommandStringUtility.Split(argumentLine); this.Parse(args); }