コード例 #1
0
ファイル: MainForm.cs プロジェクト: smile-ttxp/Paint.NET
        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
ファイル: Argument.cs プロジェクト: ArdaOzcan/SimpleArgParse
        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
ファイル: MainForm.cs プロジェクト: ykafia/Paint.Net4
 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
ファイル: MainForm.cs プロジェクト: leejungho2/xynotecgui
        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;
        }