jakeheis / SwiftCLI

A powerful framework for developing CLIs in Swift
MIT License
861 stars 72 forks source link

Having Global Option Groups #94

Closed mobileben closed 4 years ago

mobileben commented 4 years ago

Not sure if this is possible or not, but it would be super convenient if one could use Option Groups as Global Options.

I'm creating a tool where all commands require the same mutually exclusive Key items to define the input source (different possible variations of sources, but there must be one and only one).

What I am doing now is for each command, I'm doing this:

    @Key("-p", "--project")
    var project: String?
    @Key("-w", "--workspace")
    var workspace: String?
    @Key("-f", "--file")
    var file: String?
    var optionGroups: [OptionGroup] {
        return [.exactlyOne($project, $workspace, $file)]
    }

I'd ideally like to make that global.

jakeheis commented 4 years ago

This should be possible with cli.globalOptionGroups -- https://github.com/jakeheis/SwiftCLI/blob/master/Sources/SwiftCLI/CLI.swift#L44