예제 #1
0
        public bool Equals(string opt)
        {
            if (null == opt)
            {
                return(false);
            }

            return(CLIUtil.EqualIgnoreCaseInvariant(opt, this.opt));
        }
예제 #2
0
        public Option GetOption(string opt)
        {
            if (null == opt)
            {
                return(null);
            }

            opt = CLIUtil.TrimPrefix(opt);
            foreach (Option op in this.opts)
            {
                if (op.Equals(opt))
                {
                    return(op);
                }
            }

            return(null);
        }
예제 #3
0
        public static string CheckClassPath(Options opts)
        {
            if (null == opts || !opts.HasOption(CLICommand.CLI_CLASSPATH))
            {
                throw new Exception(string.Format(CLIMessage.ERR_MSG_MISSING_ARG_OPTION, CLICommand.CLI_CLASSPATH));
            }

            string classPath = opts.GetOption(CLICommand.CLI_CLASSPATH).GetVal();

            if (!CLIUtil.IsNullOrEmpty(classPath) && !Path.IsPathRooted(classPath))
            {
                classPath = Path.Combine(CLIUtil.GetCurrentDirectory(), classPath);
            }
            if (!File.Exists(classPath))
            {
                throw new Exception(string.Format(CLIMessage.ERR_MSG_INCORRECT_CLASSPATH, CLICommand.CLI_CLASSPATH, classPath));
            }

            return(classPath);
        }
예제 #4
0
 public static string ToLower(string text)
 {
     return(CLIUtil.ToLower(text, null));
 }
예제 #5
0
        public static Options Parse(Options options, string[] args, bool ignoreUnknowOpt)
        {
            Options       opts = new Options();
            List <Option> ops  = options.GetOptions();

            foreach (Option op in ops)
            {
                op.ClearVals();
            }

            if (null == args)
            {
                args = new string[0];
            }

            int idx = 0;

            while (idx < args.Length)
            {
                string arg = args[idx];
                do
                {
                    if (null == arg)
                    {
                        break;
                    }

                    if (!CLIUtil.IsValidArg(arg))
                    {
                        break;
                    }

                    Option op = options.GetOption(arg);
                    if (null == op)
                    {
                        if (!ignoreUnknowOpt)
                        {
                            throw new Exception(string.Format(CLIMessage.ERR_MSG_UNKNOW_OPTION, arg));
                        }
                        else
                        {
                            break;
                        }
                    }

                    string next     = idx < args.Length - 1 ? args[idx + 1] : null;
                    bool   isArgVal = (null != next) && !(CLIUtil.IsValidArg(next) && options.HasOption(next));
                    if (isArgVal && op.HasArgs())
                    {
                        op.AddVal(CLIUtil.TrimQuote(next));
                        idx++;
                    }

                    opts.AddOption(op);
                } while (false);

                idx++;
            }

            return(opts);
        }
예제 #6
0
 public void BuildOption(StringBuilder builder, Option op, string indent)
 {
     builder.Append(this._indent).Append(indent)
     .Append(CLIUtil.BuildOptName(op.GetOpt())).Append(CLIUtil.CompleteSpace(this._maxLen, op.GetOpt(), indent))
     .Append(op.GetDescription()).Append("\r\n");
 }
예제 #7
0
 public OptionBuilder(Options opts, string indent)
 {
     this._opts   = opts;
     this._indent = indent;
     this._maxLen = CLIUtil.GetMaxOptNameLength(this._opts);
 }