github.com/huiliang/nomad@v0.2.1-0.20151124023127-7a8b664699ff/commands.go (about) 1 package main 2 3 import ( 4 "os" 5 6 "github.com/hashicorp/nomad/command" 7 "github.com/hashicorp/nomad/command/agent" 8 "github.com/mitchellh/cli" 9 ) 10 11 // Commands returns the mapping of CLI commands for Nomad. The meta 12 // parameter lets you set meta options for all commands. 13 func Commands(metaPtr *command.Meta) map[string]cli.CommandFactory { 14 if metaPtr == nil { 15 metaPtr = new(command.Meta) 16 } 17 18 meta := *metaPtr 19 if meta.Ui == nil { 20 meta.Ui = &cli.BasicUi{ 21 Writer: os.Stdout, 22 ErrorWriter: os.Stderr, 23 } 24 } 25 26 return map[string]cli.CommandFactory{ 27 "alloc-status": func() (cli.Command, error) { 28 return &command.AllocStatusCommand{ 29 Meta: meta, 30 }, nil 31 }, 32 33 "agent": func() (cli.Command, error) { 34 return &agent.Command{ 35 Revision: GitCommit, 36 Version: Version, 37 VersionPrerelease: VersionPrerelease, 38 Ui: meta.Ui, 39 ShutdownCh: make(chan struct{}), 40 }, nil 41 }, 42 43 "agent-info": func() (cli.Command, error) { 44 return &command.AgentInfoCommand{ 45 Meta: meta, 46 }, nil 47 }, 48 49 "client-config": func() (cli.Command, error) { 50 return &command.ClientConfigCommand{ 51 Meta: meta, 52 }, nil 53 }, 54 55 "eval-monitor": func() (cli.Command, error) { 56 return &command.EvalMonitorCommand{ 57 Meta: meta, 58 }, nil 59 }, 60 61 "init": func() (cli.Command, error) { 62 return &command.InitCommand{ 63 Meta: meta, 64 }, nil 65 }, 66 67 "node-drain": func() (cli.Command, error) { 68 return &command.NodeDrainCommand{ 69 Meta: meta, 70 }, nil 71 }, 72 73 "node-status": func() (cli.Command, error) { 74 return &command.NodeStatusCommand{ 75 Meta: meta, 76 }, nil 77 }, 78 79 "run": func() (cli.Command, error) { 80 return &command.RunCommand{ 81 Meta: meta, 82 }, nil 83 }, 84 85 "server-force-leave": func() (cli.Command, error) { 86 return &command.ServerForceLeaveCommand{ 87 Meta: meta, 88 }, nil 89 }, 90 91 "server-join": func() (cli.Command, error) { 92 return &command.ServerJoinCommand{ 93 Meta: meta, 94 }, nil 95 }, 96 97 "server-members": func() (cli.Command, error) { 98 return &command.ServerMembersCommand{ 99 Meta: meta, 100 }, nil 101 }, 102 103 "spawn-daemon": func() (cli.Command, error) { 104 return &command.SpawnDaemonCommand{ 105 Meta: meta, 106 }, nil 107 }, 108 109 "status": func() (cli.Command, error) { 110 return &command.StatusCommand{ 111 Meta: meta, 112 }, nil 113 }, 114 115 "stop": func() (cli.Command, error) { 116 return &command.StopCommand{ 117 Meta: meta, 118 }, nil 119 }, 120 121 "validate": func() (cli.Command, error) { 122 return &command.ValidateCommand{ 123 Meta: meta, 124 }, nil 125 }, 126 127 "version": func() (cli.Command, error) { 128 ver := Version 129 rel := VersionPrerelease 130 if GitDescribe != "" { 131 ver = GitDescribe 132 // Trim off a leading 'v', we append it anyways. 133 if ver[0] == 'v' { 134 ver = ver[1:] 135 } 136 } 137 if GitDescribe == "" && rel == "" && VersionPrerelease != "" { 138 rel = "dev" 139 } 140 141 return &command.VersionCommand{ 142 Revision: GitCommit, 143 Version: ver, 144 VersionPrerelease: rel, 145 Ui: meta.Ui, 146 }, nil 147 }, 148 } 149 }