Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow scripts to be run with version flags #2798

Closed
dev-nicolaos opened this issue Aug 20, 2019 · 6 comments
Closed

Allow scripts to be run with version flags #2798

dev-nicolaos opened this issue Aug 20, 2019 · 6 comments

Comments

@dev-nicolaos
Copy link
Contributor

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...
  • deno test.ts --version
  • deno test.ts -v
  • deno run test.ts --version
  • deno run test.ts -v
  1. Observe the program never runs, deno instead prints out its internal version information

Additional Context

  • Deno version: 0.15.0
  • OS: Windows 10 v1903
@nayeemrmn
Copy link
Collaborator

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.

@kitsonk
Copy link
Contributor

kitsonk commented Aug 20, 2019

Yeah, we shouldn't do that.

@andyfleming
Copy link
Contributor

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.

@hayd
Copy link
Contributor

hayd commented Oct 19, 2019

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).

@mmkal
Copy link

mmkal commented Oct 26, 2019

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!

@bartlomieju
Copy link
Member

Should be fixed with #3389 landed

@ry ry closed this as completed Dec 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants