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

"Unknown argument" error using TypeORM CLI #6896

Closed
mdurling opened this issue Oct 12, 2020 · 3 comments · Fixed by #6899
Closed

"Unknown argument" error using TypeORM CLI #6896

mdurling opened this issue Oct 12, 2020 · 3 comments · Fixed by #6899

Comments

@mdurling
Copy link

Issue type:
This used to work until recently:

node --require ts-node/register ../node_modules/typeorm/cli.js query "select count(*) from users" 
typeorm query

Executes given SQL query on a default connection. Specify connection name to run
query on a specific connection.

Options:
  -h, --help        Show help                                          [boolean]
  -c, --connection  Name of the connection on which to run a query.
                                                            [default: "default"]
  -f, --config      Name of the file with connection configuration.
                                                          [default: "ormconfig"]
  -v, --version     Show version number                                [boolean]

Unknown argument: select count(*) from metrics

Now, -- must be used to avoid this error which is problematic when trying to run this via yarn/npm scripts.

node --require ts-node/register ../node_modules/typeorm/cli.js query -- "select count(*) from users" 
Running query: select count(*) from users
Query has been executed. Result:
[
  {
    "count": 104
  }
]

[x] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

@imnotjames
Copy link
Contributor

Why is that a problem for yarn / npm scripts?

Looks like this behavior changes in 0.2.27 - that's when we updated yargs.

@imnotjames
Copy link
Contributor

https://github.com/yargs/yargs/blob/master/CHANGELOG.md#-breaking-changes-3

do not allow additional positionals in strict mode

Apparently we're using strict mode which I did not know.

imnotjames added a commit to imnotjames/typeorm that referenced this issue Oct 13, 2020
the CLI command `query` had an implicit `query` positional
parameter and in earlier versions of yargs that was okay -
but in the later versions aiming for more correct code they've
refactored it to not support that

explicitly define the `query` positional parameter & add a
helpful description so people can tell what it is for

fixes typeorm#6896
imnotjames added a commit to imnotjames/typeorm that referenced this issue Oct 13, 2020
the CLI command `query` had an implicit `query` positional
parameter and in earlier versions of yargs that was okay -
but in the later versions aiming for more correct code they've
refactored it to not support that

explicitly define the `query` positional parameter & add a
helpful description so people can tell what it is for

fixes typeorm#6896
@mdurling
Copy link
Author

Why is that a problem for yarn / npm scripts?

We call scripts from other scripts and yarn in particular doesn't pass the -- through properly. I see you have a fix in process; looking forward to it. Thanks @imnotjames

imnotjames added a commit that referenced this issue Oct 14, 2020
the CLI command `query` had an implicit `query` positional
parameter and in earlier versions of yargs that was okay -
but in the later versions aiming for more correct code they've
refactored it to not support that

explicitly define the `query` positional parameter & add a
helpful description so people can tell what it is for

fixes #6896
zaro pushed a commit to zaro/typeorm that referenced this issue Jan 12, 2021
the CLI command `query` had an implicit `query` positional
parameter and in earlier versions of yargs that was okay -
but in the later versions aiming for more correct code they've
refactored it to not support that

explicitly define the `query` positional parameter & add a
helpful description so people can tell what it is for

fixes typeorm#6896
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants