diff --git a/build/DependencyVersions.props b/build/DependencyVersions.props index dfacb08a6..a508a8c63 100644 --- a/build/DependencyVersions.props +++ b/build/DependencyVersions.props @@ -4,8 +4,8 @@ 2.0.0-beta-001791-00 15.2.0-preview-000047-02 2.0.0-rc4-61325-08 - 2.0.0-alpha-20170322-1 - 4.3.0-beta1-2342 + 2.0.0-alpha-20170323-1 + 4.3.0-beta1-2418 1.0.0-alpha-20170130-3-281 15.1.0-preview-20170316-05 $(CLI_SharedFrameworkVersion) diff --git a/src/Microsoft.DotNet.Archive/ConsoleProgressReport.cs b/src/Microsoft.DotNet.Archive/ConsoleProgressReport.cs index 91e555c37..e8f6cd0df 100644 --- a/src/Microsoft.DotNet.Archive/ConsoleProgressReport.cs +++ b/src/Microsoft.DotNet.Archive/ConsoleProgressReport.cs @@ -29,9 +29,16 @@ namespace Microsoft.DotNet.Archive string line = $"{value.Phase} {progress}%"; if (value.Phase == _currentPhase) { - Console.Write(new string('\b', _lastLineLength)); + if (Console.IsOutputRedirected) + { + Console.Write($"...{progress}%"); + } + else + { + Console.Write(new string('\b', _lastLineLength)); + Console.Write(line); + } - Console.Write(line); _lastLineLength = line.Length; if (progress == 100) diff --git a/src/dotnet/CommandLine/CommandLineApplication.cs b/src/dotnet/CommandLine/CommandLineApplication.cs index a22e77535..64b6b3d17 100644 --- a/src/dotnet/CommandLine/CommandLineApplication.cs +++ b/src/dotnet/CommandLine/CommandLineApplication.cs @@ -207,7 +207,7 @@ namespace Microsoft.DotNet.Cli.CommandLine throw new CommandParsingException( command, "Required command missing", - isRequireSubCommandMissing: true); + isRequiredSubCommandMissing: true); } return command.Invoke(); diff --git a/src/dotnet/CommandLine/CommandParsingException.cs b/src/dotnet/CommandLine/CommandParsingException.cs index 79e19e522..82c675f4b 100644 --- a/src/dotnet/CommandLine/CommandParsingException.cs +++ b/src/dotnet/CommandLine/CommandParsingException.cs @@ -8,7 +8,7 @@ namespace Microsoft.DotNet.Cli.CommandLine { internal class CommandParsingException : Exception { - private readonly bool _isRequireSubCommandMissing; + private readonly bool _isRequiredSubCommandMissing; public CommandParsingException( string message, @@ -21,11 +21,11 @@ namespace Microsoft.DotNet.Cli.CommandLine public CommandParsingException( CommandLineApplication command, string message, - bool isRequireSubCommandMissing = false) + bool isRequiredSubCommandMissing = false) : this(message) { Command = command; - _isRequireSubCommandMissing = isRequireSubCommandMissing; + _isRequiredSubCommandMissing = isRequiredSubCommandMissing; } public CommandLineApplication Command { get; } @@ -36,7 +36,7 @@ namespace Microsoft.DotNet.Cli.CommandLine { get { - return _isRequireSubCommandMissing + return _isRequiredSubCommandMissing ? CommonLocalizableStrings.RequiredCommandNotPassed : base.Message; } diff --git a/src/dotnet/DotNetTopLevelCommandBase.cs b/src/dotnet/DotNetTopLevelCommandBase.cs index 5e2850ee5..650a5fcbb 100644 --- a/src/dotnet/DotNetTopLevelCommandBase.cs +++ b/src/dotnet/DotNetTopLevelCommandBase.cs @@ -28,6 +28,8 @@ namespace Microsoft.DotNet.Cli ParseResult = parser.ParseFrom($"dotnet {CommandName}", args); + ParseResult.ShowHelpIfRequested(); + var subcommandName = ParseResult.Command().Name; try diff --git a/src/dotnet/ParseResultExtensions.cs b/src/dotnet/ParseResultExtensions.cs index 82932de0b..b662d9430 100644 --- a/src/dotnet/ParseResultExtensions.cs +++ b/src/dotnet/ParseResultExtensions.cs @@ -13,6 +13,19 @@ namespace Microsoft.DotNet.Cli Console.WriteLine(parseResult.Command().HelpView()); public static void ShowHelpOrErrorIfAppropriate(this ParseResult parseResult) + { + parseResult.ShowHelpIfRequested(); + + if (parseResult.Errors.Any()) + { + throw new CommandParsingException( + message: string.Join(Environment.NewLine, + parseResult.Errors.Select(e => e.Message)), + helpText: parseResult?.Command()?.HelpView()); + } + } + + public static void ShowHelpIfRequested(this ParseResult parseResult) { var appliedCommand = parseResult.AppliedCommand(); @@ -23,14 +36,6 @@ namespace Microsoft.DotNet.Cli // NOTE: this is a temporary stage in refactoring toward the ClicCommandLineParser being used at the CLI entry point. throw new HelpException(parseResult.Command().HelpView()); } - - if (parseResult.Errors.Any()) - { - throw new CommandParsingException( - message: string.Join(Environment.NewLine, - parseResult.Errors.Select(e => e.Message)), - helpText: parseResult?.Command()?.HelpView()); - } } } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-complete/CompleteCommand.cs b/src/dotnet/commands/dotnet-complete/CompleteCommand.cs index a8375687a..a6061d37d 100644 --- a/src/dotnet/commands/dotnet-complete/CompleteCommand.cs +++ b/src/dotnet/commands/dotnet-complete/CompleteCommand.cs @@ -2,9 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; -using System.IO; using System.Linq; -using System.Text; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; @@ -28,20 +26,14 @@ namespace Microsoft.DotNet.Cli var suggestions = Suggestions(complete); - var log = new StringBuilder(); - log.AppendLine($"args: {string.Join(" ", args.Select(a => $"\"{a}\""))}"); - log.AppendLine("diagram: " + result.Diagram()); - File.WriteAllText("parse.log", log.ToString()); - foreach (var suggestion in suggestions) { Console.WriteLine(suggestion); } } - catch (Exception e) + catch (Exception) { - File.WriteAllText("dotnet completion exception.log", e.ToString()); - throw; + return 1; } return 0; diff --git a/src/dotnet/commands/dotnet-complete/ParseCommand.cs b/src/dotnet/commands/dotnet-complete/ParseCommand.cs index fb86c6300..90972e119 100644 --- a/src/dotnet/commands/dotnet-complete/ParseCommand.cs +++ b/src/dotnet/commands/dotnet-complete/ParseCommand.cs @@ -31,7 +31,7 @@ namespace Microsoft.DotNet.Cli Console.WriteLine(); foreach (var error in result.Errors) { - Console.WriteLine($"[{error?.Option?.Name ?? "???"}] {error.Message}"); + Console.WriteLine($"[{error?.Option?.Name ?? "???"}] {error?.Message}"); } } diff --git a/src/dotnet/dotnet.csproj b/src/dotnet/dotnet.csproj index a9c9a6f86..a8d4472d7 100644 --- a/src/dotnet/dotnet.csproj +++ b/src/dotnet/dotnet.csproj @@ -40,7 +40,7 @@ - + diff --git a/test/dotnet-add-reference.Tests/GivenDotnetAddReference.cs b/test/dotnet-add-reference.Tests/GivenDotnetAddReference.cs index 2192205d4..cac2a687d 100644 --- a/test/dotnet-add-reference.Tests/GivenDotnetAddReference.cs +++ b/test/dotnet-add-reference.Tests/GivenDotnetAddReference.cs @@ -19,12 +19,12 @@ namespace Microsoft.DotNet.Cli.Add.Reference.Tests Usage: dotnet add reference [options] Arguments: - The project file to operate on. If a file is not specified, the command will search the current directory for one. - Project to project references to add + The project file to operate on. If a file is not specified, the command will search the current directory for one. + Project to project references to add Options: - -h, --help Show help information - -f, --framework Add reference only when targeting a specific framework + -h, --help Show help information + -f, --framework Add reference only when targeting a specific framework "; const string FrameworkNet451Arg = "-f net451"; diff --git a/test/dotnet-list-reference.Tests/GivenDotnetListReference.cs b/test/dotnet-list-reference.Tests/GivenDotnetListReference.cs index f82c98700..e6205904d 100644 --- a/test/dotnet-list-reference.Tests/GivenDotnetListReference.cs +++ b/test/dotnet-list-reference.Tests/GivenDotnetListReference.cs @@ -18,10 +18,10 @@ namespace Microsoft.DotNet.Cli.List.Reference.Tests Usage: dotnet list reference [options] Arguments: - The project file to operate on. If a file is not specified, the command will search the current directory for one. + The project file to operate on. If a file is not specified, the command will search the current directory for one. Options: - -h, --help Show help information + -h, --help Show help information "; const string FrameworkNet451Arg = "-f net451"; diff --git a/test/dotnet-remove-reference.Tests/GivenDotnetRemoveP2P.cs b/test/dotnet-remove-reference.Tests/GivenDotnetRemoveP2P.cs index 956d380d7..a098e9719 100644 --- a/test/dotnet-remove-reference.Tests/GivenDotnetRemoveP2P.cs +++ b/test/dotnet-remove-reference.Tests/GivenDotnetRemoveP2P.cs @@ -18,12 +18,12 @@ namespace Microsoft.DotNet.Cli.Remove.Reference.Tests Usage: dotnet remove reference [options] Arguments: - The project file to operate on. If a file is not specified, the command will search the current directory for one. - Project to project references to remove + The project file to operate on. If a file is not specified, the command will search the current directory for one. + Project to project references to remove Options: - -h, --help Show help information - -f, --framework Remove reference only when targeting a specific framework + -h, --help Show help information + -f, --framework Remove reference only when targeting a specific framework "; const string FrameworkNet451Arg = "-f net451"; diff --git a/test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs b/test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs index 8ee3ca5c4..c022a8d1c 100644 --- a/test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs +++ b/test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs @@ -20,11 +20,11 @@ namespace Microsoft.DotNet.Cli.Sln.Add.Tests Usage: dotnet sln add [options] Arguments: - Solution file to operate on. If not specified, the command will search the current directory for one. - Add one or more specified projects to the solution. + Solution file to operate on. If not specified, the command will search the current directory for one. + Add one or more specified projects to the solution. Options: - -h, --help Show help information + -h, --help Show help information "; private ITestOutputHelper _output; diff --git a/test/dotnet-sln-list.Tests/GivenDotnetSlnList.cs b/test/dotnet-sln-list.Tests/GivenDotnetSlnList.cs index abaa51cea..781322e71 100644 --- a/test/dotnet-sln-list.Tests/GivenDotnetSlnList.cs +++ b/test/dotnet-sln-list.Tests/GivenDotnetSlnList.cs @@ -18,10 +18,10 @@ namespace Microsoft.DotNet.Cli.Sln.List.Tests Usage: dotnet sln list [options] Arguments: - Solution file to operate on. If not specified, the command will search the current directory for one. + Solution file to operate on. If not specified, the command will search the current directory for one. Options: - -h, --help Show help information + -h, --help Show help information "; [Theory] diff --git a/test/dotnet-sln-remove.Tests/GivenDotnetSlnRemove.cs b/test/dotnet-sln-remove.Tests/GivenDotnetSlnRemove.cs index c0e51ff8a..f32bef616 100644 --- a/test/dotnet-sln-remove.Tests/GivenDotnetSlnRemove.cs +++ b/test/dotnet-sln-remove.Tests/GivenDotnetSlnRemove.cs @@ -18,11 +18,11 @@ namespace Microsoft.DotNet.Cli.Sln.Remove.Tests Usage: dotnet sln remove [options] Arguments: - Solution file to operate on. If not specified, the command will search the current directory for one. - Remove the specified project(s) from the solution. The project is not impacted. + Solution file to operate on. If not specified, the command will search the current directory for one. + Remove the specified project(s) from the solution. The project is not impacted. Options: - -h, --help Show help information + -h, --help Show help information "; private const string ExpectedSlnContentsAfterRemove = @" diff --git a/test/dotnet.Tests/GivenThatTheUserRequestsHelp.cs b/test/dotnet.Tests/GivenThatTheUserRequestsHelp.cs new file mode 100644 index 000000000..153a375d0 --- /dev/null +++ b/test/dotnet.Tests/GivenThatTheUserRequestsHelp.cs @@ -0,0 +1,44 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using FluentAssertions; +using Microsoft.DotNet.Tools.Test.Utilities; +using Xunit; + +namespace dotnet.Tests +{ + public class GivenThatTheUserRequestsHelp + { + [Theory] + [InlineData("-h")] + [InlineData("add -h")] + [InlineData("add package -h")] + [InlineData("add reference -h")] + [InlineData("build -h")] + [InlineData("cache -h")] + [InlineData("clean -h")] + [InlineData("list -h")] + [InlineData("migrate -h")] + [InlineData("msbuild -h")] + [InlineData("new -h")] + [InlineData("nuget -h")] + [InlineData("pack -h")] + [InlineData("publish -h")] + [InlineData("remove -h")] + [InlineData("restore -h")] + [InlineData("run -h")] + [InlineData("sln -h")] + [InlineData("sln add -h")] + [InlineData("sln list -h")] + [InlineData("sln remove -h")] + [InlineData("test -h")] + public void TheResponseIsNotAnError(string commandLine) + { + var result = new DotnetCommand() + .ExecuteWithCapturedOutput(commandLine); + + result.ExitCode.Should().Be(0); + } + } +} \ No newline at end of file diff --git a/test/dotnet.Tests/dotnet.Tests.csproj b/test/dotnet.Tests/dotnet.Tests.csproj index c37528336..f9b8b2d07 100644 --- a/test/dotnet.Tests/dotnet.Tests.csproj +++ b/test/dotnet.Tests/dotnet.Tests.csproj @@ -42,6 +42,6 @@ - +