From bb38ffc28ab6786fe45b428654bab851d8f8504d Mon Sep 17 00:00:00 2001 From: Alper Ebicoglu Date: Fri, 13 Dec 2019 09:25:40 +0300 Subject: [PATCH] fixes #2387 and fix CLI command descriptions. --- .../Volo/Abp/Cli/CliService.cs | 23 ++++++++------- .../Volo/Abp/Cli/Commands/AddModuleCommand.cs | 5 ++-- .../Abp/Cli/Commands/AddPackageCommand.cs | 4 +-- .../Volo/Abp/Cli/Commands/GetSourceCommand.cs | 2 +- .../Volo/Abp/Cli/Commands/HelpCommand.cs | 2 +- .../Volo/Abp/Cli/Commands/LoginCommand.cs | 2 +- .../Volo/Abp/Cli/Commands/LogoutCommand.cs | 2 +- .../Volo/Abp/Cli/Commands/NewCommand.cs | 2 +- .../Volo/Abp/Cli/Commands/SuiteCommand.cs | 2 +- .../Volo/Abp/Cli/Commands/UpdateCommand.cs | 3 +- .../Volo/Abp/Cli/Http/CliHttpClient.cs | 28 ++++++++++++++----- .../Volo/Abp/Cli/NuGet/NuGetService.cs | 2 +- 12 files changed, 43 insertions(+), 34 deletions(-) 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 f02f03d502..436e169aad 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 @@ -69,7 +69,7 @@ namespace Volo.Abp.Cli { var assembly = typeof(CliService).Assembly; var toolPath = GetToolPath(assembly); - var currentCliVersion = await GetCurrentCliVersion(toolPath, assembly); + var currentCliVersion = await GetCurrentCliVersion(assembly); var updateChannel = GetUpdateChannel(currentCliVersion); Logger.LogInformation($"Version {currentCliVersion} ({updateChannel} channel)"); @@ -100,26 +100,25 @@ namespace Volo.Abp.Cli return assembly.Location.Substring(0, assembly.Location.IndexOf(".store", StringComparison.Ordinal)); } - private async Task GetCurrentCliVersion(string toolPath, Assembly assembly) + private static async Task GetCurrentCliVersion(Assembly assembly) { SemanticVersion currentCliVersion = default; - if (!string.IsNullOrEmpty(toolPath)) + + var consoleOutput = new StringReader(CmdHelper.RunCmdAndGetOutput($"dotnet tool list -g")); + string line; + while ((line = await consoleOutput.ReadLineAsync()) != null) { - var consoleOutput = new StringReader(CmdHelper.RunCmdAndGetOutput($"dotnet tool list --tool-path {toolPath}")); - string line; - while ((line = await consoleOutput.ReadLineAsync()) != null) + if (line.StartsWith("volo.abp.cli", StringComparison.InvariantCultureIgnoreCase)) { - if (line.StartsWith("Volo.Abp.Cli", StringComparison.InvariantCultureIgnoreCase)) - { - var version = line.Split(new char[0], StringSplitOptions.RemoveEmptyEntries)[1]; + var version = line.Split(new char[0], StringSplitOptions.RemoveEmptyEntries)[1]; - SemanticVersion.TryParse(version, out currentCliVersion); + SemanticVersion.TryParse(version, out currentCliVersion); - break; - } + break; } } + if (currentCliVersion == null) { // If not a tool executable, fallback to assembly version and treat as dev without updates diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddModuleCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddModuleCommand.cs index a7afbfa87d..58adc65fc4 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddModuleCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddModuleCommand.cs @@ -75,9 +75,8 @@ namespace Volo.Abp.Cli.Commands public string GetShortDescription() { - return "Adds a multi-package module to a solution by finding all packages of the module, " + - "finding related projects in the solution and adding each package to the" + - " corresponding project in the solution."; + return "Add a multi-package module to a solution by finding all packages of the module, " + + "finding related projects in the solution and adding each package to the corresponding project in the solution."; } protected virtual string GetSolutionFile(CommandLineArgs commandLineArgs) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddPackageCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddPackageCommand.cs index 211d20d5e1..03e228f255 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddPackageCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddPackageCommand.cs @@ -68,9 +68,7 @@ namespace Volo.Abp.Cli.Commands public string GetShortDescription() { - return "Adds a new ABP package to a project by adding related nuget package" + - " as a dependency to the project and adding [DependsOn(...)] attribute to" + - " the module class in the project."; + return "Add a new ABP package to a project by adding related NuGet package dependencies and [DependsOn(...)] attributes."; } protected virtual string GetProjectFile(CommandLineArgs commandLineArgs) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GetSourceCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GetSourceCommand.cs index 97dfe23944..e1536c2973 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GetSourceCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GetSourceCommand.cs @@ -143,7 +143,7 @@ namespace Volo.Abp.Cli.Commands public string GetShortDescription() { - return "Downloads the source code of the specified module."; + return "Download the source code of the specified module."; } public static class Options diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/HelpCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/HelpCommand.cs index dd9145e8db..2da6b82c8a 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/HelpCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/HelpCommand.cs @@ -82,7 +82,7 @@ namespace Volo.Abp.Cli.Commands public string GetShortDescription() { - return string.Empty; + return "Show command line help. Write ` abp help `"; } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LoginCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LoginCommand.cs index 5efbc358f0..fe9ed2d98f 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LoginCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LoginCommand.cs @@ -72,7 +72,7 @@ namespace Volo.Abp.Cli.Commands public string GetShortDescription() { - return string.Empty; + return "Sign in to " + CliUrls.AccountAbpIo + "."; } public static class Options diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LogoutCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LogoutCommand.cs index d3024635fb..464d40e74d 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LogoutCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LogoutCommand.cs @@ -31,7 +31,7 @@ namespace Volo.Abp.Cli.Commands public string GetShortDescription() { - return string.Empty; + return "Sign out from " + CliUrls.AccountAbpIo + "."; } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs index 44c1789907..9adf6b4a97 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs @@ -175,7 +175,7 @@ namespace Volo.Abp.Cli.Commands public string GetShortDescription() { - return "Generates a new solution based on the ABP startup templates."; + return "Generate a new solution based on the ABP startup templates."; } protected virtual DatabaseProvider GetDatabaseProvider(CommandLineArgs commandLineArgs) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs index dd811c7092..b515a34f78 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs @@ -146,7 +146,7 @@ namespace Volo.Abp.Cli.Commands public string GetShortDescription() { - return "Utility commands to use Abp Suite tool. Installs, updates, removes or starts Suite."; + return "Install, update, remove or start ABP Suite. See https://commercial.abp.io/tools/suite."; } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs index a1775bb987..4ca4f848fd 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs @@ -131,8 +131,7 @@ namespace Volo.Abp.Cli.Commands public string GetShortDescription() { - return "Automatically updates all ABP related NuGet packages and NPM packages in a" + - " solution or project to the latest versions"; + return "Update all ABP related NuGet packages and NPM packages in a solution or project to the latest version."; } public static class Options diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Http/CliHttpClient.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Http/CliHttpClient.cs index bc0b39a85a..81c64a3b5f 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Http/CliHttpClient.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Http/CliHttpClient.cs @@ -8,22 +8,36 @@ namespace Volo.Abp.Cli.Http { public class CliHttpClient : HttpClient { + public static TimeSpan DefaultTimeout { get; set; } = TimeSpan.FromMinutes(1); + public CliHttpClient(TimeSpan? timeout = null) : base(new CliHttpClientHandler()) { - Timeout = timeout ?? TimeSpan.FromMinutes(1); + Timeout = timeout ?? DefaultTimeout; AddAuthentication(this); } + public CliHttpClient(bool setBearerToken) : base(new CliHttpClientHandler()) + { + Timeout = DefaultTimeout; + + if (setBearerToken) + { + AddAuthentication(this); + } + } + private static void AddAuthentication(HttpClient client) { - if (File.Exists(CliPaths.AccessToken)) + if (!File.Exists(CliPaths.AccessToken)) + { + return; + } + + var accessToken = File.ReadAllText(CliPaths.AccessToken, Encoding.UTF8); + if (!accessToken.IsNullOrEmpty()) { - var accessToken = File.ReadAllText(CliPaths.AccessToken, Encoding.UTF8); - if (!accessToken.IsNullOrEmpty()) - { - client.SetBearerToken(accessToken); - } + client.SetBearerToken(accessToken); } } } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/NuGet/NuGetService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/NuGet/NuGetService.cs index 700303006b..1a067243d5 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/NuGet/NuGetService.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/NuGet/NuGetService.cs @@ -32,7 +32,7 @@ namespace Volo.Abp.Cli.NuGet public async Task GetLatestVersionOrNullAsync(string packageId, bool includePreviews = false, bool includeNightly = false) { - using (var client = new CliHttpClient()) + using (var client = new CliHttpClient(setBearerToken: false)) { var url = includeNightly ? $"https://www.myget.org/F/abp-nightly/api/v3/flatcontainer/{packageId.ToLowerInvariant()}/index.json" :