public int Run(string[] args) { CommandLineApplication app = new CommandLineApplication(false) { Name = "Prospect code generator", Description = "Runs different methods as dnx commands to help you to create some of picies of code", }; var help = app.HelpOption("-?|--help"); var angular = app.Option("-a|--angular", "Angular code generation", CommandOptionType.NoValue); var csharp = app.Option("-c|--csharp", "C# code generarion", CommandOptionType.NoValue); var typeScript = app.Option("-t|--typescript", "TypeScript code generarion", CommandOptionType.NoValue); app.OnExecute(() => { if (csharp.HasValue()) { CSharpRunner runner = new CSharpRunner(); return runner.Run(Config.CSharp); } if (angular.HasValue()) { AngularRunner runner = new AngularRunner(); return runner.Run(Config.Angular, args); } if (typeScript.HasValue()) { TypeScriptRunner runner = new TypeScriptRunner(); return runner.Run(Config.TypeScript); } app.ShowHelp(); return 0; }); return app.Execute(args); }
private static bool SetUp(string[] args) { CommandLineApplication result = new CommandLineApplication(false) { Name = "xpg", FullName = "XCommon Project Generator", Description = "Generate new C# project with support to Angular2 and Material Design", }; var help = result.HelpOption("--help"); var csharp = result.Option("--csharp", "Create new C# application", CommandOptionType.NoValue); var node = result.Option("--node", "Create new NODE application", CommandOptionType.NoValue); var angular = result.Option("--angular", "Create angular resource", CommandOptionType.NoValue); result.OnExecute(() => { bool error = false; List<string> messages = new List<string>(); if (angular.HasValue()) { ApplicationBase.PrintLogo(); var param = args.ToList(); param.Remove("--angular"); AngularRunner runner = new AngularRunner(); return runner.Run(new AngularConfig(), param.ToArray()); } if (!csharp.HasValue() && !node.HasValue()) { messages.Add("You need to chose which type of application you whant to create, use --node or --csharp"); error = true; } if (!csharp.HasValue() && !node.HasValue()) { messages.Add("You can't create both, choose --node or --csharp"); error = true; } if (!error && csharp.HasValue()) { App = new Application.CSharp.CSharpApplication(args); } if (!error && node.HasValue()) { App = new Application.Node.NodeApplication(args); } if (error) { ApplicationBase.PrintLogo(); result.ShowHelp(); Console.WriteLine(); Console.WriteLine(" - Errors"); messages.ForEach(msg => Console.WriteLine($" * {msg}")); return -1; } return 0; }); return result.Execute(args) == 0; }
internal int Run(AngularConfig config, string[] args) { var appCommand = new CommandLineApplication(false) { Name = "Angular Generator", FullName = "Angular Generator", Description = "Angular Generator can generate Component, Service and Pipe", }; var help = appCommand.HelpOption("-h|--help"); var name = appCommand.Argument("[terms]", "Name of items to be generate"); var feature = appCommand.Option("-f|--feature", "Feature", CommandOptionType.SingleValue); var component = appCommand.Option("-c|--component", "Generate a new Component with HTML, TS and SCSS", CommandOptionType.NoValue); var service = appCommand.Option("-s|--service", "Generate a new Angular service", CommandOptionType.NoValue); appCommand.OnExecute(() => { if (appCommand.OptionHelp.HasValue()) { appCommand.ShowHelp(); return 0; } IndexExport index = new IndexExport(); if (component.HasValue()) { var erro = false; if (!feature.HasValue()) { Console.WriteLine("Name of component doesn't specified"); erro = true; } if (string.IsNullOrEmpty(name.Value) || !feature.HasValue()) { Console.WriteLine("Name of component doesn't specified"); erro = true; } if (erro) { return -1; } Component componentWritter = new Component(); string path = ParsePath(config, feature.Value(), ItemType.Component); componentWritter.Run(path, feature.Value(), config.HtmlRoot, config.StyleInclude, GetItems(appCommand, name)); index.Run(path); return 0; } if (service.HasValue()) { if (string.IsNullOrEmpty(name.Value)) { Console.WriteLine("Name of component/feature doesn't specified"); return -1; } Service serviceWritter = new Service(); string path = ParsePath(config, string.Empty, ItemType.Service); serviceWritter.Run(path, GetItems(appCommand, name)); index.Run(path); return 0; } appCommand.ShowHelp(); return 0; }); var arguments = args.ToList(); arguments.Remove("-a"); return appCommand.Execute(arguments.ToArray()); }
protected override void SetUp(string[] args) { args = RemoveArg("--csharp", args); CommandLineApplication result = new CommandLineApplication(false) { Name = "xpg", FullName = "XCommon Project Generator", Description = "Generate new C# project with support to Angular2 and Material Design", }; var help = result.HelpOption("--help"); var simple = result.Option("-s|--simple", "Create new C# application, without business layer", CommandOptionType.NoValue); var path = result.Option("-p|--path", "Set the path to the new application", CommandOptionType.SingleValue); var name = result.Option("-n|--name", "Set the name of the new application", CommandOptionType.SingleValue); var noangular = result.Option("--noangular", "Create new C# application, without angular2 on web project", CommandOptionType.NoValue); var notest = result.Option("--notest", "Create new C# application, without test project", CommandOptionType.NoValue); var nogenerator = result.Option("--nogenerator", "Create new C# application, without code generator project", CommandOptionType.NoValue); result.OnExecute(() => { bool error = false; List<string> messages = new List<string>(); if (!path.HasValue()) { error = true; messages.Add("Path not specified"); } if (!name.HasValue()) { error = true; messages.Add("Name not specified"); } if (error) { result.ShowHelp(); Console.WriteLine(); Console.WriteLine(" - Errors"); messages.ForEach(msg => Console.WriteLine($" * {msg}")); return -1; } var config = new CSharpApplicationConfig { Name = name.Value(), Path = path.Value(), Full = !simple.HasValue(), Angular = !noangular.HasValue(), Generator = !nogenerator.HasValue(), Test = !notest.HasValue() }; Create(config); return 0; }); PrintLogo(); result.Execute(args); }