dubs: Getting into the Node scripts market

Sönke Ludwig via Digitalmars-d digitalmars-d at puremagic.com
Wed May 3 05:13:56 PDT 2017


Am 03.05.2017 um 12:54 schrieb Andre Pany:
> Hi,
>
> it would be great if we can position D as replacement of Node scripts.
> With the --single argument of Dub we have almost everything we need in
> this scenario.
>
> But one thing is very odd. If you want to execute the app.d source file
> with dub you have to write: dub --single app.d
>
> - You have to remember the argument --single
> - You have to add the .d extension
> - You do not like to have the binary created, therefore you have to add
> --temp-build
> - You do not like to have too much output, therefore you have to add
> --quiet
> - If you have application arguments you have to know to add -- at the
> end followed by the application arguments.
>
> With these limitations I cannot convince a Node developer to switch to D.
> I created a very small batch file dubs.bat which would have a huge
> impact in this scenario.
> You can execute the D source file with: dubs app
> Application arguments are just appended: dubs app --PORT 8080
>
> -- dubs.bat
> @echo off
> set _filename=%~n1
> set _extension=%~x1
> for /f "tokens=1,* delims= " %%a in ("%*") do set
> _args_without_filename=%%b
>
> IF "% _extension%" == ".d" (
>     set _sourceFile=%_filename%
> ) else (
>     set _sourceFile=%_filename%.d
> )
>
> dub run --temp-build --quiet --single %_sourceFile% --
> %_args_without_filename%
> -- dubs.bat
>
> Do you think it makes sense to add this batch file and a linux
> equivalent shell script to the D compilers?
>
> Kind regards
> André Pany

Actually there is a special syntax that is also used for shebang style 
scripts: `dub app.d arg1 arg2` is equivalent to `dub --quiet 
--temp-build --single app.d -- arg1 arg2`. It seems like the command 
line help wasn't really updated to reflect that, though.

The only catch is that the .d extension is still required to make it 
possible to tell a script file name apart from a regular command.


More information about the Digitalmars-d mailing list