public static CommandResult Version(CommandLineProto proto, CommandLine args) { string name = ProgramInfo.GetProgramName(); string version = ProgramInfo.GetProgramVersion(); string copyright = ProgramInfo.GetCopyright(); return(new CommandResult(true, $"{name} {version} {copyright}")); }
public static CommandResult WorkingFolder(CommandLineProto proto, CommandLine args) { if (args.Count == 2) { GeneralParameters.Instance.WorkingFolder = args[1].Value; } return(new CommandResult(true, GeneralParameters.Instance.WorkingFolder)); }
public static CommandResult Help(CommandLineProto proto, CommandLine args) { string command = args.GetValue(1); if (command == null) { return(GeneralHelp(CommandLineProtoRegistry.Instance)); } else { return(CommandHelp(command, CommandLineProtoRegistry.Instance)); } }
private void Register(string name, CommandLineProto proto) { if (_map.TryGetValue(name, out List <CommandLineProto> list)) { list.Add(proto); } else { List <CommandLineProto> newList = new List <CommandLineProto>(); newList.Add(proto); _map.Add(name, newList); } }
public static CommandResult CommandHelp(CommandLine args, CommandLineProtoRegistry commands) { CommandResult result = new CommandResult(); CommandLineProto proto = commands.Find(args); if (proto == null) { return(new CommandResult(false, "Command not found")); } Usage u = CommandLineProto.GetUsage(proto); result.AddMessage(u.ToString()); return(result); }
public static CommandResult CommandHelp(string command, CommandLineProtoRegistry commands) { CommandResult result = new CommandResult(); CommandLineProto[] protos = commands.Find(command); if (protos.Length == 0) { return(new CommandResult(false, "'{command}' is not a command")); } Usage u = CommandLineProto.GetUsage(protos); result.AddMessage(u.ToString()); return(result); }
public static CommandResult HelpArgument(CommandLineProto proto, CommandLine args) { string command = args.GetValue(1); string programName = ProgramInfo.GetProgramName(); if (command == null) { return(GeneralHelp(CommandLineProtoRegistry.Instance)); } else { return(CommandHelp(new CommandLine($"{programName} {command}"), CommandLineProtoRegistry.Instance)); } }
public static CommandResult GeneralHelp(CommandLineProtoRegistry commands) { CommandResult result = new CommandResult(); result.AddMessage($"{ProgramInfo.GetProgramName()} {ProgramInfo.GetProgramVersion()}"); result.AddMessage(); var description = ProgramInfo.GetProgramDescription(); if (!String.IsNullOrEmpty(description)) { result.AddMessage(description); result.AddMessage(); } CommandLineProto[] protos = commands.GetAll(); Usage u = CommandLineProto.GetUsage(protos); result.AddMessage(u.ToString()); return(result); }
public void Register(CommandLineProto proto) { if (proto != null) { CommandArg name = proto.GetPositional(0); if (name != null) { Register(name.Value, proto); } else { throw new ArgumentException($"Command cannot be registered"); } } else { throw new ArgumentNullException("Proto argument cannot be null"); } }
public CommandInstance(CommandLineProto command, CommandLine args) { Command = command; Args = args; }
public static CommandResult InvalidCommand(CommandLineProto proto, CommandLine args) { return(new CommandResult(false, $"'{args[0].Name}' is not a command.")); }
public static CommandResult Null(CommandLineProto proto, CommandLine args) { return(new CommandResult()); }
public CommandResult Execute(CommandLineProto cd, CommandLine args) { return(Execute(new CommandInstance(cd, args))); }