예제 #1
0
        private bool SplitMessage(string message, out ArgumentAction action, out string actionParm)
        {
            if (message.Length == 0)
            {
                action     = ArgumentAction.NoOp;
                actionParm = null;
                return(false);
            }

            const string printPrefix = "print:";

            if (message.IndexOf(printPrefix) == 0)
            {
                action     = ArgumentAction.Print;
                actionParm = message.Substring(printPrefix.Length);
                return(true);
            }

            const string untitledPrefix = "untitled:";

            if (message.IndexOf(untitledPrefix) == 0)
            {
                action     = ArgumentAction.OpenUntitled;
                actionParm = message.Substring(untitledPrefix.Length);
                return(true);
            }

            action     = ArgumentAction.Open;
            actionParm = message;
            return(true);
        }
예제 #2
0
파일: ArgParse.cs 프로젝트: zengfr/typhoon
        public ArgumentParser Add(string prototype, string description, ArgumentAction <string, string> action, bool hidden)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }
            Argument p = new ActionArgument(prototype, description, 2,
                                            delegate(ArgumentValueCollection v) { action(v[0], v[1]); }, hidden);

            base.Add(p);
            return(this);
        }
예제 #3
0
        internal Argument(string name,
                          string longName       = null,
                          ArgumentAction action = ArgumentAction.Store,
                          object defaultValue   = null,
                          List <string> choices = null,
                          bool required         = false,
                          string help           = "",
                          object constant       = null)
        {
            Name         = name;
            IsOptional   = Name.IsOptionalArgument();
            IsPositional = !IsOptional;
            LongName     = longName;
            Action       = action;
            DefaultValue = defaultValue;
            Choices      = choices;
            Required     = required;
            Help         = help;
            Constant     = constant;

            if (LongName == null)
            {
                KeyName = Name.TrimStart(StringUtils.DefaultPrefix);
            }
            else
            {
                KeyName = LongName.TrimStart(StringUtils.DefaultPrefix);
            }

            UpperName = KeyName.ToUpperInvariant();


            if (IsOptional)
            {
                if (IsValueAction)
                {
                    Usage = Name + " " + UpperName;
                }
                else
                {
                    Usage = "[" + Name + "]";
                }
            }
            else
            {
                Usage = Name;
            }
        }
예제 #4
0
        /// <summary>
        /// Add an argument with the specified properties to the argument parser.
        /// </summary>
        /// <param name="name">Name of the argument. If this name starts with the "-" prefix then it will be an optional argument, else it will be a positional argument.</param>
        /// <param name="longName">Longer (not necessarily) name of an optional argument, an alias. It can be used for positional arguments, it would only change the key value in the namespace.</param>
        /// <param name="action">Action of an optional argument.</param>
        /// <param name="defaultValue">Default value of an optional argument if it is not supplied. Default value is `null` by default.</param>
        /// <param name="choices">A list of strings indicating the only selectable options for an argument. An error will be thrown if the provided values is not in the list of choices.</param>
        /// <param name="required">Determines is an optional argument is required to be supplied. Can be used for positional arguments too but it won't effect anything.</param>
        /// <param name="help">Help string to be printed in the help message for the argument. It is empty by default.</param>
        /// <param name="constant">Constant value for the argument. This parameter only works for arguments with `StoreConst` and `AppendConst` actions.</param>
        public void AddArgument(string name,
                                string longName       = null,
                                ArgumentAction action = ArgumentAction.Store,
                                object defaultValue   = null,
                                List <string> choices = null,
                                bool required         = false,
                                string help           = "",
                                object constant       = null)
        {
            if (name.Contains(" "))
            {
                throw new InvalidArgumentNameException("An argument name can't contain spaces.");
            }

            Argument arg = new Argument(name,
                                        longName: longName,
                                        action: action,
                                        defaultValue: defaultValue,
                                        choices: choices,
                                        required: required,
                                        help: help,
                                        constant: constant);

            arguments.Add(arg);

            if (arg.Name.IsOptionalArgument())
            {
                Categories[optionalArgsTitle].Add(arg);
                OptionalArguments.Add(arg);
            }
            else
            {
                Categories[positionalArgsTitle].Add(arg);
                PositionalArguments.Add(arg);
            }
        }
예제 #5
0
 private bool SplitMessage(string message, out ArgumentAction action, out string actionParm)
 {
     if (message.Length == 0)
     {
         action     = ArgumentAction.NoOp;
         actionParm = null;
         return(false);
     }
     if (message.IndexOf("print:") == 0)
     {
         action     = ArgumentAction.Print;
         actionParm = message.Substring("print:".Length);
         return(true);
     }
     if (message.IndexOf("untitled:") == 0)
     {
         action     = ArgumentAction.OpenUntitled;
         actionParm = message.Substring("untitled:".Length);
         return(true);
     }
     action     = ArgumentAction.Open;
     actionParm = message;
     return(true);
 }
예제 #6
0
파일: ArgParse.cs 프로젝트: zengfr/typhoon
 public ArgumentParser Add <TKey, TValue>(string prototype, string description, ArgumentAction <TKey, TValue> action)
 {
     return(Add(new ActionArgument <TKey, TValue>(prototype, description, action)));
 }
예제 #7
0
파일: ArgParse.cs 프로젝트: zengfr/typhoon
 public ArgumentParser Add <TKey, TValue>(string prototype, ArgumentAction <TKey, TValue> action)
 {
     return(Add(prototype, null, action));
 }
예제 #8
0
파일: ArgParse.cs 프로젝트: zengfr/typhoon
 public ArgumentParser Add(string prototype, string description, ArgumentAction <string, string> action)
 {
     return(Add(prototype, description, action, false));
 }
예제 #9
0
파일: ArgParse.cs 프로젝트: zengfr/typhoon
 public ArgumentParser Add(string prototype, ArgumentAction <string, string> action)
 {
     return(Add(prototype, null, action));
 }
예제 #10
0
        private bool SplitMessage(string message, out ArgumentAction action, out string actionParm)
        {
            if (message.Length == 0)
            {
                action = ArgumentAction.NoOp;
                actionParm = null;
                return false;
            }

            const string printPrefix = "print:";

            if (message.IndexOf(printPrefix) == 0)
            {
                action = ArgumentAction.Print;
                actionParm = message.Substring(printPrefix.Length);
                return true;
            }

            action = ArgumentAction.Open;
            actionParm = message;
            return true;
        }