Default Values - Documentation Doubt

Hi,

I have a doubt about default values in the documentation - Declaring Arguments, Options, and Flags

An option or argument with a default parameter can also be omitted by the user.

Questions:

  1. How to add default values to an argument ? (I thought default values could only be specified for @Option.)

You're right there — you can't currently provide a default value for an argument. Arguments with optional or array type have an implicit default, but there's no default parameter for other cases like there is with options and flags. I'll update the documentation!

1 Like

@nnnnnnnn Thanks a lot for the clarification.

I have one more doubt:

While using @Flag with an Int property the help seems to display as follows:

struct Test : ParsableCommand {
    
    @Flag()
    var numberFlag : Int //can be omitted
    
    func run() throws {
        print("numberFlag = \(numberFlag)")
    }
}

Test.main()

--help shows the following:
USAGE: test [--number-flag ...]

Question:

  • There is [--number-flag ...] seems like an array, is this a bug ?
1 Like

It would count the number of times the flag appears.

2 Likes

@Lantua Thanks a lot, I didn't think that far.
You are right repeating it twice gives 2.

This is just such a lovely framework really enjoy using it, thanks to everyone who worked on it

1 Like