jawher / mow.cli

A versatile library for building CLI applications in Go
MIT License
871 stars 55 forks source link

Cannot use exclusive choices with OPTIONS #95

Open sungo opened 5 years ago

sungo commented 5 years ago

I'd like to use exclusive choices with OPTIONS. It seems I can't do that currently. Example code follows below. With the spec line app.Spec = "(--one | --two) [OPTIONS]", it is legal for the user to call main --one --two. With the spec line app.Spec = "(--one | --two)", the user must choice between using --one or --two.

In this example, I'm looking for the latter, to force the user to specify --one OR --two and separately allow them to specific --recursive

package main                                                                                                                                                                                          

import (                                                                                                                                                                                              
    "fmt"                                                                                                                                                                                             
    "os"                                                                                                                                                                                              

    "github.com/jawher/mow.cli"                                                                                                                                                                       
)                                                                                                                                                                                                     

func main() {                                                                                                                                                                                         
    app := cli.App("cp", "Copy files around")                                                                                                                                                         

    app.Spec = "(--one | --two) [OPTIONS]"                                                                                                                                                            
    //app.Spec = "(--one | --two)"                                                                                                                                                                    

    var (                                                                                                                                                                                             
        recursive = app.BoolOpt("r recursive", false, "Copy files recursively")                                                                                                                       
        one       = app.BoolOpt("one", false, "One")                                                                                                                                                  
        two       = app.BoolOpt("two", false, "Two")                                                                                                                                                  
    )                                                                                                                                                                                                 

    app.Action = func() {                                                                                                                                                                             
        fmt.Println("hello")                                                                                                                                                                          
        fmt.Printf("One: %v | Two: %v | Recursive: %v\n", *one, *two, *recursive)                                                                                                                     
    }                                                                                                                                                                                                 

    app.Run(os.Args)                                                                                                                                                                                  
}