aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go54
1 files changed, 15 insertions, 39 deletions
diff --git a/main.go b/main.go
index 5265ada..5088e84 100644
--- a/main.go
+++ b/main.go
@@ -1,49 +1,25 @@
package main
import (
- "errors"
- "fmt"
+ "context"
+ "flag"
"os"
-)
-
-var mainUsage = []string{
- "-C [-q] -p pubkey -x sigfile [file ...]",
- "-G [-n] [-c comment] -p pubkey -s seckey",
- "-S [-ez] [-x sigfile] -s seckey -m message",
- "-V [-eqz] [-p pubkey] [-t keytype] [-x sigfile] -m message",
-}
-var ErrEZ = errors.New("can't combine -e and -z options")
+ "github.com/google/subcommands"
+)
-func usage() {
- fmt.Println("Usage:")
- for _, u := range mainUsage {
- fmt.Printf("%v %v\n", progName(), u)
- }
- os.Exit(2)
-}
+func main() {
+ subcommands.Register(subcommands.CommandsCommand(), "")
+ subcommands.Register(subcommands.FlagsCommand(), "")
+ subcommands.Register(subcommands.HelpCommand(), "")
-func fail(err error) {
- fmt.Println(err)
- os.Exit(1)
-}
+ subcommands.Register(&checkCommand{}, "")
+ subcommands.Register(&generateCommand{}, "")
+ subcommands.Register(&signCommand{}, "")
+ subcommands.Register(&verifyCommand{}, "")
-var modes = map[string]func([]string) error{
- "-C": check,
- "-G": generate,
- "-S": sign,
- "-V": verify,
-}
+ flag.Parse()
-func main() {
- if len(os.Args) < 2 {
- usage()
- }
- mode, ok := modes[os.Args[1]]
- if !ok {
- usage()
- }
- if err := mode(os.Args[2:]); err != nil {
- fail(err)
- }
+ ctx := context.Background()
+ os.Exit(int(subcommands.Execute(ctx)))
}