How to setup my arguments: two flag -ios -macos : can only set one to true

I want my command to work like this:

mytool --ios          # do iOS
mytool --macos.   # do macOS
mytool                  # must choose either --ios or --macos

I think this can be done with:

enum OSType: ExpressibleByArgument {
  case ios, macos

  init?(argument: String) {
    if "ios" == argument {
      self = .ios
    } else if "macos" == argument {
      self = .macos
    } else {
      return nil

// ... the in my command:

    @Argument(help: "Enter either --ios or --macOS (<== this doesn't work, how to enter?")
    var ostype: OSType

Am I doing the correctly? And how to use my Argument?

You are implementing this correctly, but you're trying to pass it in as an option, not an argument. To run this from the command line, you want:

mytool ios # do iOS
mytool macos #do macOS
1 Like


very nice! It worked.