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

trim() input string of .arguments method #1874

Merged
merged 1 commit into from
May 4, 2023
Merged

Conversation

Felarn
Copy link
Contributor

@Felarn Felarn commented May 4, 2023

Pull Request

Problem

If there are trailing spaces in string with list of arguments passed to .arguments() method, script will expect extra argument with empty name ''.

import {program} from 'commander'

program.arguments('<arg1> <arg2> ')
program.parse()

console.log(program.args);

And throw error when called, that is obscure on a first glance:

node commanderTest.js one two
error: missing required argument ''

Solution

Trimmed string of arguments before splitting it in into array of individual names

ChangeLog

leading and trailing spaces are now ignored by the .arguments() method.

Copy link
Collaborator

@shadowspawn shadowspawn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
It is a bit of an edge case, but the split allows for extra spaces so consistent with existing code. Fair enough.

@shadowspawn shadowspawn changed the base branch from master to develop May 4, 2023 10:32
Copy link
Collaborator

@abetomo abetomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@abetomo abetomo merged commit 2f07c2a into tj:develop May 4, 2023
@shadowspawn shadowspawn added the pending release Merged into a branch for a future release, but not released yet label May 4, 2023
@shadowspawn
Copy link
Collaborator

Released in v11

Thanks @Felarn

@shadowspawn shadowspawn removed the pending release Merged into a branch for a future release, but not released yet label Jun 16, 2023
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.

3 participants