Beispiel #1
0
        public async Task <object> RunAsync(CommandLineProcessor processor, IConsoleHost host)
        {
            if (!string.IsNullOrEmpty(Input) && !Input.StartsWith("/") && !Input.StartsWith("-"))
            {
                await ExecuteDocumentAsync(host, Input);
            }
            else
            {
                var hasNSwagJson = DynamicApis.FileExists("nswag.json");
                if (hasNSwagJson)
                {
                    await ExecuteDocumentAsync(host, "nswag.json");
                }

                var currentDirectory = DynamicApis.DirectoryGetCurrentDirectory();
                var files            = DynamicApis.DirectoryGetFiles(currentDirectory, "*.nswag");
                if (files.Any())
                {
                    foreach (var file in files)
                    {
                        await ExecuteDocumentAsync(host, file);
                    }
                }
                else if (!hasNSwagJson)
                {
                    host.WriteMessage("Current directory does not contain any .nswag files.");
                }
            }
            return(null);
        }
Beispiel #2
0
        private static string[] GetNSwagPath(string[] args)
        {
            var files = new List <string>();

            Queue <string> queue = new Queue <string>(args);

            while (queue.Any())
            {
                var arg = queue.Dequeue();
                if (arg.StartsWith("-"))
                {
                    if (arg.Equals("-c", StringComparison.OrdinalIgnoreCase))
                    {
                        while (true)
                        {
                            if (!queue.Any())
                            {
                                break;
                            }

                            arg = queue.Dequeue();
                            if (arg.StartsWith("-"))
                            {
                                break;
                            }

                            var tmpPath = arg;
                            if (Path.IsPathRooted(tmpPath))
                            {
                                files.Add(tmpPath);
                                continue;
                            }

                            if (arg.StartsWith('.'))
                            {
                                tmpPath = Path.Combine(Directory.GetCurrentDirectory(), arg);
                                files.Add(tmpPath);
                                continue;
                            }

                            tmpPath = Path.Combine(Directory.GetCurrentDirectory(), arg);
                            files.Add(tmpPath);
                        }
                    }
                }
            }

            if (files.Any())
            {
                return(files.ToArray());
            }

            var currentDirectory = DynamicApis.DirectoryGetCurrentDirectory();

            Console.WriteLine(currentDirectory);
            files = DynamicApis.DirectoryGetFiles(currentDirectory, "*.nswag").ToList();
            if (files.Any())
            {
                return(files.ToArray());
            }

            currentDirectory = AppContext.BaseDirectory;
            Console.WriteLine(currentDirectory);
            files = DynamicApis.DirectoryGetFiles(currentDirectory, "*.nswag").ToList();
            if (files.Any())
            {
                return(files.ToArray());
            }

            currentDirectory = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
            Console.WriteLine(currentDirectory);
            files = DynamicApis.DirectoryGetFiles(currentDirectory, "*.nswag").ToList();
            if (files.Any())
            {
                return(files.ToArray());
            }

            return(files.ToArray());
        }