public static async System.Threading.Tasks.Task ASyncMain(string[] args) { FluentCommandLineParser <BitCLIV1Args> commandLineParser = new FluentCommandLineParser <BitCLIV1Args>(); commandLineParser.Setup(arg => arg.Action) .As('a', "action") .Required() .WithDescription($"Action to perform. {nameof(BitCLIV1Action.Clean)} || {nameof(BitCLIV1Action.Generate)} || {nameof(BitCLIV1Action.Validate)}. Required"); commandLineParser.Setup(arg => arg.SolutionPath) .As('p', "path") .Required() .WithDescription("Path to solution file. Required."); commandLineParser.SetupHelp("?", "help") .Callback(helpText => Console.WriteLine(helpText)); ICommandLineParserResult result = commandLineParser.Parse(args); if (result.HasErrors == true) { Console.WriteLine(result.ErrorText); } else { BitCLIV1Args typedArgs = commandLineParser.Object; typedArgs.SolutionPath = Path.Combine(Environment.CurrentDirectory, typedArgs.SolutionPath); } }
private static async Task AsyncMain(string[] args) { FluentCommandLineParser <BitCLIV1Args> commandLineParser = new FluentCommandLineParser <BitCLIV1Args>(); commandLineParser.Setup(arg => arg.Action) .As('a', "action") .SetDefault(BitCLIV1Action.Generate) .WithDescription($"Action to perform. {nameof(BitCLIV1Action.Clean)} || {nameof(BitCLIV1Action.Generate)} || {nameof(BitCLIV1Action.Validate)}. Required"); commandLineParser.Setup(arg => arg.Path) .As('p', "path") .Required() .WithDescription("Path to solution file. Required."); commandLineParser.SetupHelp("?", "help") .Callback(helpText => WriteInfo(helpText)); ICommandLineParserResult result = commandLineParser.Parse(args); if (result.HasErrors == true) { throw new Exception(result.ErrorText); } else { BitCLIV1Args typedArgs = commandLineParser.Object; typedArgs.Path = Path.Combine(Environment.CurrentDirectory, typedArgs.Path); if (!File.Exists(typedArgs.Path)) { throw new FileNotFoundException($"Solution could not be found at {typedArgs.Path}"); } WriteInfo($"Solution Path: {typedArgs.Path}"); WriteInfo($"Action: {typedArgs.Action}"); try { WriteMessage("DotNetBuild started..."); using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false)) using (AutoResetEvent errorWaitHandle = new AutoResetEvent(false)) { using (Process dotnetBuildProcess = new Process()) { dotnetBuildProcess.StartInfo.UseShellExecute = false; dotnetBuildProcess.StartInfo.RedirectStandardOutput = dotnetBuildProcess.StartInfo.RedirectStandardError = true; dotnetBuildProcess.StartInfo.FileName = "dotnet"; dotnetBuildProcess.StartInfo.Arguments = $"build {typedArgs.Path}"; dotnetBuildProcess.StartInfo.CreateNoWindow = true; dotnetBuildProcess.StartInfo.WorkingDirectory = Directory.GetParent(typedArgs.Path).FullName; dotnetBuildProcess.OutputDataReceived += (sender, e) => { if (e.Data != null) { WriteMessage(e.Data); } else { outputWaitHandle.Set(); } }; dotnetBuildProcess.ErrorDataReceived += (sender, e) => { if (e.Data != null) { WriteError(e.Data); } else { errorWaitHandle.Set(); } }; dotnetBuildProcess.Start(); dotnetBuildProcess.BeginOutputReadLine(); dotnetBuildProcess.BeginErrorReadLine(); dotnetBuildProcess.WaitForExit(); outputWaitHandle.WaitOne(); errorWaitHandle.WaitOne(); } } WriteMessage("DotNetBuild completed"); } catch (Exception ex) { WriteError($"DotNetBuild Error => {ex.ToString()}"); } using (MSBuildWorkspace workspace = MSBuildWorkspace.Create()) { workspace.LoadMetadataForReferencedProjects = workspace.SkipUnrecognizedProjects = true; workspace.WorkspaceFailed += Workspace_WorkspaceFailed; await workspace.OpenSolutionAsync(typedArgs.Path); switch (typedArgs.Action) { case BitCLIV1Action.Generate: IProjectDtoControllersProvider controllersProvider = new DefaultProjectDtoControllersProvider(); IProjectDtosProvider dtosProvider = new DefaultProjectDtosProvider(controllersProvider); DefaultTypeScriptClientProxyGenerator generator = new DefaultTypeScriptClientProxyGenerator(new DefaultBitCodeGeneratorOrderedProjectsProvider(), new DefaultBitConfigProvider(), dtosProvider, new DefaultTypeScriptClientProxyDtoGenerator(), new DefaultTypeScriptClientContextGenerator(), controllersProvider, new DefaultProjectEnumTypesProvider(controllersProvider, dtosProvider)); await generator.GenerateCodes(workspace); break; case BitCLIV1Action.Validate: throw new NotImplementedException("Validate"); case BitCLIV1Action.Clean: throw new NotImplementedException("Clean"); default: throw new NotSupportedException(); } } } }