From ee718ffb3a6a7f6464dc4c37a0a4e3deea751d7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 27 Aug 2020 16:34:13 +0300 Subject: [PATCH 1/2] Resolved #5205: Add "--skip-cli-version-check" option to ABP CLI. --- docs/en/CLI.md | 6 ++++++ .../src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs | 10 +++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/en/CLI.md b/docs/en/CLI.md index 99808c3ba5..ff828b91a3 100644 --- a/docs/en/CLI.md +++ b/docs/en/CLI.md @@ -16,6 +16,12 @@ To update an existing installation: dotnet tool update -g Volo.Abp.Cli ```` +## Global Options + +While each command may have a set of options, there are some global options those can be used with any command; + +* `--skip-cli-version-check`: Skips to check the latest version of the ABP CLI. If you don't specify, it will check the latest version and shows a warning message if there is a newer version of the ABP CLI. + ## Commands Here, the list of all available commands before explaining their details: diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs index ef6eb79042..a984d79771 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs @@ -41,9 +41,13 @@ namespace Volo.Abp.Cli { Logger.LogInformation("ABP CLI (https://abp.io)"); - await CheckCliVersionAsync(); - var commandLineArgs = CommandLineArgumentParser.Parse(args); + + if (!commandLineArgs.Options.ContainsKey("skip-cli-version-check")) + { + await CheckCliVersionAsync(); + } + var commandType = CommandSelector.Select(commandLineArgs); using (var scope = ServiceScopeFactory.CreateScope()) @@ -72,7 +76,7 @@ namespace Volo.Abp.Cli var currentCliVersion = await GetCurrentCliVersion(assembly); var updateChannel = GetUpdateChannel(currentCliVersion); - Logger.LogInformation($"Version {currentCliVersion} ({updateChannel} channel)"); + Logger.LogInformation($"Version {currentCliVersion} ({updateChannel})"); try { From 28b13d3af39598bde9644f7e5d871a5fcf3eced4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 27 Aug 2020 16:35:48 +0300 Subject: [PATCH 2/2] Add options to GenerateProxyCommand --- .../Abp/Cli/Commands/GenerateProxyCommand.cs | 76 ++++++++++++++++--- 1 file changed, 65 insertions(+), 11 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GenerateProxyCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GenerateProxyCommand.cs index ab680ce4b8..5e88417b4a 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GenerateProxyCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GenerateProxyCommand.cs @@ -2,7 +2,6 @@ using System; using System.IO; using System.Text; using System.Threading.Tasks; -using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Volo.Abp.Cli.Args; using Volo.Abp.Cli.Utils; @@ -17,7 +16,31 @@ namespace Volo.Abp.Cli.Commands CheckAngularJsonFile(); CheckNgSchematics(); - CmdHelper.RunCmd("npx ng g @abp/ng.schematics:proxy"); + var prompt = commandLineArgs.Options.ContainsKey("p") || commandLineArgs.Options.ContainsKey("prompt"); + var defaultValue = prompt ? null : "__default"; + + var module = commandLineArgs.Options.GetOrNull(Options.Module.Short, Options.Module.Long) ?? defaultValue; + var source = commandLineArgs.Options.GetOrNull(Options.Source.Short, Options.Source.Long) ?? defaultValue; + var target = commandLineArgs.Options.GetOrNull(Options.Target.Short, Options.Target.Long) ?? defaultValue; + + var commandBuilder = new StringBuilder("npx ng g @abp/ng.schematics:proxy"); + + if (module != null) + { + commandBuilder.Append($" --module {module}"); + } + + if (source != null) + { + commandBuilder.Append($" --source {source}"); + } + + if (target != null) + { + commandBuilder.Append($" --target {target}"); + } + + CmdHelper.RunCmd(commandBuilder.ToString()); return Task.CompletedTask; } @@ -29,20 +52,21 @@ namespace Volo.Abp.Cli.Commands if (!File.Exists(packageJsonPath)) { throw new CliUsageException( - "package.json file not found" + - Environment.NewLine + - GetUsageInfo() + "package.json file not found" + + Environment.NewLine + + GetUsageInfo() ); } - var schematicsPackageNode = (string) JObject.Parse(File.ReadAllText(packageJsonPath))["devDependencies"]?["@abp/ng.schematics"]; + var schematicsPackageNode = + (string) JObject.Parse(File.ReadAllText(packageJsonPath))["devDependencies"]?["@abp/ng.schematics"]; if (schematicsPackageNode == null) { throw new CliUsageException( - "\"@abp/ng.schematics\" NPM package should be installed to the devDependencies before running this command!" + - Environment.NewLine + - GetUsageInfo() + "\"@abp/ng.schematics\" NPM package should be installed to the devDependencies before running this command!" + + Environment.NewLine + + GetUsageInfo() ); } } @@ -69,9 +93,12 @@ namespace Volo.Abp.Cli.Commands sb.AppendLine(""); sb.AppendLine(" abp generate-proxy"); sb.AppendLine(""); - sb.AppendLine("Examples:"); + sb.AppendLine("Options:"); sb.AppendLine(""); - sb.AppendLine(" abp generate-proxy"); + sb.AppendLine("-m|--module (default: 'app') The name of the backend module you wish to generate proxies for."); + sb.AppendLine("-s|--source (default: 'defaultProject') Angular project name to resolve the root namespace & API definition URL from."); + sb.AppendLine("-t|--target (default: 'defaultProject') Angular project name to place generated code in."); + sb.AppendLine("-p|--prompt Asks the options from the command line prompt (for the missing options)"); sb.AppendLine(""); sb.AppendLine("See the documentation for more info: https://docs.abp.io/en/abp/latest/CLI"); @@ -82,5 +109,32 @@ namespace Volo.Abp.Cli.Commands { return "Generates Angular service proxies and DTOs to consume HTTP APIs."; } + + public static class Options + { + public static class Module + { + public const string Short = "m"; + public const string Long = "module"; + } + + public static class Source + { + public const string Short = "s"; + public const string Long = "source"; + } + + public static class Target + { + public const string Short = "t"; + public const string Long = "target"; + } + + public static class Prompt + { + public const string Short = "p"; + public const string Long = "prompt"; + } + } } }