Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,71 @@ | ||
package main | ||
|
||
import "fmt" | ||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"berty.tech/go/internal/banner" | ||
"github.com/peterbourgon/ff" | ||
"github.com/peterbourgon/ff/ffcli" | ||
) | ||
|
||
func main() { | ||
fmt.Println("Hello from bertychat!") | ||
log.SetFlags(0) | ||
|
||
var ( | ||
globalFlags = flag.NewFlagSet("bertychat", flag.ExitOnError) | ||
globalDebug = globalFlags.Bool("debug", false, "debug mode") | ||
bannerFlags = flag.NewFlagSet("banner", flag.ExitOnError) | ||
bannerLight = bannerFlags.Bool("light", false, "light mode") | ||
) | ||
|
||
globalPreRun := func() error { | ||
if *globalDebug { | ||
log.Print("debug enabled") | ||
// here: configure the logger | ||
} | ||
return nil | ||
} | ||
|
||
banner := &ffcli.Command{ | ||
Name: "banner", | ||
Usage: "banner", | ||
FlagSet: bannerFlags, | ||
Exec: func(args []string) error { | ||
if err := globalPreRun(); err != nil { | ||
return err | ||
} | ||
if *bannerLight { | ||
fmt.Println(banner.QOTD()) | ||
} else { | ||
fmt.Println(banner.OfTheDay()) | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
version := &ffcli.Command{ | ||
Name: "version", | ||
Usage: "version", | ||
Exec: func(args []string) error { | ||
fmt.Println("latest") | ||
return nil | ||
}, | ||
} | ||
|
||
root := &ffcli.Command{ | ||
Usage: "bertychat [global flags] <subcommand> [flags] [args...]", | ||
FlagSet: globalFlags, | ||
Options: []ff.Option{ff.WithEnvVarPrefix("BERTY")}, | ||
Subcommands: []*ffcli.Command{banner, version}, | ||
Exec: func([]string) error { | ||
return flag.ErrHelp | ||
}, | ||
} | ||
|
||
if err := root.Run(os.Args[1:]); err != nil { | ||
log.Fatalf("error: %v", err) | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module berty.tech/go | ||
|
||
go 1.13 | ||
|
||
require github.com/peterbourgon/ff v1.6.0 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= | ||
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= | ||
github.com/peterbourgon/ff v1.6.0 h1:DNnSOwtqmHfQ/yLgdOvtN4eFzP4ps+IjNhUEW9/ZkIg= | ||
github.com/peterbourgon/ff v1.6.0/go.mod h1:8rO4i98n/oYmyP28qiK6V4jGB85nMNVr+qwSErTwFrs= | ||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc= | ||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |