@@ -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
@@ -448,7 +443,8 @@ int runDubCommandLine(string[] args)
448
443
449
444
auto common_args = new CommandArgs(args[1 .. $]);
450
445
451
- try handler.prepareOptions(common_args);
446
+ try
447
+ args = handler.prepareOptions(common_args);
452
448
catch (Exception e) {
453
449
logError(" Error processing arguments: %s" , e.msg);
454
450
logDiagnostic(" Full exception: %s" , e.toString().sanitize);
@@ -464,14 +460,12 @@ int runDubCommandLine(string[] args)
464
460
465
461
// extract the command
466
462
args = common_args.extractAllRemainingArgs();
467
-
468
- auto command_name_argument = extractCommandNameArgument(args);
469
-
470
- auto command_args = new CommandArgs(command_name_argument.remaining);
463
+ const command_name = commandNameArgument(args);
464
+ auto command_args = new CommandArgs(args);
471
465
Command cmd;
472
466
473
467
try {
474
- cmd = handler.prepareCommand(command_name_argument.value , command_args);
468
+ cmd = handler.prepareCommand(command_name , command_args);
475
469
} catch (Exception e) {
476
470
logError(" Error processing arguments: %s" , e.msg);
477
471
logDiagnostic(" Full exception: %s" , e.toString().sanitize);
@@ -482,14 +476,14 @@ int runDubCommandLine(string[] args)
482
476
if (cmd is null ) {
483
477
logInfoNoTag(" USAGE: dub [--version] [<command>] [<options...>] [-- [<application arguments...>]]" );
484
478
logInfoNoTag(" " );
485
- logError(" Unknown command: %s" , command_name_argument.value );
479
+ logError(" Unknown command: %s" , command_name );
486
480
import std.algorithm.iteration : filter;
487
481
import std.uni : toUpper;
488
482
foreach (CommandGroup key; handler.commandGroups)
489
483
{
490
484
foreach (Command command; key.commands)
491
485
{
492
- if (levenshteinDistance(command_name_argument.value , command.name) < 4 ) {
486
+ if (levenshteinDistance(command_name , command.name) < 4 ) {
493
487
logInfo(" Did you mean '%s'?" , command.name);
494
488
}
495
489
}
0 commit comments