示例#1
0
        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}"));
        }
示例#2
0
 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));
 }
示例#3
0
        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));
            }
        }
示例#4
0
 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);
     }
 }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
        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));
            }
        }
示例#8
0
        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);
        }
示例#9
0
 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");
     }
 }
示例#10
0
 public CommandInstance(CommandLineProto command, CommandLine args)
 {
     Command = command;
     Args    = args;
 }
示例#11
0
 public static CommandResult InvalidCommand(CommandLineProto proto, CommandLine args)
 {
     return(new CommandResult(false, $"'{args[0].Name}' is not a command."));
 }
示例#12
0
 public static CommandResult Null(CommandLineProto proto, CommandLine args)
 {
     return(new CommandResult());
 }
示例#13
0
 public CommandResult Execute(CommandLineProto cd, CommandLine args)
 {
     return(Execute(new CommandInstance(cd, args)));
 }