Deno: Allow scripts to be run with version flags

Created on 20 Aug 2019  路  6Comments  路  Source: denoland/deno

Description

As a developer, I would like to be able to consume the -v or --version flags in my application. I'd prefer that if a script is provided, Deno ignore the version flag and instead pass it on to Deno.args. Currently if I run a script with either flag, Deno prints out its internal version information as if I had run

  • deno version
  • deno --version
  • deno -v

Steps to Reproduce

  1. Create a file test.ts containing the following code
console.log(Deno.args);
  1. Run deno test.ts or deno run test.ts
  2. Observe the program runs successfully and prints out: [ "test.ts" ]
  3. Run any of the following...
  4. deno test.ts --version
  5. deno test.ts -v
  6. deno run test.ts --version
  7. deno run test.ts -v
  8. Observe the program never runs, deno instead prints out its internal version information

Additional Context

  • Deno version: 0.15.0
  • OS: Windows 10 v1903

Most helpful comment

Yeah, we shouldn't do that.

All 6 comments

I also don't like how Deno unexpectedly consumes flags after the script name when it recognises them.

@dev-nicolaos You can currently run deno test.ts -- --version. Anything after -- is strictly passed to the script. (Note that -- is included as an argument.)

The built-in argument passing is pretty bare-bones. Check out https://github.com/denoland/deno_std/blob/master/flags/README.md.

Yeah, we shouldn't do that.

I think any arguments after the script name should be passed to the script even without --. Additionally I think that any arguments before the script name should _not_ be passed to the user script.

A nice thing to keep this convenience might be to remap deno --version (and maybe deno -v) to deno version iff NO other arguments are passed... if you pass a script or anything else then don't do that (and so you'd see the flag to Deno.args).

Using -- to separate deno args and program args can be dangerous. We've run in to some pretty scary situations because of the similar functionality npm has. Here's our example:
We had a deploy script that accepted a --dry-run cli arg. It was usually called with npm run deploy, but someone new to the team accidentally tried to use npm run deploy --dry-run without supplying the --. The command happily deployed our services for real, even though we were expecting it to just do a dry run. It gets even worse when npm scripts need to call other npm scripts. You can end up needing commands like npm run blah -- -- -- --force (or bake the same number of --s into the scripts themselves). If npm had just required that npm args go between npm run and blah, this danger and inconvenience would just disappear. It's too late for npm - if they changed the behaviour now, all sorts of existing scripts would break or subtly change behaviour. Deno is in v0, so can still change!

Should be fixed with #3389 landed

Was this page helpful?
0 / 5 - 0 ratings

Related issues

somombo picture somombo  路  3Comments

ry picture ry  路  3Comments

ry picture ry  路  3Comments

xueqingxiao picture xueqingxiao  路  3Comments

justjavac picture justjavac  路  3Comments