Пример #1
0
        static void Main(string[] args)
        {
            string path      = null;
            string outPath   = null;
            string outType   = null;
            var    space     = "Luis";
            string className = null;

            for (var i = 0; i < args.Length; ++i)
            {
                var arg = NextArg(ref i, args, allowCmd: true);
                if (arg != null)
                {
                    if (arg.StartsWith('-'))
                    {
                        arg = arg.ToLower();
                        switch (arg)
                        {
                        case "-cs":
                        case "-ts":
                        {
                            ++i;
                            var name = NextArg(ref i, args, optional: true);
                            if (name != null)
                            {
                                var lastDot = arg == "-cs" ? name.LastIndexOf('.') : -1;
                                if (lastDot == -1)
                                {
                                    className = name;
                                }
                                else
                                {
                                    space     = name.Substring(0, lastDot);
                                    className = name.Substring(lastDot + 1);
                                }
                            }
                            outType = arg.Substring(1);
                        }
                        break;

                        case "-o":
                        {
                            ++i;
                            outPath = NextArg(ref i, args);
                        }
                        break;

                        case "-v":
                        case "--version":
                            Console.WriteLine($"LUISGen version {System.Reflection.Assembly.GetExecutingAssembly().GetName().Version}");
                            break;

                        default:
                            Usage();
                            break;
                        }
                    }
                    else if (path == null)
                    {
                        path = arg;
                    }
                    else
                    {
                        Usage();
                    }
                }
            }
            if (path == null || outType == null)
            {
                Usage();
            }
            outPath = outPath ?? (path == "-" ? "." : Path.GetDirectoryName(path));

            if (path == "-")
            {
                Console.Error.WriteLine("Reading from stdin until EOF (Ctrl-Z).");
            }
            dynamic app;

            using (var inFile = path == "-" ? Console.In : new StreamReader(path))
            {
                app = JsonConvert.DeserializeObject(inFile.ReadToEnd());
            }
            className = className ?? ((string)app.name).Replace(' ', '_');
            if (outType == "cs")
            {
                var description = $"LUISGen {path} -cs {space}.{className} -o {outPath}";
                CSharp.Generate(description, app, className, space, outPath);
            }
            else if (outType == "ts")
            {
                var description = $"LUISGen {path} -ts {className} -o {outPath}";
                Typescript.Generate(description, app, className, outPath);
            }
        }
Пример #2
0
        public static void Main(string[] args)
        {
            Console.Error.WriteLine("\n\n---------------------------------------------------------- -\n");
            Console.Error.WriteLine(" NOTICE:\n");
            Console.Error.WriteLine(" This tool has been deprecated.\n");
            Console.Error.WriteLine(" All functionality was ported over to the new BF CLI.\n");
            Console.Error.WriteLine(" To learn more visit ");
            Console.Error.WriteLine("https://aka.ms/NewBFCLI\n");
            Console.Error.WriteLine("-----------------------------------------------------------\n\n");
            string path      = null;
            string outPath   = null;
            string outType   = null;
            var    space     = "Luis";
            string className = null;

            for (var i = 0; i < args.Length; ++i)
            {
                var arg = NextArg(ref i, args, allowCmd: true);
                if (arg != null)
                {
                    if (arg.StartsWith('-'))
                    {
                        arg = arg.ToLower();
                        switch (arg)
                        {
                        case "-cs":
                        case "-ts":
                        {
                            ++i;
                            var name = NextArg(ref i, args, optional: true);
                            if (name != null)
                            {
                                var lastDot = arg == "-cs" ? name.LastIndexOf('.') : -1;
                                if (lastDot == -1)
                                {
                                    className = name;
                                }
                                else
                                {
                                    space     = name.Substring(0, lastDot);
                                    className = name.Substring(lastDot + 1);
                                }
                            }
                            outType = arg.Substring(1);
                        }
                        break;

                        case "--stdin":
                        {
                            path = "--stdin";
                            break;
                        }

                        case "-o":
                        {
                            ++i;
                            outPath = NextArg(ref i, args);
                        }
                        break;

                        case "-v":
                        case "--version":
                            Console.WriteLine($"LUISGen version {System.Reflection.Assembly.GetExecutingAssembly().GetName().Version}");
                            break;

                        default:
                            Usage();
                            break;
                        }
                    }
                    else if (path == null)
                    {
                        path = arg;
                    }
                    else
                    {
                        Usage();
                    }
                }
            }
            if (path == null || outType == null)
            {
                Usage();
            }
            outPath = outPath ?? (path == "--stdin" ? "." : Path.GetDirectoryName(path));

            if (path == "--stdin")
            {
                Console.Error.WriteLine("Reading from stdin until EOF (Ctrl-Z).");
            }
            dynamic app;

            using (var inFile = path == "--stdin" ? Console.In : new StreamReader(path))
            {
                app = JsonConvert.DeserializeObject(inFile.ReadToEnd());
            }

            if (app == null)
            {
                Usage();
            }
            else
            {
                ReorderEntities(app, "entities");
                ReorderEntities(app, "prebuiltEntities");
                ReorderEntities(app, "closedLists");
                ReorderEntities(app, "regex_entities");
                ReorderEntities(app, "patternAnyEntities");
                ReorderEntities(app, "composites");

                className = className ?? ((string)app.name).Replace(' ', '_');
                if (outType == "cs")
                {
                    var description = $"LUISGen {path} -cs {space}.{className} -o {outPath}";
                    CSharp.Generate(description, app, className, space, outPath);
                }
                else if (outType == "ts")
                {
                    var description = $"LUISGen {path} -ts {className} -o {outPath}";
                    Typescript.Generate(description, app, className, outPath);
                }
            }
        }