2 * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.Text.RegularExpressions;
20 using System.Threading.Tasks;
23 namespace GenDummy.CommandLine
27 FileInfo[] inputFiles;
29 public async Task Run(Options options)
31 if (Directory.Exists(options.InputPath))
33 options.IsMultiple = true;
36 if (options.IsMultiple)
38 if (string.IsNullOrEmpty(options.OutputPath) || !Directory.Exists(options.OutputPath))
40 ExitWithError("Directory should be set as the output path.");
42 DirectoryInfo inputDirInfo = new DirectoryInfo(options.InputPath);
43 inputFiles = inputDirInfo.GetFiles("*.cs", SearchOption.AllDirectories);
47 if (!File.Exists(options.InputPath))
49 ExitWithError("Couldn't find the input file : " + options.InputPath);
51 FileInfo fileInfo = new FileInfo(options.InputPath);
52 inputFiles = new FileInfo[] { fileInfo };
55 DummyProject project = new DummyProject();
57 Regex rgx = new Regex("^" + options.InputPath.Replace("\\", "\\\\"));
58 foreach (var f in inputFiles)
60 if (string.IsNullOrEmpty(options.OutputPath))
62 await project.GenerateDummy(f.FullName);
64 else if (Directory.Exists(options.OutputPath))
66 var outputFile = rgx.Replace(f.FullName, options.OutputPath);
67 Directory.CreateDirectory(Path.GetDirectoryName(outputFile));
68 await project.GenerateDummy(f.FullName, outputFile);
72 await project.GenerateDummy(f.FullName, options.OutputPath);
77 Console.WriteLine($"Processed : {f.FullName}");
82 static void Main(string[] args)
84 Program program = new Program();
85 Parser.Default.ParseArguments<Options>(args)
86 .WithParsed(opts => program.Run(opts).Wait());
89 static void ExitWithError(string err)
91 Console.Error.WriteLine("Error: " + err);