Last active
September 25, 2017 01:36
-
-
Save therealplato/8381f6943108149047e60f9a77e48377 to your computer and use it in GitHub Desktop.
urfave/cli delegating flag handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//$GOPATH/src/github.com/therealplato/scratch/repro-urfave/baz.go | |
package baz | |
import ( | |
"flag" | |
"fmt" | |
) | |
func Run() { | |
filename := flag.String("c", "", "filename of the JSON-based configuration file") | |
flag.Parse() | |
fmt.Printf("flag was `%v`", *filename) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//$GOPATH/src/github.com/therealplato/scratch/repro-urfave/cmd/main.go | |
/* | |
repro-urfave/cmd Ω ./cmd bar baz -c asdf | |
flag was ``% | |
repro-urfave/cmd Ω ./cmd bar baz -c=asdf | |
flag was ``% | |
repro-urfave/cmd Ω ./cmd bar baz -c='asdf' | |
flag was ``% | |
*/ | |
package main | |
import ( | |
"os" | |
baz "github.com/therealplato/scratch/repro-urfave" | |
cli "gopkg.in/urfave/cli.v1" | |
) | |
var args []string | |
func main() { | |
app := cli.NewApp() | |
app.Name = "foo" | |
app.Commands = []cli.Command{ | |
{ | |
Name: "bar", | |
Usage: "initialize", | |
SkipFlagParsing: true, | |
Subcommands: []cli.Command{ | |
{ | |
Name: "baz", | |
SkipFlagParsing: true, | |
Action: func(c *cli.Context) error { | |
baz.Run() | |
return nil | |
}, | |
}, | |
}, | |
}, | |
} | |
app.Run(os.Args) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
) | |
func main() { | |
filename := flag.String("c", "", "filename of the JSON-based configuration file") | |
flag.Parse() | |
fmt.Printf("flag was `%v`", *filename) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment