Beispiel #1
0
        static async Task <int> Main(string[] args)
        {
            if (args.Length == 0)
            {
                args = new string[] { "--help" };
            }
            else if (args.Length == 1 && args[0].Equals("example") == false) // support drag & drop
            {
                ToCodeVerb toCode = new ToCodeVerb();
                toCode.inputPaths = args;
                toCode.fileName   = Path.GetFileName(args[0]) + "_gen";

                var result = await ToCodeVerb.Verb(toCode);

                return((int)result);
            }

            // var commandLineParser = new Parser(settings => settings.CaseSensitive = false);
            var commandLineParser = Parser.Default;
            var mainResult        = await commandLineParser
                                    .ParseArguments <ToCodeVerb, ExampleVerb>(args)
                                    .MapResult(
                (ToCodeVerb toCode) => ToCodeVerb.Verb(toCode),
                (ExampleVerb example) => ExampleVerb.Verb(example),
                err => Task.FromResult(ErrorCode.NoVerb));

            if (mainResult == ErrorCode.NoVerb)
            {
                Console.WriteLine($"wait input for exit..");
                Console.ReadKey();
            }

            return((int)mainResult);
        }
Beispiel #2
0
        public static async Task <ErrorCode> Verb(ExampleVerb option)
        {
            List <ISerializer> serializers = new List <ISerializer>();

            if ((option.format & SupportFileFormat.csv) == SupportFileFormat.csv)
            {
                serializers.Add(new CSVSerializer());
            }

            if ((option.format & SupportFileFormat.json) == SupportFileFormat.json)
            {
                serializers.Add(new JsonSerializerWrapper());
            }

            string folderPath = Path.Combine(Directory.GetCurrentDirectory(), "Example");

            if (serializers.Any())
            {
                Directory.CreateDirectory(folderPath);
            }

            List <Task> tasks = new List <Task>();

            foreach (var serializer in serializers)
            {
                string fileExtension = serializer.fileExtension;
                string filePath      = Path.Combine(folderPath, $"example.{fileExtension}");

                ClassFormat[] formats = ClassFormat.DummyArray;
                formats[0].className += fileExtension;
                formats[1].className += fileExtension;

                string text = serializer.Serialize(formats);
                tasks.Add(File.WriteAllTextAsync(filePath, text));
                System.Console.WriteLine($"example file create! path:{filePath}");
            }
            Task.WaitAll(tasks.ToArray());

            return(ErrorCode.Success);
        }