@@ -87,23 +87,40 @@ internal static int Run(
8787
8888 if ( args [ 0 ] is "--license" or "license" )
8989 {
90+ if ( args [ 0 ] == "license" && args . Length > 1 && ArgHelper . WantsHelp ( args . AsSpan ( 1 ) ) )
91+ {
92+ ConsoleUi . PrintCommandUsage ( "license" ) ;
93+ GlobalToolLog . Info ( $ "command_complete exit_code={ CommandExitCodes . Success } subcommand_help=true") ;
94+ EmitCommandMetric ( "license" , args , commandStartTimestamp , commandStopwatch , CommandExitCodes . Success ) ;
95+ return CommandExitCodes . Success ;
96+ }
97+
9098 ConsoleUi . PrintLicenseSummary ( ) ;
9199 GlobalToolLog . Info ( $ "command_complete exit_code={ CommandExitCodes . Success } license_only=true") ;
92100 EmitCommandMetric ( "license" , args , commandStartTimestamp , commandStopwatch , CommandExitCodes . Success ) ;
93101 return CommandExitCodes . Success ;
94102 }
95103
96- if ( args [ 0 ] == "--completions" )
104+ if ( args [ 0 ] is "--completions" or " completions")
97105 {
98- var exitCode = RunCompletions ( args [ 1 ..] ) ;
106+ if ( args [ 0 ] == "completions" && args . Length > 1 && ArgHelper . WantsHelp ( args . AsSpan ( 1 ) ) )
107+ {
108+ ConsoleUi . PrintCommandUsage ( "completions" ) ;
109+ GlobalToolLog . Info ( $ "command_complete exit_code={ CommandExitCodes . Success } subcommand_help=true") ;
110+ EmitCommandMetric ( "completions" , args , commandStartTimestamp , commandStopwatch , CommandExitCodes . Success ) ;
111+ return CommandExitCodes . Success ;
112+ }
113+
114+ var exitCode = RunCompletions ( args [ 1 ..] , args [ 0 ] == "completions" ? "completions" : "--completions" ) ;
99115 GlobalToolLog . Info ( $ "command_complete exit_code={ exitCode } command=completions") ;
100116 EmitCommandMetric ( "completions" , args , commandStartTimestamp , commandStopwatch , exitCode ) ;
101117 return exitCode ;
102118 }
103119
104120 if ( args . Length > 1 && ArgHelper . WantsHelp ( args . AsSpan ( 1 ) ) )
105121 {
106- ConsoleUi . PrintUsage ( showBanner : true ) ;
122+ if ( ! ConsoleUi . PrintCommandUsage ( args [ 0 ] ) )
123+ ConsoleUi . PrintUsage ( showBanner : true ) ;
107124 GlobalToolLog . Info ( $ "command_complete exit_code={ CommandExitCodes . Success } subcommand_help=true") ;
108125 EmitCommandMetric ( args [ 0 ] , args , commandStartTimestamp , commandStopwatch , CommandExitCodes . Success ) ;
109126 return CommandExitCodes . Success ;
@@ -1078,28 +1095,29 @@ internal static string FormatVersionLine(ConsoleUi.BuildMetadata metadata, strin
10781095 return $ "cdidx v{ metadata . Version } (commit { commit } , built { buildDate } , { dirty } ){ suffix } ";
10791096 }
10801097
1081- private static int RunCompletions ( string [ ] cmdArgs )
1098+ private static int RunCompletions ( string [ ] cmdArgs , string commandName = "--completions" )
10821099 {
1100+ var usage = $ "cdidx { commandName } <shell>";
10831101 if ( cmdArgs . Length == 0 )
10841102 return CommandErrorWriter . Write (
1085- "--completions requires a shell value.",
1103+ $ " { commandName } requires a shell value.",
10861104 CommandExitCodes . UsageError ,
10871105 "rerun with one of `bash`, `zsh`, `fish`, or `powershell`." ,
1088- "cdidx --completions <shell>" ) ;
1106+ usage ) ;
10891107
10901108 if ( cmdArgs [ 0 ] . StartsWith ( "-" , StringComparison . Ordinal ) )
10911109 return CommandErrorWriter . Write (
1092- $ "--completions requires a shell value, got option-like token '{ cmdArgs [ 0 ] } '.",
1110+ $ "{ commandName } requires a shell value, got option-like token '{ cmdArgs [ 0 ] } '.",
10931111 CommandExitCodes . UsageError ,
10941112 "rerun with one of `bash`, `zsh`, `fish`, or `powershell`." ,
1095- "cdidx --completions <shell>" ) ;
1113+ usage ) ;
10961114
10971115 if ( cmdArgs . Length > 1 )
10981116 return CommandErrorWriter . Write (
1099- $ "--completions accepts exactly one shell value, got extra { ConsoleUi . Counted ( cmdArgs . Length - 1 , "argument" ) } : { string . Join ( ", " , cmdArgs . Skip ( 1 ) . Select ( arg => $ "`{ arg } `") ) } .",
1117+ $ "{ commandName } accepts exactly one shell value, got extra { ConsoleUi . Counted ( cmdArgs . Length - 1 , "argument" ) } : { string . Join ( ", " , cmdArgs . Skip ( 1 ) . Select ( arg => $ "`{ arg } `") ) } .",
11001118 CommandExitCodes . UsageError ,
11011119 "rerun with exactly one shell name: `bash`, `zsh`, `fish`, or `powershell`." ,
1102- "cdidx --completions <shell>" ) ;
1120+ usage ) ;
11031121
11041122 if ( ConsoleUi . PrintCompletions ( cmdArgs [ 0 ] ) )
11051123 return CommandExitCodes . Success ;
@@ -1108,7 +1126,7 @@ private static int RunCompletions(string[] cmdArgs)
11081126 $ "unsupported completion shell `{ cmdArgs [ 0 ] } `.",
11091127 CommandExitCodes . UsageError ,
11101128 "rerun with one of `bash`, `zsh`, `fish`, or `powershell`." ,
1111- "cdidx --completions <shell>" ) ;
1129+ usage ) ;
11121130 }
11131131
11141132 private static string StripErrorPrefix ( string message )
0 commit comments