sindresorhus/meow

Add setting to indicate a flag can be set multiple times #111

sindresorhus posted onGitHub

Currently, if you have:

foo: {
    type: 'string'
}

And on the command-line, you do:

$ cli --foo=a

You get 'a' back, but if you do:

$ cli --foo=a --foo=b

You get and array back ['a', 'b'].

This is surprising and inconsistent.

Instead, we should allow only one value by default, and add a setting to the flags config to allow multiple for a flag, in which case, it will always return an array, even if there's only one flag.

I imagine it could be something like this:

{
    flags: {
        foo: {
            type: 'string',
            multiple: true
        }
    }
}

I also would like to propose this form when using multiple flag arguments:

{
    flags: {
        foo: {
            type: 'string',
            multiple: true
        }
    }
}

cli --foo=a --foo=b
cli --foo=a,b

// ['a', 'b']

if not already supported, and if the multiple property is true, the foo flag value should always be an array even if only one input is passed:

cli --foo=a
// ['a']
posted by b4dnewz about 6 years ago

and if the multiple property is true, the foo flag value should always be an array even if only one input is passed

Yes, that's already noted:

and add a setting to the flags config to allow multiple for a flag, in which case, it will always return an array, even if there's only one flag.

posted by sindresorhus about 6 years ago

Ah, sorry! I missed that, looking forward to see this update, when I've some spare time I'll watch at the src code and try to contribute myself. great project, it makes creating cli tools extremely easy and immediate, thanks!

posted by b4dnewz about 6 years ago

I also would like to propose this form when using multiple flag arguments:

I considered that form, but it's complicated as it would only work for flags where the value cannot be comma, otherwise it becomes ambiguous. For example, how would it handle this?

{
    flags: {
        foo: {
            type: 'string',
            multiple: true
        }
    }
}

cli --foo="I like unicorns, but not horses"
posted by sindresorhus about 6 years ago

The author would have to explicitly opt into supporting it if so, like multiple: 'list'.

posted by sindresorhus about 6 years ago

@sindresorhus mmh.. didn't thought about that..

The author would have to explicitly opt into supporting it if so, like multiple: 'list'.

It could be a good solution, do you mean list for using the comma separated values?

posted by b4dnewz about 6 years ago

It could be a good solution, do you mean list for using the comma separated values?

Yes

posted by sindresorhus about 6 years ago

it make sense, i'm looking to other project (yargs for example) to see how they deal with it but it seems they don't support the comma separated values so my idea probably might be bad and the list option shallow.

posted by b4dnewz about 6 years ago

@issuehunt has funded $40.00 to this issue. See it on IssueHunt

posted by IssueHuntBot about 6 years ago

Third time's a charm? #143

posted by ulken almost 5 years ago

@sindresorhus has rewarded $36.00 to @ulken. See it on IssueHunt

  • :moneybag: Total deposit: $40.00
  • :tada: Repository reward(0%): $0.00
  • :wrench: Service fee(10%): $4.00
posted by issuehunt-app[bot] almost 5 years ago

Fund this Issue

$40.00
Rewarded

Rewarded pull request

Recent activities

ulken was rewarded by sindresorhus for sindresorhus/meow# 111
almost 5 years ago
sindresorhus submitted an output to  sindresorhus/ meow# 111
almost 5 years ago