Skip to content

Commit

Permalink
Move shebang invocation syntax handling further up the command line p…
Browse files Browse the repository at this point in the history
…rocessing queue.

Common command line arguments must not be parsed before handling the shebang invocation syntax.
  • Loading branch information
s-ludwig committed Jun 8, 2016
1 parent da84a45 commit daa0f65
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions source/dub/commandline.d
Expand Up @@ -98,6 +98,11 @@ int runDubCommandLine(string[] args)
environment["TEMP"] = environment["TEMP"].replace("/", "\\");
}

// special single-file package shebang syntax
if (args.length >= 2 && args[1].endsWith(".d")) {
args = args[0] ~ ["run", "-q", "--single", args[1], "--"] ~ args[2 ..$];

This comment has been minimized.

Copy link
@PetarKirov

PetarKirov Jun 9, 2016

Member

Maybe this is a good place to enforce(Path(args[1]).exists, "Expected a valid D file name, but got: '" ~ args[1] ~ "'.")?

This comment has been minimized.

Copy link
@s-ludwig

s-ludwig Jun 9, 2016

Author Member

It currently will print /path/to/foo.d: No such file or directory, resulting from Dub.loadSingleFilePackage calling std.file.readText. We could add an additional one here, but the current error message isn't bad either.

This comment has been minimized.

Copy link
@PetarKirov

PetarKirov Jun 9, 2016

Member

Ok, works for me. Maybe add a test for the error message? (Or ignore if you think this is an overkill :D I recently reviewed some dmd PR that change/add/remove error messages and I liked the idea of testing the actual message output.)

}

// split application arguments from DUB arguments
string[] app_args;
auto app_args_idx = args.countUntil("--");
Expand Down Expand Up @@ -146,15 +151,8 @@ int runDubCommandLine(string[] args)
string cmdname;
args = common_args.extractRemainingArgs();
if (args.length >= 1 && !args[0].startsWith("-")) {
if (args[0].endsWith(".d")) {
cmdname = "run";
if (app_args.length) app_args = args[1 .. $] ~ "--" ~ app_args;
else app_args = args[1 .. $];
args = ["-q", "--single", args[0]];
} else {
cmdname = args[0];
args = args[1 .. $];
}
cmdname = args[0];
args = args[1 .. $];
} else {
if (options.help) {
showHelp(commands, common_args);
Expand Down

0 comments on commit daa0f65

Please sign in to comment.