@@ -82,21 +82,16 @@ CommandGroup[] getCommands() @safe pure nothrow
82
82
args = a list of string arguments that will be processed
83
83
84
84
Returns:
85
- A structure with two members. `value` is the command name
86
- `remaining` is a list of unprocessed arguments
85
+ The command name that was found (may be null).
87
86
*/
88
- auto extractCommandNameArgument ( string [] args)
87
+ string commandNameArgument ( ref string [] args)
89
88
{
90
- struct Result {
91
- string value;
92
- string [] remaining;
93
- }
94
-
95
89
if (args.length >= 1 && ! args[0 ].startsWith(" -" ) && ! args[0 ].canFind(" :" )) {
96
- return Result (args[0 ], args[1 .. $]);
90
+ const result = args[0 ];
91
+ args = args[1 .. $];
92
+ return result;
97
93
}
98
-
99
- return Result (null , args);
94
+ return null ;
100
95
}
101
96
102
97
// / test extractCommandNameArgument usage
@@ -464,14 +459,12 @@ int runDubCommandLine(string[] args)
464
459
465
460
// extract the command
466
461
args = common_args.extractAllRemainingArgs();
467
-
468
- auto command_name_argument = extractCommandNameArgument(args);
469
-
470
- auto command_args = new CommandArgs(command_name_argument.remaining);
462
+ const command_name = commandNameArgument(args);
463
+ auto command_args = new CommandArgs(args);
471
464
Command cmd;
472
465
473
466
try {
474
- cmd = handler.prepareCommand(command_name_argument.value , command_args);
467
+ cmd = handler.prepareCommand(command_name , command_args);
475
468
} catch (Exception e) {
476
469
logError(" Error processing arguments: %s" , e.msg);
477
470
logDiagnostic(" Full exception: %s" , e.toString().sanitize);
@@ -482,14 +475,14 @@ int runDubCommandLine(string[] args)
482
475
if (cmd is null ) {
483
476
logInfoNoTag(" USAGE: dub [--version] [<command>] [<options...>] [-- [<application arguments...>]]" );
484
477
logInfoNoTag(" " );
485
- logError(" Unknown command: %s" , command_name_argument.value );
478
+ logError(" Unknown command: %s" , command_name );
486
479
import std.algorithm.iteration : filter;
487
480
import std.uni : toUpper;
488
481
foreach (CommandGroup key; handler.commandGroups)
489
482
{
490
483
foreach (Command command; key.commands)
491
484
{
492
- if (levenshteinDistance(command_name_argument.value , command.name) < 4 ) {
485
+ if (levenshteinDistance(command_name , command.name) < 4 ) {
493
486
logInfo(" Did you mean '%s'?" , command.name);
494
487
}
495
488
}
0 commit comments