Created
October 1, 2019 16:10
-
-
Save bkono/b9abb43b3896689f0d038f8a7b9fabaf to your computer and use it in GitHub Desktop.
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 ( | |
"fmt" | |
"gopkg.in/alecthomas/kingpin.v2" | |
) | |
type DevCommand struct { | |
debug bool | |
} | |
func (d *DevCommand) run(c *kingpin.ParseContext) error { | |
fmt.Println("running dev, debug? ", d.debug) | |
return nil | |
} | |
func configureDevCommand(app *kingpin.Application) { | |
cmd := &DevCommand{} | |
d := app.Command("dev", "Runs dev").Action(cmd.run) | |
d.Flag("debug", "use debug").BoolVar(&cmd.debug) | |
} |
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
module github.com/bkono/clier | |
go 1.12 | |
require ( | |
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect | |
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect | |
github.com/stretchr/testify v1.3.0 // indirect | |
gopkg.in/alecthomas/kingpin.v2 v2.2.6 | |
) |
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 ( | |
"fmt" | |
"gopkg.in/alecthomas/kingpin.v2" | |
"os" | |
) | |
func parseConfig(c *kingpin.ParseContext) error { | |
fmt.Printf("parse config with context: %+v\n", c) | |
return nil | |
} | |
func main() { | |
kingpin.HelpFlag.Short('h') | |
app := kingpin.New("modular", "My modular application.").Action(parseConfig) | |
configureServerCommand(app) | |
configureDevCommand(app) | |
kingpin.MustParse(app.Parse(os.Args[1:])) | |
} |
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 ( | |
"fmt" | |
"gopkg.in/alecthomas/kingpin.v2" | |
) | |
type ServerCommand struct { | |
port string | |
} | |
func (s *ServerCommand) run(c *kingpin.ParseContext) error { | |
fmt.Println("running server on port ", s.port) | |
return nil | |
} | |
func configureServerCommand(app *kingpin.Application) { | |
cmd := &ServerCommand{} | |
s := app.Command("server", "Runs a server").Action(cmd.run).Default() | |
s.Flag("port", "port to listen on").Short('p').Default("4000").StringVar(&cmd.port) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment