本文整理匯總了Golang中code/google/com/p/go-commander.Command類的典型用法代碼示例。如果您正苦於以下問題:Golang Command類的具體用法?Golang Command怎麽用?Golang Command使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Command類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: runInit
// runInit.
func runInit(cmd *commander.Command, args []string) {
if len(args) != 1 {
cmd.Usage()
return
}
// Initialize the engine based on the first argument and
// then verify it's not in-memory.
engines, err := initEngines(args[0])
if err != nil {
log.Errorf("Failed to initialize engine %q: %v", args[0], err)
return
}
e := engines[0]
if _, ok := e.(*engine.InMem); ok {
log.Errorf("Cannot initialize a cluster using an in-memory store")
return
}
// Generate a new UUID for cluster ID and bootstrap the cluster.
clusterID := uuid.New()
localDB, err := BootstrapCluster(clusterID, e)
if err != nil {
log.Errorf("Failed to bootstrap cluster: %v", err)
return
}
defer localDB.Close()
fmt.Fprintf(os.Stdout, "Cockroach cluster %s has been initialized\n", clusterID)
fmt.Fprintf(os.Stdout, "To start the cluster, run \"cockroach start\"\n")
}
示例2: runRmZone
// runRmZone invokes the REST API with DELETE action and key prefix as
// path.
func runRmZone(cmd *commander.Command, args []string) {
if len(args) != 1 {
cmd.Usage()
return
}
server.RunRmZone(Context, args[0])
}
示例3: runSetAcct
// runSetAcct invokes the REST API with POST action and key prefix as
// path. The specified configuration file is read from disk and sent
// as the POST body.
func runSetAcct(cmd *commander.Command, args []string) {
if len(args) != 2 {
cmd.Usage()
return
}
server.RunSetAcct(Context, args[0], args[1])
}
示例4: runLsZones
// runLsZones invokes the REST API with GET action and no path, which
// fetches a list of all zone configuration prefixes. The optional
// regexp is applied to the complete list and matching prefixes
// displayed.
func runLsZones(cmd *commander.Command, args []string) {
if len(args) > 1 {
cmd.Usage()
return
}
pattern := ""
if len(args) == 1 {
pattern = args[0]
}
server.RunLsZone(Context, pattern)
}
示例5: runGetZones
// runGetZones invokes the REST API with GET action and key prefix as path.
func runGetZones(cmd *commander.Command, args []string) {
if len(args) != 1 {
cmd.Usage()
return
}
req, err := http.NewRequest("GET", kv.HTTPAddr()+zoneKeyPrefix+"/"+args[0], nil)
if err != nil {
log.Errorf("unable to create request to admin REST endpoint: %v", err)
return
}
// TODO(spencer): need to move to SSL.
b, err := sendAdminRequest(req)
if err != nil {
log.Errorf("admin REST request failed: %v", err)
return
}
fmt.Fprintf(os.Stdout, "zone config for key prefix %q:\n%s\n", args[0], string(b))
}
示例6: runRmZone
// runRmZone invokes the REST API with DELETE action and key prefix as
// path.
func runRmZone(cmd *commander.Command, args []string) {
if len(args) != 1 {
cmd.Usage()
return
}
req, err := http.NewRequest("DELETE", kv.HTTPAddr()+zoneKeyPrefix+"/"+args[0], nil)
if err != nil {
fmt.Fprintf(os.Stderr, "unable to create request to admin REST endpoint: %v\n", err)
return
}
// TODO(spencer): need to move to SSL.
_, err = sendAdminRequest(req)
if err != nil {
fmt.Fprintf(os.Stderr, "admin REST request failed: %v\n", err)
return
}
fmt.Fprintf(os.Stdout, "removed zone config for key prefix %q\n", args[0])
}
示例7: runLsZones
// runLsZones invokes the REST API with GET action and no path, which
// fetches a list of all zone configuration prefixes. The optional
// regexp is applied to the complete list and matching prefixes
// displayed.
func runLsZones(cmd *commander.Command, args []string) {
if len(args) > 1 {
cmd.Usage()
return
}
req, err := http.NewRequest("GET", kv.HTTPAddr()+zoneKeyPrefix, nil)
if err != nil {
log.Errorf("unable to create request to admin REST endpoint: %v", err)
return
}
b, err := sendAdminRequest(req)
if err != nil {
log.Errorf("admin REST request failed: %v", err)
return
}
var prefixes []string
if err = json.Unmarshal(b, &prefixes); err != nil {
log.Errorf("unable to parse admin REST response: %v", err)
return
}
var re *regexp.Regexp
if len(args) == 1 {
if re, err = regexp.Compile(args[0]); err != nil {
log.Warningf("invalid regular expression %q; skipping regexp match and listing all zone prefixes", args[0])
re = nil
}
}
for _, prefix := range prefixes {
if re != nil {
unescaped, err := url.QueryUnescape(prefix)
if err != nil || !re.MatchString(unescaped) {
continue
}
}
if prefix == "" {
prefix = "[default]"
}
fmt.Fprintf(os.Stdout, "%s\n", prefix)
}
}
示例8: runInit
// runInit.
func runInit(cmd *commander.Command, args []string) {
if len(args) != 2 {
cmd.Usage()
return
}
// Specifying the disk type as HDD may be incorrect, but doesn't
// matter for this bootstrap step.
engine, err := initEngine(args[0])
if engine.Type() == storage.MEM {
glog.Fatal("Cannot initialize a cockroach cluster using an in-memory storage device")
}
if err != nil {
glog.Fatal(err)
}
// Generate a new cluster UUID.
clusterID := uuid.New()
if _, err := BootstrapCluster(clusterID, engine); err != nil {
glog.Fatal(err)
}
// TODO(spencer): install the default zone config.
glog.Infof("Cockroach cluster %s has been initialized", clusterID)
glog.Infof(`To start the cluster, run "cockroach start"`)
}
示例9: runSetZone
// runSetZone invokes the REST API with POST action and key prefix as
// path. The specified configuration file is read from disk and sent
// as the POST body.
func runSetZone(cmd *commander.Command, args []string) {
if len(args) != 2 {
cmd.Usage()
return
}
// Read in the config file.
body, err := ioutil.ReadFile(args[1])
if err != nil {
log.Errorf("unable to read zone config file %q: %v", args[1], err)
return
}
req, err := http.NewRequest("POST", kv.HTTPAddr()+zoneKeyPrefix+"/"+args[0], bytes.NewReader(body))
if err != nil {
log.Errorf("unable to create request to admin REST endpoint: %v", err)
return
}
// TODO(spencer): need to move to SSL.
_, err = sendAdminRequest(req)
if err != nil {
log.Errorf("admin REST request failed: %v", err)
return
}
fmt.Fprintf(os.Stdout, "set zone config for key prefix %q\n", args[0])
}