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

feat: Enhance cli command line #107

Merged
merged 12 commits into from
Jul 5, 2023
Merged

feat: Enhance cli command line #107

merged 12 commits into from
Jul 5, 2023

Conversation

davidgamez
Copy link
Member

@davidgamez davidgamez commented Jun 29, 2023

Description

In this PR, the cli.js file is enhanced with additional parameters, help messages, and error handling. The following parameters were added:

Usage: cli [OPTIONS]...

Options:
  -v, --version                    output the version number
  -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")
  -h, --help                       display help for command

#Tasks pending before Ready

  • add unit tests
  • Update REAME.md

@netlify
Copy link

netlify bot commented Jun 29, 2023

Deploy Preview for gbfs-validator ready!

Name Link
🔨 Latest commit cadabd5
🔍 Latest deploy log https://app.netlify.com/sites/gbfs-validator/deploys/64a5b694bf0f7c0008c73443
😎 Deploy Preview https://deploy-preview-107--gbfs-validator.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Collaborator

@PierrickP PierrickP left a 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')
Copy link
Collaborator

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

Copy link
Member Author

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.

}
}

if (options.url) {
Copy link
Collaborator

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.

Copy link
Member Author

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.

Copy link
Collaborator

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

}
try {
const report = await getFeedValidationReport(options.url)
if (options.print) {
Copy link
Collaborator

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

Copy link
Member Author

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.

Copy link
Contributor

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?

Copy link
Member Author

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.

gbfs-validator/cli.js Outdated Show resolved Hide resolved
@davidgamez
Copy link
Member Author

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?

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 davidgamez marked this pull request as ready for review July 4, 2023 20:41
@PierrickP
Copy link
Collaborator

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

@davidgamez
Copy link
Member Author

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

gbfs-validator/cli.js Outdated Show resolved Hide resolved
gbfs-validator/__test__/cli.test.js Dismissed Show dismissed Hide dismissed
gbfs-validator/cli.js Outdated Show resolved Hide resolved
davidgamez and others added 2 commits July 5, 2023 14:29
Co-authored-by: Fabien Richard-Allouard <fabien@mobilitydata.org>
Co-authored-by: Fabien Richard-Allouard <fabien@mobilitydata.org>
.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']))
Copy link
Contributor

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?

Suggested change
.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']))

Copy link
Member Author

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 () => {
Copy link
Contributor

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)

Suggested change
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'])
Copy link
Contributor

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)

Suggested change
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'])
Copy link
Contributor

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)

Suggested change
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'])
Copy link
Contributor

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)

Suggested change
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")
Copy link
Contributor

@richfab richfab Jul 5, 2023

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)

Suggested change
-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")

Copy link
Contributor

@richfab richfab left a 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!

@davidgamez davidgamez merged commit 2bc59f9 into master Jul 5, 2023
8 checks passed
@davidgamez davidgamez deleted the feat/enhance-cli-command branch July 5, 2023 20:21
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

Successfully merging this pull request may close these issues.

None yet

3 participants