コード例 #1
0
ファイル: Program.cs プロジェクト: qljiong/KSOA
        private static CommandLineParser.CommandLineParser CreateParser()
        {
            CommandLineParser.CommandLineParser parser = new CommandLineParser.CommandLineParser();
            ValueArgument<SqlConnectionStringBuilder> connectionStringArgument = new ValueArgument<SqlConnectionStringBuilder>('c', "connectionString", "ConnectionString of the documented database")
            {
                Optional = false,
                ConvertValueHandler = (stringValue) =>
                {
                    SqlConnectionStringBuilder connectionStringBuilder;
                    try
                    {
                        connectionStringBuilder = new SqlConnectionStringBuilder(stringValue);
                    }
                    catch
                    {
                        throw new InvalidConversionException("invalid connection string", "connectionString");
                    }
                    if (String.IsNullOrEmpty(connectionStringBuilder.InitialCatalog))
                    {
                        throw new InvalidConversionException("no InitialCatalog was specified", "connectionString");
                    }

                    return connectionStringBuilder;
                }
            };
            FileArgument inputFileArgument = new FileArgument('i', "input", "original edmx file") { FileMustExist = true, Optional = false };
            FileArgument outputFileArgument = new FileArgument('o', "output", "output edmx file - Default : original edmx file") { FileMustExist = false, Optional = true };

            parser.Arguments.Add(connectionStringArgument);
            parser.Arguments.Add(inputFileArgument);
            parser.Arguments.Add(outputFileArgument);

            parser.IgnoreCase = true;
            return parser;
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: MarcStan/icon-generator
        static void Main(string[] args)
        {
            var arg = new FileArgument('i', "inputFile")
            {
                FileMustExist = true
            };
            var parser = new CommandLineParser.CommandLineParser
            {
                AcceptEqualSignSyntaxForValueArguments = true,
                AcceptHyphen = true,
                AcceptSlash  = true
            };

            parser.Arguments.Add(arg);

            try
            {
                parser.ParseCommandLine(args);
                if (!arg.Parsed)
                {
                    throw new NotSupportedException("No argument provided.");
                }

                var icons = Collect(arg.Value.FullName).ToList();
                Generate(icons);
            }
            catch (Exception e)
            {
                Console.WriteLine("The process was aborted mid-way. Some icons may have been generated.");
                Console.WriteLine(e.Message);
                return;
            }
            Console.WriteLine("All done!");
        }
コード例 #3
0
        private CommandLineParser.CommandLineParser InitIgnoreCase()
        {
            var commandLineParser = new CommandLineParser.CommandLineParser();

            commandLineParser.IgnoreCase = true;
            commandLineParser.ShowUsageOnEmptyCommandline = true;

            SwitchArgument showArgument = new SwitchArgument('s', "show", "Set whether show or not", true);

            SwitchArgument hideArgument = new SwitchArgument('h', "hide", "Set whether hid or not", false);

            ValueArgument <string> level = new ValueArgument <string>('l', "level", "Set the level");

            ValueArgument <decimal> version = new ValueArgument <decimal>('v', "version", "Set desired version");

            ValueArgument <Point> point = new ValueArgument <Point>('p', "point", "specify the point");

            BoundedValueArgument <int> optimization = new BoundedValueArgument <int>('o', "optimization", 0, 3);

            EnumeratedValueArgument <string> color = new EnumeratedValueArgument <string>('c', "color", new[] { "red", "green", "blue" });

            FileArgument inputFile = new FileArgument('i', "input", "Input file");

            inputFile.FileMustExist = false;
            FileArgument outputFile = new FileArgument('x', "output", "Output file");

            outputFile.FileMustExist = false;

            DirectoryArgument inputDirectory = new DirectoryArgument('d', "directory", "Input directory");

            inputDirectory.DirectoryMustExist = false;

            point.ConvertValueHandler = delegate(string stringValue)
            {
                if (stringValue.StartsWith("[") && stringValue.EndsWith("]"))
                {
                    string[] parts =
                        stringValue.Substring(1, stringValue.Length - 2).Split(';', ',');
                    Point p = new Point();
                    p.x = int.Parse(parts[0]);
                    p.y = int.Parse(parts[1]);
                    return(p);
                }

                throw new CommandLineArgumentException("Bad point format", "point");
            };

            commandLineParser.Arguments.Add(showArgument);
            commandLineParser.Arguments.Add(hideArgument);
            commandLineParser.Arguments.Add(level);
            commandLineParser.Arguments.Add(version);
            commandLineParser.Arguments.Add(point);
            commandLineParser.Arguments.Add(optimization);
            commandLineParser.Arguments.Add(color);
            commandLineParser.Arguments.Add(inputFile);
            commandLineParser.Arguments.Add(outputFile);
            commandLineParser.Arguments.Add(inputDirectory);

            return(commandLineParser);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: gpavlovych/GerberTools
        static int Main(string[] args)
        {
            var parser    = new CommandLineParser.CommandLineParser(); //switch argument is meant for true/false logic
            var inputFile = new FileArgument('i', "input", "Input Excellon file")
            {
                FileMustExist = true, Optional = false
            };
            var inputRealFile = new FileArgument('i', "input", "Input file with 2 imaginary and real points")
            {
                FileMustExist = true, Optional = false
            };
            var outputFile = new FileArgument('o', "output", "Output Excellon file with all real coordinates")
            {
                FileMustExist = false, Optional = false
            };

            parser.Arguments.Add(inputFile);
            parser.Arguments.Add(outputFile);
            try
            {
                parser.ParseCommandLine(args);
                using (var reader = inputFile.Value.OpenText())
                    using (var writer = new StreamWriter(outputFile.Value.OpenWrite()))
                    {
                    }

                return(0);
            }
            catch (CommandLineException e)
            {
                Console.WriteLine(e.Message);
                return(-1);
            }
        }
コード例 #5
0
        public void Setvalue()
        {
            var sut = new FileArgument(NAME, DESCRIPTION);

            sut.SetValue(VALID_FILE_NAME);
            Assert.AreEqual(VALID_FILE_NAME, sut.Value);
        }
コード例 #6
0
        public static int  Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            var commandLineParser = new CommandLineParser.CommandLineParser();

            var sourcePath = new FileArgument('i', "input", "Source file path")
            {
                Optional = false
            };
            var outPath = new FileArgument('o', "output", "Output file path")
            {
                Optional = true, FileMustExist = false
            };

            var lexicalAnalysis = new SwitchArgument('l', "lexical", false);
            var syntaxAnalysis  = new SwitchArgument('s', "syntax", false);
            var semanticsCheck  = new SwitchArgument('c', "semantics", "turn off semantics check", true);
            var codeGeneration  = new SwitchArgument('a', "assembler", "generate assembler", false);
            var optimization    = new SwitchArgument('O', "optimization", "optimization", false);

            commandLineParser.Arguments.Add(sourcePath);
            commandLineParser.Arguments.Add(outPath);
            commandLineParser.Arguments.Add(lexicalAnalysis);
            commandLineParser.Arguments.Add(syntaxAnalysis);
            commandLineParser.Arguments.Add(semanticsCheck);
            commandLineParser.Arguments.Add(codeGeneration);
            commandLineParser.Arguments.Add(optimization);

            var compileStageGroupCertification = new ArgumentGroupCertification("l,s,a", EArgumentGroupCondition.ExactlyOneUsed);

            commandLineParser.Certifications.Add(compileStageGroupCertification);

            try {
                commandLineParser.ParseCommandLine(args);
            }
            catch (CommandLineException) {
                commandLineParser.ShowUsage();
                return(1);
            }
            using (var output = outPath.Value == null ? Console.Out : new StreamWriter(outPath.StringValue))
                using (var input = new StreamReader(sourcePath.OpenFileRead())) {
                    if (lexicalAnalysis.Value)
                    {
                        PerformLexicalAnalysis(input, output);
                    }

                    if (syntaxAnalysis.Value)
                    {
                        PerformSyntaxAnalysis(input, output, semanticsCheck.Value);
                    }

                    if (codeGeneration.Value)
                    {
                        PerformCodeGeneration(input, output, optimization.Value);
                    }
                }

            return(0);
        }
コード例 #7
0
        static void Main(string[] args)
        {
            CommandLineParser.CommandLineParser parser = new CommandLineParser.CommandLineParser();

            SwitchArgument debugFlag      = new SwitchArgument('d', "debug", "Enable debug mode", false);
            FileArgument   definitionFile = new FileArgument('f', "file", "Path to skin definition file");

            definitionFile.Optional = false;
            DirectoryArgument steamDirectory = new DirectoryArgument('s', "steam", "Path to Steam directory");

            steamDirectory.Optional = false;
            DirectoryArgument baseDirectory    = new DirectoryArgument('b', "base", "Path to directory containing skin bases. Defaults to %STEAM_FOLDER%/skins/");
            SwitchArgument    nobackupFlag     = new SwitchArgument('n', "nobackup", "Backup old skin folder before writing new one", false);
            SwitchArgument    activateSkinFlag = new SwitchArgument('a', "activate", "Activate skin after compilation", false);

            //dumbResponse = Array.Exists(args, el => el == "--dumb") || Array.Exists(args, el => el == "-q");

            parser.Arguments.Add(debugFlag);
            parser.Arguments.Add(definitionFile);
            parser.Arguments.Add(steamDirectory);
            parser.Arguments.Add(baseDirectory);
            parser.Arguments.Add(nobackupFlag);
            parser.Arguments.Add(activateSkinFlag);

#if !DEBUG
            try
            {
#endif
            parser.ParseCommandLine(args);
#if !DEBUG
            try
            {
#endif
            Core.backupEnabled = !nobackupFlag.Value;
            Core.debugMode     = debugFlag.Value;
            Core.activateSkin  = activateSkinFlag.Value;
            Core.Compile(definitionFile.Value, steamDirectory.Value, baseDirectory.Value);
#if !DEBUG
        }

        catch (Exception e)
        {
            Console.WriteLine(e.Message);
            Environment.Exit(2);
        }
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
        Environment.Exit(1);
    }
#endif
#if DEBUG
            Console.ReadKey();
#endif
        }
コード例 #8
0
        static int Main(string[] args)
        {
            bool isElevated;

            using (WindowsIdentity identity = WindowsIdentity.GetCurrent())
            {
                WindowsPrincipal principal = new WindowsPrincipal(identity);
                isElevated = principal.IsInRole(WindowsBuiltInRole.Administrator);
            }
            if (!isElevated)
            {
                Console.Error.WriteLine("You must be Administrator to run this.");
                return(-2);
            }
            CommandLineParser.CommandLineParser parser = new CommandLineParser.CommandLineParser
            {
                ShowUsageHeader = "ProcSurgeon - Minimal ProcMon logs for when a process starts."
            };
            FileArgument procMon = new FileArgument('p', "procmon", "Path of the procmon executable")
            {
                FileMustExist = true,
                Optional      = false
            };
            FileArgument target = new FileArgument('t', "target", "Path of the target executable")
            {
                FileMustExist = true,
                Optional      = false
            };
            ValueArgument <string> output = new ValueArgument <string>('o', "output", "Path of the output")
            {
                Optional = false
            };
            ValueArgument <int> time = new ValueArgument <int>('m', "millis", "How many milliseconds to log after starting the target." +
                                                               " If you do not include this parameter, ProcSurgeon will wait for the target process to exit.")
            {
                DefaultValue = 0
            };

            parser.Arguments.Add(procMon);
            parser.Arguments.Add(target);
            parser.Arguments.Add(output);
            parser.Arguments.Add(time);
            try
            {
                parser.ParseCommandLine(args);
            }
            catch (CommandLineException e)
            {
                Console.Error.WriteLine(e.Message);
                parser.ShowUsage();
                return(-1);
            }
            Execute(procMon.Value.FullName, target.Value.FullName, output.Value, time.Value);
            return(0);
        }
コード例 #9
0
        public void ArgumentTranslator_LocalFileParse_FileArgumentExpected()
        {
            var id       = Guid.NewGuid();
            var filePath = "local://" + id;

            var expected = new FileArgument(id);

            var result = _translator.Process(new object[] { filePath });

            Assert.Equal(expected.FileId, ((FileArgument)result.First()).FileId);
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: SteamCustomizer/Compiler
        static void Main(string[] args)
        {
            CommandLineParser.CommandLineParser parser = new CommandLineParser.CommandLineParser();

            SwitchArgument debugFlag = new SwitchArgument('d', "debug", "Enable debug mode", false);
            FileArgument definitionFile = new FileArgument('f', "file", "Path to skin definition file");
            definitionFile.Optional = false;
            DirectoryArgument steamDirectory = new DirectoryArgument('s', "steam", "Path to Steam directory");
            steamDirectory.Optional = false;
            DirectoryArgument baseDirectory = new DirectoryArgument('b', "base", "Path to directory containing skin bases. Defaults to %STEAM_FOLDER%/skins/");
            SwitchArgument nobackupFlag = new SwitchArgument('n', "nobackup", "Backup old skin folder before writing new one", false);
            SwitchArgument activateSkinFlag = new SwitchArgument('a', "activate", "Activate skin after compilation", false);

            //dumbResponse = Array.Exists(args, el => el == "--dumb") || Array.Exists(args, el => el == "-q");

            parser.Arguments.Add(debugFlag);
            parser.Arguments.Add(definitionFile);
            parser.Arguments.Add(steamDirectory);
            parser.Arguments.Add(baseDirectory);
            parser.Arguments.Add(nobackupFlag);
            parser.Arguments.Add(activateSkinFlag);

            #if !DEBUG
            try
            {
            #endif
                parser.ParseCommandLine(args);
            #if !DEBUG
                try
                {
            #endif
                    Core.backupEnabled = !nobackupFlag.Value;
                    Core.debugMode = debugFlag.Value;
                    Core.activateSkin = activateSkinFlag.Value;
                    Core.Compile(definitionFile.Value, steamDirectory.Value, baseDirectory.Value);
            #if !DEBUG
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Environment.Exit(2);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Environment.Exit(1);
            }
            #endif
            #if DEBUG
            Console.ReadKey();
            #endif
        }
コード例 #11
0
 public void Setvalue_InvalidFileName()
 {
     try
     {
         var sut = new FileArgument(NAME, DESCRIPTION, mustExist: true);
         sut.SetValue(INVALID_FILE_NAME);
     }
     catch (Exception ex)
     {
         Assert.AreEqual("Argument 'f' is invalid", ex.Message);
         throw;
     }
 }
コード例 #12
0
        private static string GetSettingsFilePathFromCmdLineArgs(string[] args)
        {
            string settingsFilePath = "settings.json";
            var    parser           = new CommandLineParser.CommandLineParser();
            var    fileArgument     = new FileArgument('f', "settings");

            fileArgument.FileMustExist = true;
            parser.Arguments.Add(fileArgument);
            parser.ParseCommandLine(args);
            if (fileArgument.Parsed)
            {
                settingsFilePath = fileArgument.Value.FullName;
            }

            return(settingsFilePath);
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: gpavlovych/GerberTools
        static int Main(string[] args)
        {
            var settings = Properties.Settings.Default;

            CommandLineParser.CommandLineParser parser = new CommandLineParser.CommandLineParser(); //switch argument is meant for true/false logic
            FileArgument inputFile = new FileArgument('i', "input", "Input Excellon file");

            inputFile.FileMustExist = true;
            inputFile.Optional      = false;
            FileArgument outputFile = new FileArgument('o', "output", "Output GRBL file");

            outputFile.FileMustExist = false;
            outputFile.Optional      = false;
            ValueArgument <double> maximumZ = new ValueArgument <double>("zmax");

            maximumZ.DefaultValue = settings.zmax;
            ValueArgument <double> minimumZ = new ValueArgument <double>("zmin");

            minimumZ.DefaultValue = settings.zmin;
            parser.Arguments.Add(inputFile);
            parser.Arguments.Add(outputFile);
            parser.Arguments.Add(minimumZ);
            parser.Arguments.Add(maximumZ);
            try
            {
                parser.ParseCommandLine(args);
                var xlnConfig = new ExcellonToGCodeConverterConfig(
                    settings.drillFeed,
                    settings.moveFeed,
                    settings.spindle,
                    minimumZ.Value,
                    maximumZ.Value);
                var xlnConverter = new ExcellonToGCodeConverter(xlnConfig);
                using (var reader = inputFile.Value.OpenText())
                    using (var writer = new StreamWriter(outputFile.Value.OpenWrite()))
                    {
                        xlnConverter.Convert(reader, writer);
                    }

                return(0);
            }
            catch (CommandLineException e)
            {
                Console.WriteLine(e.Message);
                return(-1);
            }
        }
コード例 #14
0
        private static CommandLineParser.CommandLineParser CreateParser()
        {
            CommandLineParser.CommandLineParser        parser = new CommandLineParser.CommandLineParser();
            ValueArgument <SqlConnectionStringBuilder> connectionStringArgument = new ValueArgument <SqlConnectionStringBuilder>('c', "connectionString", "ConnectionString of the documented database")
            {
                Optional            = false,
                ConvertValueHandler = (stringValue) =>
                {
                    SqlConnectionStringBuilder connectionStringBuilder;
                    try
                    {
                        connectionStringBuilder = new SqlConnectionStringBuilder(stringValue);
                    }
                    catch
                    {
                        throw new InvalidConversionException("invalid connection string", "connectionString");
                    }
                    if (String.IsNullOrEmpty(connectionStringBuilder.InitialCatalog))
                    {
                        throw new InvalidConversionException("no InitialCatalog was specified", "connectionString");
                    }

                    return(connectionStringBuilder);
                }
            };
            FileArgument inputFileArgument = new FileArgument('i', "input", "original edmx file")
            {
                FileMustExist = true, Optional = false
            };
            FileArgument outputFileArgument = new FileArgument('o', "output", "output edmx file - Default : original edmx file")
            {
                FileMustExist = false, Optional = true
            };

            parser.Arguments.Add(connectionStringArgument);
            parser.Arguments.Add(inputFileArgument);
            parser.Arguments.Add(outputFileArgument);

            parser.IgnoreCase = true;
            return(parser);
        }
コード例 #15
0
        private async Task <(int ExitCode, IConsole Console)> RunCommand(string filename, bool allowNewFile = false)
        {
            var file = new FileArgument("file");

            file.AllowNewFile = allowNewFile;

            var command = new RootCommand();

            command.AddArgument(file);

            var console = new TestConsole();

            command.SetHandler((string file) =>
            {
                console.Out.Write("Success " + file);
            }, file);

            var exitCode = await command.InvokeAsync(filename, console);

            return(exitCode, console);
        }
コード例 #16
0
ファイル: FileArgumentTests.cs プロジェクト: jcapellman/filex
        public void FileArgument_UsageText()
        {
            var fArgument = new FileArgument();

            Assert.IsNotNull(fArgument.UsageText);
        }
コード例 #17
0
        static void Main(string[] args)
        {
            var commandLineParser = new CommandLineParser.CommandLineParser();

            var compilerPath = new FileArgument('c', "compiler", "Path to compiler")
            {
                Optional = false
            };

            var testsDirectory = new DirectoryArgument('t', "test-dir", "Path to tests directory")
            {
                Optional = false
            };

            var testLexer     = new SwitchArgument('l', "lexer", "Test lexer", false);
            var testParser    = new SwitchArgument('p', "parser", "Test parser", false);
            var testSemantics = new SwitchArgument('s', "semantics", "Test parser with semantics", false);
            var testCodeGen   = new SwitchArgument('g', "codegen", "Test code generation", false);
            var testAll       = new SwitchArgument('a', "all", "Launch all tests", false);

            commandLineParser.Arguments.Add(compilerPath);
            commandLineParser.Arguments.Add(testsDirectory);

            commandLineParser.Arguments.Add(testLexer);
            commandLineParser.Arguments.Add(testParser);
            commandLineParser.Arguments.Add(testSemantics);
            commandLineParser.Arguments.Add(testCodeGen);
            commandLineParser.Arguments.Add(testAll);

            var testGroupCertification = new ArgumentGroupCertification("a,p,l,s,g", EArgumentGroupCondition.AtLeastOneUsed);

            commandLineParser.Certifications.Add(testGroupCertification);

            try {
                commandLineParser.ParseCommandLine(args);
            }
            catch (CommandLineException) {
                commandLineParser.ShowUsageHeader = "dotnet Tester.dll [pathToCompiler] [pathToTestsRoot]";
                commandLineParser.ShowUsage();
            }


            if (testLexer.Value || testAll.Value)
            {
                TestLexer(compilerPath.Value.FullName, testsDirectory.Value.FullName);
            }

            if (testParser.Value || testAll.Value)
            {
                TestParser(compilerPath.Value.FullName, testsDirectory.Value.FullName, "parser");
            }

            if (testSemantics.Value || testAll.Value)
            {
                TestParser(compilerPath.Value.FullName, testsDirectory.Value.FullName, "semantics", true);
            }

            if (testCodeGen.Value || testAll.Value)
            {
                string nasmPath;
                string gccPath;

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    //todo: remove hardcode?
                    nasmPath = @"C:\Program Files\NASM\nasm.exe";
                    gccPath  = @"C:\Users\Alexey\dev\toolchains\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin\gcc.exe";
                }
                else
                {
                    nasmPath = "nasm";
                    gccPath  = "gcc";
                }
                TestCodeGen(compilerPath.Value.FullName, nasmPath, gccPath, testsDirectory.Value.FullName, "codegen");
            }
        }
コード例 #18
0
        public void Constructor_MustExist()
        {
            var sut = new FileArgument(NAME, DESCRIPTION, mustExist: true);

            Assert.IsTrue(sut.MustExist);
        }
コード例 #19
0
        public void Syntax()
        {
            var sut = new FileArgument(NAME, DESCRIPTION, true);

            Assert.AreEqual("/f <File>", sut.Syntax);
        }
コード例 #20
0
        public void Constructor()
        {
            var sut = new FileArgument(NAME, DESCRIPTION);

            Assert.IsFalse(sut.MustExist);
        }
コード例 #21
0
ファイル: Program.cs プロジェクト: txjmb/CommandLineParser
        public static void Main(string[] args)
        {
            var parser = new CommandLineParser.CommandLineParser();

            parser.ShowUsageOnEmptyCommandline = true;

            var p = new ParsingTarget();

            // read the argument attributes
            parser.ShowUsageHeader = "This is an interesting command";
            parser.ShowUsageFooter = "And that is all";
            parser.ExtractArgumentAttributes(p);
            parser.Certifications.Add(new DistinctGroupsCertification("d", "color")
            {
                Description = "This is this"
            });

            var examples = new List <string[]>();

            examples.Add(new string[0]);                                                //No arguments passed
            examples.Add(new[] { "/help" });                                            //show usage
            examples.Add(new[] { "/version", "1.3" });                                  //parses OK
            examples.Add(new[] { "/color", "red", "/version", "1.2" });                 //parses OK
            examples.Add(new[] { "/point", "[1;3]", "/o", "2" });                       //parses OK
            examples.Add(new[] { "/d", "C:\\Input", "/i", "in.txt", "/x", "out.txt" }); //parses OK
            examples.Add(new[] { "/show", "/hide" });                                   //parses OK
            examples.Add(new[] { "/d" });                                               // error, missing value
            examples.Add(new[] { "/d", "C:\\Input" });
            examples.Add(new[] { "file1", "file2" });

            foreach (string[] arguments in examples)
            {
                try
                {
                    if (arguments.Length == 0)
                    {
                        Console.WriteLine("INPUT: No arguments supplied.");
                    }
                    else
                    {
                        Console.WriteLine("INPUT: {0}", arguments);
                    }

                    parser.ParseCommandLine(arguments);

                    parser.ShowParsedArguments();
                    Console.WriteLine("RESULT: OK");
                    Console.WriteLine();
                }
                catch (CommandLineException e)
                {
                    Console.WriteLine("RESULT: EXC - " + e.Message);
                    Console.WriteLine();
                }
            }

            /*
             * Example: requiring additional arguments of certain type (1 file in this case)
             */
            FileArgument additionalFileArgument1 = new FileArgument('_');

            additionalFileArgument1.FileMustExist = false;
            additionalFileArgument1.Optional      = false;

            FileArgument additionalFileArgument2 = new FileArgument('_');

            additionalFileArgument2.FileMustExist = false;
            additionalFileArgument2.Optional      = false;

            parser.AdditionalArgumentsSettings.TypedAdditionalArguments.Clear();
            parser.AdditionalArgumentsSettings.TypedAdditionalArguments.Add(additionalFileArgument1);
            parser.AdditionalArgumentsSettings.TypedAdditionalArguments.Add(additionalFileArgument2);
            try
            {
                // this fails, because there is only one file
                parser.ParseCommandLine(new[] { "/d", "C:\\Input", "file1.txt" });
                parser.ShowParsedArguments();
            }
            catch (CommandLineException e)
            {
                Console.WriteLine("RESULT: EXC - " + e.Message);
                Console.WriteLine();
            }

            // two files - OK
            parser.ParseCommandLine(new[] { "/d", "C:\\Input", "file1.txt", "file2.txt" });
            parser.ShowParsedArguments();
            Console.WriteLine("RESULT: OK");
            Console.WriteLine();
        }
コード例 #22
0
ファイル: FileArgumentTests.cs プロジェクト: jcapellman/filex
        public void FileArgument_DefaultValue()
        {
            var fArgument = new FileArgument();

            Assert.IsFalse(fArgument.SupportsDefaultValue);
        }