當前位置: 首頁>>代碼示例>>Golang>>正文


Golang go-commander.Command類代碼示例

本文整理匯總了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")
}
開發者ID:jay23jack,項目名稱:cockroach,代碼行數:29,代碼來源:init.go

示例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])
}
開發者ID:josephwinston,項目名稱:cockroach,代碼行數:9,代碼來源:zone.go

示例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])
}
開發者ID:josephwinston,項目名稱:cockroach,代碼行數:10,代碼來源:accounting.go

示例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)
}
開發者ID:josephwinston,項目名稱:cockroach,代碼行數:15,代碼來源:zone.go

示例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))
}
開發者ID:bdotdub,項目名稱:cockroach,代碼行數:19,代碼來源:zone_cli.go

示例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])
}
開發者ID:Zemnmez,項目名稱:cockroach,代碼行數:20,代碼來源:zone_cli.go

示例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)
	}
}
開發者ID:bdotdub,項目名稱:cockroach,代碼行數:44,代碼來源:zone_cli.go

示例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"`)
}
開發者ID:Zemnmez,項目名稱:cockroach,代碼行數:24,代碼來源:init.go

示例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])
}
開發者ID:bdotdub,項目名稱:cockroach,代碼行數:27,代碼來源:zone_cli.go


注:本文中的code/google/com/p/go-commander.Command類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。