[Build] Update .NETCore reference assemblies for tizen50 TFM
[platform/core/csapi/tizenfx.git] / tools / src / GenDummy.CommandLine / Program.cs
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18 using System.IO;
19 using System.Text.RegularExpressions;
20 using System.Threading.Tasks;
21 using CommandLine;
22
23 namespace GenDummy.CommandLine
24 {
25     class Program
26     {
27         FileInfo[] inputFiles;
28
29         public async Task Run(Options options)
30         {
31             if (Directory.Exists(options.InputPath))
32             {
33                 options.IsMultiple = true;
34             }
35
36             if (options.IsMultiple)
37             {
38                 if (string.IsNullOrEmpty(options.OutputPath) || !Directory.Exists(options.OutputPath))
39                 {
40                     ExitWithError("Directory should be set as the output path.");
41                 }
42                 DirectoryInfo inputDirInfo = new DirectoryInfo(options.InputPath);
43                 inputFiles = inputDirInfo.GetFiles("*.cs", SearchOption.AllDirectories);
44             }
45             else
46             {
47                 if (!File.Exists(options.InputPath))
48                 {
49                     ExitWithError("Couldn't find the input file : " + options.InputPath);
50                 }
51                 FileInfo fileInfo = new FileInfo(options.InputPath);
52                 inputFiles = new FileInfo[] { fileInfo };
53             }
54
55             DummyProject project = new DummyProject();
56
57             Regex rgx = new Regex("^" + options.InputPath.Replace("\\", "\\\\"));
58             foreach (var f in inputFiles)
59             {
60                 if (string.IsNullOrEmpty(options.OutputPath))
61                 {
62                     await project.GenerateDummy(f.FullName);
63                 }
64                 else if (Directory.Exists(options.OutputPath))
65                 {
66                     var outputFile = rgx.Replace(f.FullName, options.OutputPath);
67                     Directory.CreateDirectory(Path.GetDirectoryName(outputFile));
68                     await project.GenerateDummy(f.FullName, outputFile);
69                 }
70                 else
71                 {
72                     await project.GenerateDummy(f.FullName, options.OutputPath);
73                 }
74                 
75                 if (options.Verbose)
76                 {
77                     Console.WriteLine($"Processed : {f.FullName}");
78                 }
79             }
80         }
81
82         static void Main(string[] args)
83         {
84             Program program = new Program();
85             Parser.Default.ParseArguments<Options>(args)
86                 .WithParsed(opts => program.Run(opts).Wait());
87         }
88
89         static void ExitWithError(string err)
90         {
91             Console.Error.WriteLine("Error: " + err);
92             Environment.Exit(1);
93         }
94
95     }
96 }