File tree Expand file tree Collapse file tree 6 files changed +17
-13
lines changed Expand file tree Collapse file tree 6 files changed +17
-13
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ namespace Microsoft.DotNet.Cli.Commands.Package.Add;
15
15
16
16
internal static class PackageAddCommandParser
17
17
{
18
- public static readonly Argument < PackageIdentity > CmdPackageArgument = CommonArguments . PackageIdentityArgument ( true )
18
+ public static readonly Argument < PackageIdentity > CmdPackageArgument = CommonArguments . RequiredPackageIdentityArgument ( )
19
19
. AddCompletions ( ( context ) =>
20
20
{
21
21
// we should take --prerelease flags into account for version completion
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ namespace Microsoft.DotNet.Cli.Commands.Tool.Execute
15
15
{
16
16
internal class ToolExecuteCommand ( ParseResult result ) : CommandBase ( result )
17
17
{
18
- private readonly PackageIdentity ? _packageToolIdentityArgument = result . GetValue ( ToolExecuteCommandParser . PackageIdentityArgument ) ;
18
+ private readonly PackageIdentity _packageToolIdentityArgument = result . GetRequiredValue ( ToolExecuteCommandParser . PackageIdentityArgument ) ;
19
19
private readonly IEnumerable < string > _forwardArguments = result . GetValue ( ToolExecuteCommandParser . CommandArgument ) ?? Enumerable . Empty < string > ( ) ;
20
20
private readonly bool _allowRollForward = result . GetValue ( ToolExecuteCommandParser . RollForwardOption ) ;
21
21
private readonly string ? _configFile = result . GetValue ( ToolExecuteCommandParser . ConfigOption ) ;
@@ -29,12 +29,6 @@ internal class ToolExecuteCommand(ParseResult result) : CommandBase(result)
29
29
30
30
public override int Execute ( )
31
31
{
32
- if ( _packageToolIdentityArgument is null )
33
- {
34
- // System.CommandLine will throw an error if the argument is not provided, but we can still check here for clarity.
35
- return 1 ;
36
- }
37
-
38
32
if ( ! UserAgreedToRunFromSource ( ) )
39
33
{
40
34
throw new GracefulException ( CliCommandStrings . ToolRunFromSourceUserConfirmationFailed , isUserError : true ) ;
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ namespace Microsoft.DotNet.Cli.Commands.Tool.Execute
13
13
internal static class ToolExecuteCommandParser
14
14
15
15
{
16
- public static readonly Argument < PackageIdentity ? > PackageIdentityArgument = ToolInstallCommandParser . PackageIdentityArgument ;
16
+ public static readonly Argument < PackageIdentity > PackageIdentityArgument = ToolInstallCommandParser . PackageIdentityArgument ;
17
17
18
18
public static readonly Argument < IEnumerable < string > > CommandArgument = new ( "commandArguments" )
19
19
{
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ namespace Microsoft.DotNet.Cli.Commands.Tool.Install;
12
12
13
13
internal static class ToolInstallCommandParser
14
14
{
15
- public static readonly Argument < PackageIdentity ? > PackageIdentityArgument = CommonArguments . PackageIdentityArgument ( ) ;
15
+ public static readonly Argument < PackageIdentity > PackageIdentityArgument = CommonArguments . RequiredPackageIdentityArgument ( ) ;
16
16
17
17
public static readonly Option < string > VersionOption = new ( "--version" )
18
18
{
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ namespace Microsoft.DotNet.Cli.Commands.Tool.Update;
10
10
11
11
internal static class ToolUpdateCommandParser
12
12
{
13
- public static readonly Argument < PackageIdentity ? > PackageIdentityArgument = CommonArguments . PackageIdentityArgument ( requireArgument : false ) ;
13
+ public static readonly Argument < PackageIdentity ? > PackageIdentityArgument = CommonArguments . OptionalPackageIdentityArgument ( ) ;
14
14
15
15
public static readonly Option < bool > UpdateAllOption = ToolAppliedOption . UpdateAllOption ;
16
16
Original file line number Diff line number Diff line change @@ -11,15 +11,25 @@ namespace Microsoft.DotNet.Cli
11
11
{
12
12
internal class CommonArguments
13
13
{
14
- public static DynamicArgument < PackageIdentity ? > PackageIdentityArgument ( bool requireArgument = true ) =>
14
+ public static DynamicArgument < PackageIdentity ? > OptionalPackageIdentityArgument ( ) =>
15
15
new ( "packageId" )
16
16
{
17
17
HelpName = "PACKAGE_ID" ,
18
18
Description = CliStrings . PackageIdentityArgumentDescription ,
19
19
CustomParser = ( ArgumentResult argumentResult ) => ParsePackageIdentityWithVersionSeparator ( argumentResult . Tokens [ 0 ] ? . Value ) ,
20
- Arity = requireArgument ? ArgumentArity . ExactlyOne : ArgumentArity . ZeroOrOne ,
20
+ Arity = ArgumentArity . ZeroOrOne ,
21
21
} ;
22
22
23
+ public static DynamicArgument < PackageIdentity > RequiredPackageIdentityArgument ( ) =>
24
+ new ( "packageId" )
25
+ {
26
+ HelpName = "PACKAGE_ID" ,
27
+ Description = CliStrings . PackageIdentityArgumentDescription ,
28
+ CustomParser = ( ArgumentResult argumentResult ) => ParsePackageIdentityWithVersionSeparator ( argumentResult . Tokens [ 0 ] ? . Value ) ,
29
+ Arity = ArgumentArity . ExactlyOne ,
30
+ } ;
31
+
32
+
23
33
private static PackageIdentity ? ParsePackageIdentityWithVersionSeparator ( string ? packageIdentity , char versionSeparator = '@' )
24
34
{
25
35
if ( string . IsNullOrEmpty ( packageIdentity ) )
You can’t perform that action at this time.
0 commit comments