-
Notifications
You must be signed in to change notification settings - Fork 279
Update DAB CLI to return appropriate exit codes based upon exit reason #2084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
892e48f
update cli to return -1 when failure occurs. 0 when successful. Next …
seantleonard 795b213
Cleanup unused code and function.
seantleonard e6d0b63
add tests and comments.
seantleonard 56eb9ff
update tests and added cases to cover the int return code enhancements.
seantleonard cb9ed7f
Merge branch 'main' into dev/sean/cli_validReturnCodes
seantleonard b9dc379
add const return codes in new constants folder and remove commented o…
seantleonard 73df65f
Update CLITESTs to utilize new return codes and run dotnet format
seantleonard 39eb8e3
Merge branch 'dev/sean/cli_validReturnCodes' of https://github.com/Az…
seantleonard be172a6
Merge branch 'main' into dev/sean/cli_validReturnCodes
seantleonard 1079f27
Merge branch 'main' into dev/sean/cli_validReturnCodes
seantleonard f2bfc82
Merge branch 'main' into dev/sean/cli_validReturnCodes
seantleonard c98b88e
update comment for DabCliParserErrorHandler to denote "--version" res…
seantleonard 6ed5023
merge main w/ conflict resolution
seantleonard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("Cli.Tests")] | ||
namespace Cli.Constants | ||
{ | ||
internal class CliReturnCode | ||
{ | ||
public const int SUCCESS = 0; | ||
public const int GENERAL_ERROR = -1; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using CommandLine; | ||
|
||
namespace Cli | ||
{ | ||
/// <summary> | ||
/// Processes errors that occur during parsing of CLI verbs (start, init, export, add, update, etc) and their arguments. | ||
/// </summary> | ||
public class DabCliParserErrorHandler | ||
{ | ||
/// <summary> | ||
/// Processes errors accumulated by each parser in parser.ParseArguments<parsers>(). | ||
/// For DAB CLI, this only includes scenarios where the user provides invalid DAB CLI input. | ||
/// e.g. incorrectly formed or missing options and parameters. | ||
/// Additionally, an error is tracked if the user uses: | ||
/// -> an unsupported CLI verb | ||
/// -> --help. | ||
/// -> --version | ||
/// </summary> | ||
/// <param name="err">Collection of Error objects collected by the CLI parser.</param> | ||
/// <returns>Return code: 0 when --help is used, otherwise -1.</returns> | ||
public static int ProcessErrorsAndReturnExitCode(IEnumerable<Error> err) | ||
{ | ||
// To know if `--help` or `--version` was requested. | ||
bool isHelpOrVersionRequested = false; | ||
|
||
/// System.CommandLine considers --help and --version as NonParsed Errors | ||
/// ref: https://github.com/commandlineparser/commandline/issues/630 | ||
/// This is a workaround to make sure our app exits with exit code 0, | ||
/// when user does --help or --versions. | ||
/// dab --help -> ErrorType.HelpVerbRequestedError | ||
/// dab [command-name] --help -> ErrorType.HelpRequestedError | ||
/// dab --version -> ErrorType.VersionRequestedError | ||
List<Error> errors = err.ToList(); | ||
if (errors.Any(e => e.Tag == ErrorType.VersionRequestedError | ||
|| e.Tag == ErrorType.HelpRequestedError | ||
|| e.Tag == ErrorType.HelpVerbRequestedError)) | ||
{ | ||
isHelpOrVersionRequested = true; | ||
} | ||
|
||
return isHelpOrVersionRequested ? 0 : -1; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.