github.com/jbendotnet/noms@v0.0.0-20190904222105-c43e4293ea92/cmd/noms/noms.go (about) 1 // Copyright 2016 Attic Labs, Inc. All rights reserved. 2 // Licensed under the Apache License, version 2.0: 3 // http://www.apache.org/licenses/LICENSE-2.0 4 5 package main 6 7 import ( 8 "fmt" 9 "math/rand" 10 "os" 11 "strings" 12 "time" 13 14 "github.com/attic-labs/kingpin" 15 16 "github.com/attic-labs/noms/cmd/noms/splore" 17 "github.com/attic-labs/noms/cmd/util" 18 "github.com/attic-labs/noms/go/util/profile" 19 "github.com/attic-labs/noms/go/util/verbose" 20 ) 21 22 var kingpinCommands = []util.KingpinCommand{ 23 nomsBlob, 24 nomsCommit, 25 nomsConfig, 26 nomsDiff, 27 nomsDs, 28 nomsList, 29 nomsLog, 30 nomsMerge, 31 nomsJSON, 32 nomsMap, 33 nomsRoot, 34 nomsServe, 35 nomsSet, 36 nomsShow, 37 nomsStats, 38 nomsStruct, 39 nomsSync, 40 splore.Cmd, 41 nomsVersion, 42 } 43 44 var actions = []string{ 45 "interacting with", 46 "poking at", 47 "goofing with", 48 "dancing with", 49 "playing with", 50 "contemplation of", 51 "showing off", 52 "jiggerypokery of", 53 "singing to", 54 "nomming on", 55 } 56 57 func usageString() string { 58 i := rand.New(rand.NewSource(time.Now().UnixNano())).Intn(len(actions)) 59 return fmt.Sprintf(`Noms is a tool for %s Noms data.`, actions[i]) 60 } 61 62 func main() { 63 // allow short (-h) help 64 kingpin.EnableFileExpansion = false 65 kingpin.CommandLine.HelpFlag.Short('h') 66 noms := kingpin.New("noms", usageString()) 67 68 // global flags 69 profile.RegisterProfileFlags(noms) 70 verbose.RegisterVerboseFlags(noms) 71 72 handlers := map[string]util.KingpinHandler{} 73 74 // install kingpin handlers 75 for _, cmdFunction := range kingpinCommands { 76 command, handler := cmdFunction(noms) 77 handlers[command.FullCommand()] = handler 78 } 79 80 input := kingpin.MustParse(noms.Parse(os.Args[1:])) 81 82 if handler := handlers[strings.Split(input, " ")[0]]; handler != nil { 83 handler(input) 84 } 85 }