-
Notifications
You must be signed in to change notification settings - Fork 13
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
feat: Enhance cli command line #107
Conversation
✅ Deploy Preview for gbfs-validator ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR, it's a great improvement.
I made 2 personal remarks, and maybe we can add a "summary" option to only have the summary ?
const gbfs = new GBFS(process.argv[2]) | ||
parseOptions = () => { | ||
commander | ||
.version(pjson.version, '-v, --version') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's always 1.0.0
because we don't use it right now.
We return the git hash instead https://github.com/MobilityData/gbfs-validator/blob/master/gbfs-validator/gbfs.js#L3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in preparation for publishing an npm package. In the case of the command line, if we would like to include the commit hash, more work is needed to make available the hash information on local computers.
gbfs-validator/cli.js
Outdated
} | ||
} | ||
|
||
if (options.url) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this parameter is mandatory, it may be preferable to pass the URL such as node gbfs-validator/cli.js [URL]
instead of -u
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I'll add the option as mandatory. I considered adding -f
for local files in the near future; that's why defining -u
for URLs and -f
for files gives consistency for the consumer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting for the local files :)
gbfs-validator/cli.js
Outdated
} | ||
try { | ||
const report = await getFeedValidationReport(options.url) | ||
if (options.print) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe make it default ?
If no -p
/ -s
arguments is passed, nothing happen, and we don't have any clue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think changing -p
to -nstdout
or similar as No standard output, in addition to trigger an error if -nstdout
is passed and -s
is not present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, what do you think about removing the -p
option completely and only print when option -s
is missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good solution too. My only concern is to drive the use of the command line too much. Having separate options give more control over what goes to a file and stdout.
…to a cli like testing
Hi @PierrickP, can you expand on what information might be interesting to have in the summary response? I might defer this task to a follow-up PR. |
@davidgamez On summary (based on #101) i would like if the feed is valid or not, versions, and the number of errors (distinct and total, part of #106). |
@PierrickP, thanks for the response. I'll have this as a follow-up task after the mentioned PRs are reviewed and merged. |
const cliExec = (args) => { | ||
const command = `${path.resolve(`${__dirname}/../cli.js`)} ${args.join(' ')}` | ||
return new Promise(resolve => { | ||
exec(command, |
Check warning
Code scanning / CodeQL
Shell command built from environment values
Co-authored-by: Fabien Richard-Allouard <[email protected]>
Co-authored-by: Fabien Richard-Allouard <[email protected]>
.requiredOption('-u, --url <feed_url>', 'URL of the GBFS feed') | ||
.option('-vb, --verbose', 'Verbose mode prints debugging console logs') | ||
.option('-s, --save-report <report_path>', 'Local path to output report file') | ||
.addOption(new commander.Option('-pr, --print-report <yes_no>', 'Print report to standard output').default('yes').choices(['yes', 'no'])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with -s
, could we use one letter -p
for printing?
.addOption(new commander.Option('-pr, --print-report <yes_no>', 'Print report to standard output').default('yes').choices(['yes', 'no'])) | |
.addOption(new commander.Option('-p, --print-report <yes_no>', 'Print report to standard output').default('yes').choices(['yes', 'no'])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I connected with @richfab, and we couldn't find any strong feelings either way. Let's keep it as it is for simplicity; in the future, more options will be added, and the short argument name will be always a point of conflict.
const url = `http://${gbfsFeedServer.server.address().address}:${ | ||
gbfsFeedServer.server.address().port | ||
}` | ||
test('should success and print the report when url parameter set and -pr is set as default', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Only if you accept the suggestion to use -p
for consistency with -s
)
test('should success and print the report when url parameter set and -pr is set as default', async () => { | |
test('should success and print the report when url parameter set and -p is set as default', async () => { |
|
||
process.argv[2] = url | ||
test('should show an error if pr parameter is set to `no` and -s is not set', async () => { | ||
const result = await cliExec([`-u ${feedUrl}`, '-pr no']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Only if you accept the suggestion to use -p
for consistency with -s
)
const result = await cliExec([`-u ${feedUrl}`, '-pr no']) | |
const result = await cliExec([`-u ${feedUrl}`, '-p no']) |
|
||
const cli = await require('../cli.js') | ||
test('should success when paramters url and save report has valid values and print report is set to no', async () => { | ||
const result = await cliExec([`-u ${feedUrl}`, '-s /dev/null', '-pr no']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Only if you accept the suggestion to use -p
for consistency with -s
)
const result = await cliExec([`-u ${feedUrl}`, '-s /dev/null', '-pr no']) | |
const result = await cliExec([`-u ${feedUrl}`, '-s /dev/null', '-p no']) |
}) | ||
}) | ||
test('should success and print report when paramters url and save report are valid and print report is set to yes', async () => { | ||
const result = await cliExec([`-u ${feedUrl}`, '-s /dev/null', '-pr yes']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Only if you accept the suggestion to use -p
for consistency with -s
)
const result = await cliExec([`-u ${feedUrl}`, '-s /dev/null', '-pr yes']) | |
const result = await cliExec([`-u ${feedUrl}`, '-s /dev/null', '-p yes']) |
-u, --url <feed_url> URL of the GBFS feed | ||
-vb, --verbose Verbose mode prints debugging console logs | ||
-s, --save-report <report_path> Local path to output report file | ||
-pr, --print-report <yes_no> Print report to standard output (choices: "yes", "no", default: "yes") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Only if you accept the suggestion to use -p
for consistency with -s
)
-pr, --print-report <yes_no> Print report to standard output (choices: "yes", "no", default: "yes") | |
-p, --print-report <yes_no> Print report to standard output (choices: "yes", "no", default: "yes") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Thank you @davidgamez for this great improvement to the CLI tool!
Description
In this PR, the
cli.js
file is enhanced with additional parameters, help messages, and error handling. The following parameters were added:#Tasks pending before Ready