Ejemplo n.º 1
0
        private void Execute()
        {
            try
            {
                argParse.Parse(args);
            }
            catch (ArgumentException e)
            {
                argParse.Usage();
                return;
            }
            OptionSet activeOptionSet = argParse.GetActiveOptionSet();

            Console.Out.WriteLine("Active optionset: " + activeOptionSet.Name);
            if (activeOptionSet.Name.Equals("Analysis command"))
            {
                Option option = activeOptionSet.GetOption("-i");
                Console.Out.WriteLine("input: " + option.ParamValue);
                option = activeOptionSet.GetOption("-o");
                Console.Out.WriteLine("output: " + option.ParamValue);
                option = activeOptionSet.GetOption("-t");
                Console.Out.WriteLine("trend: " + (option.IsProvided ? "true" : "false"));
            }
        }
Ejemplo n.º 2
0
        public void ArgParse_OneOptionSetTwoOptions_Add_Success()
        {
            ArgParse  argParse  = new ArgParse();
            Option    option    = new Option("-a", "--add", "Add an option", true, true);
            Option    option2   = new Option("-d", "--delete", "Delete an option", false, true);
            OptionSet optionSet = new OptionSet("Two parameters");

            optionSet.Add(option);
            optionSet.Add(option2);
            argParse.Add(optionSet);

            Assert.AreEqual("Usage:\nTwo parameters:\n\t-a\t--add Value\t\tAdd an option" +
                            "\n\t-d\t--delete Value\t\t[Optional] Delete an option\n", argParse.Usage());
        }
Ejemplo n.º 3
0
        public void ArgParse_TwoOptionSetTwoOptions_Add_Success()
        {
            ArgParse  argParse  = new ArgParse();
            Option    option    = new Option("-a", "--add", "Add an option", true, true);
            Option    option2   = new Option("-d", "--delete", "Delete an option", false, true);
            OptionSet optionSet = new OptionSet("Two parameters");

            optionSet.Add(option);
            optionSet.Add(option2);
            argParse.Add(optionSet);
            OptionSet optionSet2 = new OptionSet("One parameter");
            Option    option3    = new Option("-v", "--version", "Version of the application", true, false);

            optionSet2.Add(option3);
            argParse.Add(optionSet2);

            Assert.AreEqual("Usage:\nTwo parameters:\n\t-a\t--add Value\t\t" +
                            "Add an option\n\t-d\t--delete Value\t\t[Optional] Delete an option\n" +
                            "One parameter:\n\t-v\t--version\t\tVersion of the application\n", argParse.Usage());
        }
Ejemplo n.º 4
0
        public void ArgParse_OneOptionSet_Add_Success()
        {
            ArgParse  argParse  = new ArgParse();
            Option    option    = new Option("-a", "--add", "Add an option", true, true);
            OptionSet optionSet = new OptionSet("Single parameter");

            optionSet.Add(option);
            argParse.Add(optionSet);

            Assert.AreEqual("Usage:\nSingle parameter:\n\t-a\t--add Value\t\tAdd an option\n", argParse.Usage());
        }