Specifies a set of features to configure a CommandLine.CommandLineParser behavior.
Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandLine.CommandLineParser"/> class,
        /// configurable with a <see cref="CommandLine.CommandLineParserSettings"/> object.
        /// </summary>
        /// <param name="settings">The <see cref="CommandLine.CommandLineParserSettings"/> object is used to configure
        /// aspects and behaviors of the parser.</param>
        public CommandLineParser(CommandLineParserSettings settings)
        {
            if (settings == null)
              throw new ArgumentNullException("settings");

            _settings = settings;
        }
Exemplo n.º 2
0
        public static Options Create(string[] args, CommandLineParserSettings settings)
        {
            Options mailOptions = new Options();
            ICommandLineParser parser = new CommandLineParser(settings);

            parser.ParseArguments(args, mailOptions);
            return mailOptions;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandLine.CommandLineParser"/> class,
        /// configurable with a <see cref="CommandLine.CommandLineParserSettings"/> object.
        /// </summary>
        /// <param name="settings">The <see cref="CommandLine.CommandLineParserSettings"/> object is used to configure
        /// aspects and behaviors of the parser.</param>
        public CommandLineParser(CommandLineParserSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            _settings = settings;
        }
Exemplo n.º 4
0
        public static OptionMap CreateMap(object target, CommandLineParserSettings settings)
        {
            var       list = ReflectionUtil.RetrieveFieldList <OptionAttribute>(target);
            OptionMap map  = new OptionMap(list.Count, settings);

            foreach (Pair <FieldInfo, OptionAttribute> pair in list)
            {
                map[pair.Right.UniqueName] = new OptionInfo(pair.Right, pair.Left);
            }

            return(map);
        }
Exemplo n.º 5
0
        public static OptionMap CreateMap(object target, CommandLineParserSettings settings)
        {
            var list = ReflectionUtil.RetrieveFieldList<OptionAttribute>(target);
            OptionMap map = new OptionMap(list.Count, settings);

            foreach (Pair<FieldInfo, OptionAttribute> pair in list)
            {
                map[pair.Right.UniqueName] = new OptionInfo(pair.Right, pair.Left);
            }

            return map;
        }
Exemplo n.º 6
0
        private static IMsBuilderificCoreOptions GetCommandLineOptions(string[] args)
        {
            var options = Injection.Engine.Resolve<IMsBuilderificCoreOptions>();
            var visitorOptions = Injection.Engine.ResolveAll<IVisitorOptions>();
            var writer = new StringWriter();

            if (args != null && args.Length > 0)
            {
                var parserSettings = new CommandLineParserSettings(false, false, true, System.Console.Out);
                var parser = new CommandLineParser(parserSettings);

                if (!parser.ParseArguments(args, options, writer))
                {
                    visitorOptions.ForEach(v => parser.ParseArguments(args, v, writer));
                    System.Console.WriteLine(writer.ToString());
                    Environment.Exit(1);
                }
                else
                {
                    visitorOptions.ForEach(v =>
                                               {
                                                   if (!parser.ParseArguments(args, v, writer))
                                                       Environment.Exit(1);

                                                   Injection.Engine.RegisterInstance(v.GetType(), v);
                                               });
                }
            }
            else
            {
                var commandLineOptionsCore = options as CommandLineOptionsBase;
                if (commandLineOptionsCore != null)
                {
                    var help = HelpText.AutoBuild(commandLineOptionsCore, current => HelpText.DefaultParsingErrorsHandler(commandLineOptionsCore, current));
                    System.Console.WriteLine(help);

                    visitorOptions.ForEach(v =>
                        {
                            var visitorOptionBase = v as CommandLineOptionsBase;
                            if (visitorOptionBase == null) 
                                return;

                            help = HelpText.AutoBuild(v, current => HelpText.DefaultParsingErrorsHandler(visitorOptionBase, current));
                            System.Console.WriteLine(help);
                        });
                }

                Environment.Exit(2);
            }
            return options;
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            CbcOptions options = new CbcOptions();
            CommandLineParserSettings settings = new CommandLineParserSettings();
            settings.CaseSensitive = true;
            CommandLineParser parser = new CommandLineParser(settings);
            if (!parser.ParseArguments(args, options, System.Console.Error))
            {
                return;
            }

            options.Process();

            var config = new CouchbaseClientConfiguration();
            config.Bucket = options.Bucket;
            config.Username = options.Username;
            config.Password = options.Password;
            config.BucketPassword = options.BucketPassword;
            string uriString = "http://" + options.Hostname + "/pools";
            System.Console.WriteLine("URI: " + uriString);
            config.Urls.Add(new UriBuilder(uriString).Uri);

            DateTime begin = DateTime.Now;
            CouchbaseClient cli = new CouchbaseClient(config);
            System.Console.WriteLine("Created new client..");

            if (!commandMap.ContainsKey(options.Command))
            {
                throw new ArgumentException("Unknown command!");
            }

            Type t = commandMap[options.Command];
            Type[] proto = {
                               typeof(CouchbaseClient),
                               typeof(string),
                               typeof(CbcOptions)
                           };
            object[] cargs = {
                                cli,
                                options.Key,
                                options
                            };

            CommandBase cmd = (CommandBase) t.GetConstructor(proto).Invoke(cargs);
            cmd.Execute();

            var duration = DateTime.Now - begin;
            Console.WriteLine(
                String.Format("Duration was {0:F} Sec.", duration.TotalMilliseconds/1000));
        }
Exemplo n.º 8
0
        public OptionMap(int capacity, CommandLineParserSettings settings)
        {
            _settings = settings;

            IEqualityComparer<string> comparer;
            if (_settings.CaseSensitive)
                comparer = StringComparer.Ordinal;
            else
                comparer = StringComparer.OrdinalIgnoreCase;

            _names = new Dictionary<string, string>(capacity, comparer);
            _map = new Dictionary<string, OptionInfo>(capacity * 2, comparer);

            if (_settings.MutuallyExclusive)
                _mutuallyExclusiveSetMap = new Dictionary<string, int>(capacity, StringComparer.OrdinalIgnoreCase);
        }
Exemplo n.º 9
0
        public static ExampleOptions ParseArgs(string[] args)
        {
            var options = new ExampleOptions();
            var settings = new CommandLineParserSettings { CaseSensitive = false };
            var parser = new CommandLineParser(settings);
            var results = parser.ParseArguments(args, options);
            if (!results)
                return null;

            if (!string.IsNullOrEmpty(options.Manifest) && !File.Exists(options.Manifest))
            {
                Console.WriteLine("Missing manifest file: {0}", options.Manifest);
                return null;
            }

            return options;
        }
Exemplo n.º 10
0
        [STAThread] // おまじない
        static void Main(string[] args)
        {
            // コマンドライン引数の情報を入れる構造体
            var param = new IPParams();

            //コマンドライン引数の解析
            var setting = new CommandLineParserSettings(Console.Error);
            var paser = new CommandLineParser(setting);

            //パースに失敗した場合停止
            if (!paser.ParseArguments(args, param))
            {
                Environment.Exit(1);
            }

            var executor = new ImageProcessRunner(param);
            executor.Start();
        }
Exemplo n.º 11
0
    static void Main(string[] args)
    {
      var parserSettings = new CommandLineParserSettings(false, true);
      var parser = new CommandLineParser(parserSettings);
      var options = new Options();
      if (!parser.ParseArguments(args, options))
      {
        Console.WriteLine(options.GetUsage());
        Environment.Exit(-1);
      }

      var scriptLocations = options.PathsToBundle.Select(path => new ScriptLocation(path, options.BasePath, options.BundleName));

      foreach (var location in scriptLocations)
      {
        var bundler = new Bundler(location, options);
        bundler.CreateBundles();
      }
    }
Exemplo n.º 12
0
        public static ExampleOptions ParseArgs(string[] args)
        {
            var options  = new ExampleOptions();
            var settings = new CommandLineParserSettings {
                CaseSensitive = false
            };
            var parser  = new CommandLineParser(settings);
            var results = parser.ParseArguments(args, options);

            if (!results)
            {
                return(null);
            }

            if (!string.IsNullOrEmpty(options.Manifest) && !File.Exists(options.Manifest))
            {
                Console.WriteLine("Missing manifest file: {0}", options.Manifest);
                return(null);
            }

            return(options);
        }
Exemplo n.º 13
0
        public OptionMap(int capacity, CommandLineParserSettings settings)
        {
            _settings = settings;

            IEqualityComparer <string> comparer;

            if (_settings.CaseSensitive)
            {
                comparer = StringComparer.Ordinal;
            }
            else
            {
                comparer = StringComparer.OrdinalIgnoreCase;
            }

            _names = new Dictionary <string, string>(capacity, comparer);
            _map   = new Dictionary <string, OptionInfo>(capacity * 2, comparer);

            if (_settings.MutuallyExclusive)
            {
                _mutuallyExclusiveSetMap = new Dictionary <string, int>(capacity, StringComparer.OrdinalIgnoreCase);
            }
        }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            var settings = new CommandLineParserSettings();
            settings.CaseSensitive = false;
            settings.HelpWriter = Console.Error;
            ICommandLineParser parser = new CommandLineParser(settings);

            var options = new Options();
            //
            // create parser (with settings) here, see above
            //
            bool success = parser.ParseArguments(args, options);
            if (success)
            {
                Console.WriteLine("Successfully parsed args, attempting to download blob");
            }
            else
            {
                throw new ArgumentException("Unable to parse args");
            }

            DownloadFile(options);
        }
Exemplo n.º 15
0
        public Main()
        {
            Instance = this;

            InitializeComponent();

            menuStrip1.Hide();

            menuStrip1.Renderer = new MyRenderer();

            ToolStripSystemTextBox licenseItem = new ToolStripSystemTextBox();
            licenseItem.TextBox.BackColor = Color.FromArgb(64, 64, 64);
            licenseItem.TextBox.ForeColor = Color.FromArgb(200, 200, 200);
            licenseItem.TextBox.Text = Licensing.LicenseName + "  ";
            licenseItem.TextBox.Font = new System.Drawing.Font("Arial", 8, FontStyle.Regular);
            licenseItem.TextBox.Cursor = System.Windows.Forms.Cursors.Arrow;
            licenseItem.TextBox.BorderStyle = BorderStyle.None;
            licenseItem.Width = 300;
            licenseItem.TextBox.ReadOnly = true;
            licenseItem.TextBox.TabStop = false;
            licenseItem.Alignment = ToolStripItemAlignment.Right;
            this.menuStrip1.Items.Add(licenseItem);

            Application.AddMessageFilter(this);

            var settings = new CommandLineParserSettings();
            settings.CaseSensitive = false;
            settings.HelpWriter = Console.Error;

            ICommandLineParser parser = new CommandLineParser(settings);
            String[] args = Environment.GetCommandLineArgs();
            if (parser.ParseArguments(args, options))
            {
                if (options.TransportType != null)
                {
                    foreach (ExportFactory<Transport, ITransportName> transportAdapter in Program.TransportAdapters)
                    {
                        String transportName = transportAdapter.Metadata.Name;
                        if (transportName == options.TransportType)
                        {
                            SpawnTransport(transportAdapter);
                        }
                    }
                }
            }
            else
            {
                Close();
                return;
            }

            //licenseToolStripMenuItem.Text = Licensing.LicenseName;

            FormClosing += Main_FormClosing;

            ReturnToStartScreen();
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            Options options = new Options();
            CommandLineParserSettings parserSettings = new CommandLineParserSettings();
            parserSettings.CaseSensitive = true;
            CommandLineParser parser = new CommandLineParser(parserSettings);

            if (!parser.ParseArguments(args, options, Console.Error))
            {
                return;
            }

            var config = new CouchbaseClientConfiguration();
            config.Bucket = options.Bucket;
            var url = "http://";
            if (!options.Hostname.Contains(":"))
            {
                options.Hostname += ":8091";
            }
            url += options.Hostname + "/pools";
            config.Urls.Add(new Uri(url));

            Console.Error.WriteLine("URL: " + url + ", Bucket: " + config.Bucket);
            Console.Error.WriteLine("Design: " + options.Design + ", View: " + options.View);

            CouchbaseClient cli = new CouchbaseClient(config);
            var res = cli.ExecuteStore(Enyim.Caching.Memcached.StoreMode.Set, "foo", "bar");
            Console.WriteLine("Store result ? {0}", res.Success);

            var view = cli.GetView(options.Design, options.View);
            if (options.Group)
            {
                view.Group(options.Group);
            }
            if (options.GroupLevel > 0)
            {
                view.GroupAt(options.GroupLevel);
            }

            if (options.Range != null)
            {
                if (options.Range.Count > 2)
                {
                    Console.Error.WriteLine("Too many keys in range (use -R for compount keys)");
                    return;
                }
                if (!String.IsNullOrEmpty(options.Range[0]))
                {
                    view.StartKey(options.Range[0]);
                }
                if (!String.IsNullOrEmpty(options.Range[1]))
                {
                    view.EndKey(options.Range[1]);
                }
            }
            else if (options.CompoundRanges != null)
            {
                IList<string> sk = null, ek = null;

                int firstIx = options.CompoundRanges.IndexOf(":");
                if (firstIx == -1)
                {
                    Console.Error.WriteLine("Malformed compound range");
                    return;
                }
                if (firstIx == 0)
                {
                    ek = options.CompoundRanges.Skip(1).ToList();
                }
                else if (firstIx == options.CompoundRanges.Count - 1)
                {
                    sk = options.CompoundRanges.Take(
                        options.CompoundRanges.Count - 1).ToList();
                }
                else
                {
                    sk = options.CompoundRanges.Take(firstIx).ToList();
                    ek = options.CompoundRanges.Skip(firstIx + 1).ToList();
                }

                if (sk != null)
                {
                    Console.Error.WriteLine("Using start key " +
                        new JavaScriptSerializer().Serialize(sk));
                    view.StartKey(sk);
                }
                if (ek != null)
                {
                    if (ek[0].StartsWith("+"))
                    {
                        ek[0] = new String(ek[0].Skip(1).ToArray());
                        view.WithInclusiveEnd(true);
                    }

                    Console.Error.WriteLine("Using end key " +
                        new JavaScriptSerializer().Serialize(ek));

                    view.EndKey(ek);
                }
            }

            if (options.Limit > 0)
            {
                view = view.Limit(options.Limit);
            }

            if (options.Fresh)
            {
                view.Stale(StaleMode.False);
            }

            try
            {
                DoExecuteView(view);
            }
            catch (WebException exc)
            {
                Console.WriteLine(exc);
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandLine.CommandLineParser"/> class,
        /// configurable with a <see cref="CommandLine.CommandLineParserSettings"/> object.
        /// </summary>
        /// <param name="settings">The <see cref="CommandLine.CommandLineParserSettings"/> object is used to configure
        /// aspects and behaviors of the parser.</param>
        public CommandLineParser(CommandLineParserSettings settings)
        {
            Assumes.NotNull(settings, "settings");

            _settings = settings;
        }
Exemplo n.º 18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandLine.CommandLineParser"/> class.
 /// </summary>
 public CommandLineParser()
 {
     _settings = new CommandLineParserSettings();
 }
Exemplo n.º 19
0
        public static OptionMap CreateMap(object target, CommandLineParserSettings settings)
        {
            var list = ReflectionUtil.RetrievePropertyList<OptionAttribute>(target);
            if (list != null)
            {
                var map = new OptionMap(list.Count, settings);

                foreach (var pair in list)
                {
                    if (pair != null && pair.Right != null)
                        map[pair.Right.UniqueName] = new OptionInfo(pair.Right, pair.Left);
                }

                map.RawOptions = target;

                return map;
            }

            return null;
        }
Exemplo n.º 20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandLine.CommandLineParser"/> class,
 /// configurable with a <see cref="CommandLine.CommandLineParserSettings"/> object.
 /// </summary>
 /// <param name="settings">The <see cref="CommandLine.CommandLineParserSettings"/> object is used to configure
 /// aspects and behaviors of the parser.</param>
 public CommandLineParser(CommandLineParserSettings settings)
 {
     Assumes.NotNull(settings, "settings", SR.ArgumentNullException_CommandLineParserSettingsInstanceCannotBeNull);
     _settings = settings;
 }
Exemplo n.º 21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandLine.CommandLineParser"/> class.
 /// </summary>
 public CommandLineParser()
 {
     _settings = new CommandLineParserSettings();
 }
Exemplo n.º 22
0
 // special constructor for singleton instance, parameter ignored
 private CommandLineParser(bool singleton)
 {
     _settings = new CommandLineParserSettings(false, false, Console.Error);
 }
Exemplo n.º 23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandLine.CommandLineParser"/> class,
 /// configurable with a <see cref="CommandLine.CommandLineParserSettings"/> object.
 /// </summary>
 /// <param name="settings">The <see cref="CommandLine.CommandLineParserSettings"/> object is used to configure
 /// aspects and behaviors of the parser.</param>
 public CommandLineParser(CommandLineParserSettings settings)
 {
     Assumes.NotNull(settings, "settings");
     //InitializeDelagate();
     _settings = settings;
 }
Exemplo n.º 24
0
 static CommandLineParser GetParser()
 {
     var parserSettings = new CommandLineParserSettings
     {
         MutuallyExclusive = true
     };
     return new CommandLineParser(parserSettings);
 }
Exemplo n.º 25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandLine.CommandLineParser"/> class,
        /// configurable with a <see cref="CommandLine.CommandLineParserSettings"/> object.
        /// </summary>
        /// <param name="settings">The <see cref="CommandLine.CommandLineParserSettings"/> object is used to configure
        /// aspects and behaviors of the parser.</param>
        public CommandLineParser(CommandLineParserSettings settings)
        {
            Assumes.NotNull(settings, "settings");

            _settings = settings;
        }