Example #1
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);
        }
        /// <summary>
        /// Entry point of the CLI.
        /// </summary>
        /// <param name="args">Command line arguments.</param>
        private static void Main(string[] args)
        {
            var cliParser         = new CommandLineParser.CommandLineParser();
            var directoryArgument = new DirectoryArgument('d', "directory", "The directory containing the files to match.")
            {
                DirectoryMustExist = true, Optional = true, DefaultValue = new DirectoryInfo(Environment.CurrentDirectory)
            };
            var fileExtensionArgument = new ValueArgument <string>('x', "extension", "The file extension (without dot) to match as a regular expression pattern, e.g. \"^(pdf|jpe?g)$\" or \"db$\". Matches all extensions if omitted.")
            {
                Optional = true, DefaultValue = string.Empty
            };
            var startDateArgument = new ValueArgument <DateTime>('s', "start-date", "The range start date (YYYY-MM-DD).")
            {
                Optional = false
            };
            var endDateArgument = new ValueArgument <DateTime>('e', "end-date", "The range end date (YYYY-MM-DD).")
            {
                Optional = false
            };

            cliParser.ShowUsageHeader = "Check if a directory containing files with named date ranges is missing any dates from a given range.";
            cliParser.Arguments.Add(directoryArgument);
            cliParser.Arguments.Add(fileExtensionArgument);
            cliParser.Arguments.Add(startDateArgument);
            cliParser.Arguments.Add(endDateArgument);
            cliParser.ShowUsageOnEmptyCommandline = true;

            try
            {
                cliParser.ParseCommandLine(args);
            }
            catch (CommandLineException cle)
            {
                Console.WriteLine(cle.Message);
                cliParser.ShowUsage();
                return;
            }
            catch (DirectoryNotFoundException dnfe)
            {
                Console.WriteLine(dnfe.Message.EndsWith(" and DirectoryMustExist flag is set to true.")
                    ? dnfe.Message.Substring(0, dnfe.Message.Length - 44)
                    : dnfe.Message);
                return;
            }

            if (!cliParser.ParsingSucceeded)
            {
                return;
            }

            if (startDateArgument.Value > endDateArgument.Value)
            {
                Console.WriteLine("The start date of the range cannot be later than the end date.");
                return;
            }

            Console.BackgroundColor = ConsoleColor.Black;

            if (HasMissingRanges(directoryArgument.Value, fileExtensionArgument.Value, (startDateArgument.Value, endDateArgument.Value), out (DateTime, DateTime)[] missingRanges))
Example #3
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
        }
Example #4
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
        }
        static void Main(string[] args)
        {
            CommandLineParser.CommandLineParser parser = new CommandLineParser.CommandLineParser()
            {
                CheckMandatoryArguments     = true,
                ShowUsageOnEmptyCommandline = true
            };

            DirectoryArgument schemaDirArg = new DirectoryArgument('s', "schema", "json schema source directory")
            {
                Optional           = false,
                DirectoryMustExist = true
            };
            DirectoryArgument typeScriptDirArg = new DirectoryArgument('t', "typescript", "typescript target directory")
            {
                Optional           = true,
                DirectoryMustExist = false
            };
            DirectoryArgument cSharpDirArg = new DirectoryArgument('c', "csharp", "c# target directory")
            {
                Optional           = true,
                DirectoryMustExist = false
            };

            SwitchArgument interactive = new SwitchArgument('i', "interactive", "interactive yes/no to continue", false);
            SwitchArgument recursive   = new SwitchArgument('r', "recursive", "recursive parsing from source directory", false);

            parser.Arguments.Add(schemaDirArg);
            parser.Arguments.Add(typeScriptDirArg);
            parser.Arguments.Add(cSharpDirArg);
            //parser.Arguments.Add(interactive);
            //parser.Arguments.Add(recursive);


            try
            {
                parser.ParseCommandLine(args);
                //parser.ShowParsedArguments();
                if (!parser.ParsingSucceeded)
                {
                    return;
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Exception parsing arguments:");
                System.Console.WriteLine(e.Message);
                parser.PrintUsage(System.Console.Out);
                System.Console.WriteLine("press any key to continue");
                System.Console.ReadKey();
                return;
            }


            if (typeScriptDirArg.DirectoryInfo == null &&
                cSharpDirArg.DirectoryInfo == null)
            {
                System.Console.WriteLine("TypeScript and/or C# target directory missing");
                System.Console.WriteLine("press any key to continue");
                System.Console.ReadKey();
                return;
            }

            var sDirInfo = schemaDirArg.DirectoryInfo;
            var tDirInfo = typeScriptDirArg.DirectoryInfo;
            var cDirInfo = cSharpDirArg.DirectoryInfo;

            if (tDirInfo != null && !tDirInfo.Exists)
            {
                tDirInfo.Create();
            }
            if (cDirInfo != null && !cDirInfo.Exists)
            {
                cDirInfo.Create();
            }



            //get only .json files
            var schemasFiles = sDirInfo.GetFiles().ToList().Where((f) => f.Extension.ToLower().Equals(".json")).ToList();

            System.Console.WriteLine("found {0} json schema files", schemasFiles.Count());
            foreach (FileInfo schemafile in schemasFiles)
            {
                System.Console.WriteLine("generating from {0} to", schemafile.Name);
                try
                {
                    var schema = JsonSchema4.FromFile(schemafile.FullName);
                    //typescript
                    if (tDirInfo != null)
                    {
                        var generator  = new TypeScriptGenerator(schema);
                        var typeScript = generator.GenerateFile();
                        Save(sDirInfo, tDirInfo, schemafile, typeScript, ".ts");
                    }
                    //c#
                    if (cDirInfo != null)
                    {
                        var generator = new CSharpGenerator(schema);
                        var cSharp    = generator.GenerateFile();
                        Save(sDirInfo, cDirInfo, schemafile, cSharp, ".cs");
                    }
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine("Exception: {0} ", ex.Message);
                    System.Console.WriteLine("Overstep and continue generating remaining?");
                    if (!GetYesOrNoUserInput())
                    {
                        return;
                    }
                }
            }
            //exit
            System.Console.WriteLine("Done!");
            System.Console.WriteLine("Press any key to exit.");
            System.Console.ReadKey();
        }
Example #6
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");
            }
        }
Example #7
0
        static void Main(string[] args)
        {
            // process args
            CommandLineParser.CommandLineParser parser =
                new CommandLineParser.CommandLineParser();

            var helpArgument = new SwitchArgument(
                'h', "help", "Display usage help", false);
            var configArgument = new SwitchArgument(
                'c', "config", "Only generate config file.", false);
            var inputArgument = new DirectoryArgument(
                'i', "input", "Path to the input folder. The folder must contain ApiDefinitions.cs and StructsAndEnums.cs");
            var outputArgument = new DirectoryArgument(
                'o', "output", "Path to the output folder");

            outputArgument.DirectoryMustExist = false;
            var namespaceArgument = new ValueArgument <string>(
                'n', "namespace", "Namespace for the individual objects");

            parser.Arguments.Add(helpArgument);
            parser.Arguments.Add(configArgument);
            parser.Arguments.Add(inputArgument);
            parser.Arguments.Add(outputArgument);
            parser.Arguments.Add(namespaceArgument);

            try
            {
                parser.ParseCommandLine(args);

                if (helpArgument.Parsed && helpArgument.Value)
                {
                    parser.ShowUsage();
                    Console.WriteLine(@"First step is to generate a config file:
dotnet run -- -i ../Bindings/ -o ../MaterialComponents.Parsed/ -c

Second step is to edit the config file and set EnableBinding and EnableXFWrapper for desired components.

Third step is to generate separated ObjC wrappers and Xamarin Forms wrappers/renderers:
dotnet run -- -i ../Bindings/ -o ../MaterialComponents.Parsed/ -n MaterialComponents");
                }
            }
            catch (CommandLineException e)
            {
                Console.WriteLine(e.Message);
                return;
            }
            catch (System.IO.DirectoryNotFoundException e)
            {
                Console.WriteLine(e.Message);
                return;
            }

            // load input files - ApiDefinitions.cs StructsAndEnums.cs
            var sharpieParser = new SharpieParser();
            var inputFolder   = inputArgument.Parsed ? inputArgument.Value : new DirectoryInfo(DefaultInputFolder);

            try
            {
                sharpieParser.ParseInputFolder(inputFolder.FullName);
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
                return;
            }

            // output each interface/delegate/enum into separate files, add usings, and namespace
            var outputFolder = outputArgument.Parsed ? outputArgument.Value : new DirectoryInfo(DefaultOutputFolder);
            var ns           = namespaceArgument.Parsed ? namespaceArgument.Value : DefaultNamespace;
            var cfgOnly      = configArgument.Parsed ? configArgument.Value : false;

            // Create or update JSON config file that lists all components we are interested in generating.
            sharpieParser.UpdateOrCreateConfig(outputFolder.FullName, DefaultConfigName);

            if (!cfgOnly)
            {
                // Using JSON config create bindings
                sharpieParser.WriteOutput(outputFolder.FullName + "/Components/", ns);
                sharpieParser.WriteProject(outputFolder.FullName + "/Components/", DefaultProject);

                // Using JSON config generates XF wrappers
                sharpieParser.WriteXFWrappers(outputFolder.FullName,
                                              DefaultConfigName,
                                              DefaultXfFolder,
                                              DefaultIOSFolder,
                                              DefaultAndroidFolder,
                                              DefaultNamespace);
            }
        }