summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/GeertJohan/go.rice/rice/flags.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-02-18 23:00:46 +0100
committerWim <wim@42.be>2017-02-18 23:11:48 +0100
commit930b639cc9cd2d2873302f30303378c0e53816a8 (patch)
tree8cd3f1d464fb5d4e5607fe16255c35a31a9d8b62 /vendor/github.com/GeertJohan/go.rice/rice/flags.go
parent58483ea70c2c99a352592c5e50686fb03985650e (diff)
downloadmatterbridge-msglm-930b639cc9cd2d2873302f30303378c0e53816a8.tar.gz
matterbridge-msglm-930b639cc9cd2d2873302f30303378c0e53816a8.tar.bz2
matterbridge-msglm-930b639cc9cd2d2873302f30303378c0e53816a8.zip
Update vendor
Diffstat (limited to 'vendor/github.com/GeertJohan/go.rice/rice/flags.go')
-rw-r--r--vendor/github.com/GeertJohan/go.rice/rice/flags.go80
1 files changed, 80 insertions, 0 deletions
diff --git a/vendor/github.com/GeertJohan/go.rice/rice/flags.go b/vendor/github.com/GeertJohan/go.rice/rice/flags.go
new file mode 100644
index 00000000..167fea80
--- /dev/null
+++ b/vendor/github.com/GeertJohan/go.rice/rice/flags.go
@@ -0,0 +1,80 @@
+package main
+
+import (
+ "fmt"
+ "go/build"
+ "os"
+
+ goflags "github.com/jessevdk/go-flags" // rename import to `goflags` (file scope) so we can use `var flags` (package scope)
+)
+
+// flags
+var flags struct {
+ Verbose bool `long:"verbose" short:"v" description:"Show verbose debug information"`
+ ImportPaths []string `long:"import-path" short:"i" description:"Import path(s) to use. Using PWD when left empty. Specify multiple times for more import paths to append"`
+
+ Append struct {
+ Executable string `long:"exec" description:"Executable to append" required:"true"`
+ } `command:"append"`
+
+ EmbedGo struct{} `command:"embed-go" alias:"embed"`
+ EmbedSyso struct{} `command:"embed-syso"`
+ Clean struct{} `command:"clean"`
+}
+
+// flags parser
+var flagsParser *goflags.Parser
+
+// initFlags parses the given flags.
+// when the user asks for help (-h or --help): the application exists with status 0
+// when unexpected flags is given: the application exits with status 1
+func parseArguments() {
+ // create flags parser in global var, for flagsParser.Active.Name (operation)
+ flagsParser = goflags.NewParser(&flags, goflags.Default)
+
+ // parse flags
+ args, err := flagsParser.Parse()
+ if err != nil {
+ // assert the err to be a flags.Error
+ flagError := err.(*goflags.Error)
+ if flagError.Type == goflags.ErrHelp {
+ // user asked for help on flags.
+ // program can exit successfully
+ os.Exit(0)
+ }
+ if flagError.Type == goflags.ErrUnknownFlag {
+ fmt.Println("Use --help to view available options.")
+ os.Exit(1)
+ }
+ if flagError.Type == goflags.ErrRequired {
+ os.Exit(1)
+ }
+ fmt.Printf("Error parsing flags: %s\n", err)
+ os.Exit(1)
+ }
+
+ // error on left-over arguments
+ if len(args) > 0 {
+ fmt.Printf("Unexpected arguments: %s\nUse --help to view available options.", args)
+ os.Exit(1)
+ }
+
+ // default ImportPath to pwd when not set
+ if len(flags.ImportPaths) == 0 {
+ pwd, err := os.Getwd()
+ if err != nil {
+ fmt.Printf("error getting pwd: %s\n", err)
+ os.Exit(1)
+ }
+ verbosef("using pwd as import path\n")
+ // find non-absolute path for this pwd
+ pkg, err := build.ImportDir(pwd, build.FindOnly)
+ if err != nil {
+ fmt.Printf("error using current directory as import path: %s\n", err)
+ os.Exit(1)
+ }
+ flags.ImportPaths = append(flags.ImportPaths, pkg.ImportPath)
+ verbosef("using import paths: %s\n", flags.ImportPaths)
+ return
+ }
+}