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


Golang cli.Command類代碼示例

本文整理匯總了Golang中github.com/jwaldrip/odin/cli.Command的典型用法代碼示例。如果您正苦於以下問題:Golang Command類的具體用法?Golang Command怎麽用?Golang Command使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Command類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: download

func download(c cli.Command) {
	var (
		arglen     = len(c.Args())
		objectName string
		path       = c.Flag("path").String()
	)
	switch arglen {
	case 1:
		objectName = c.Arg(0).String()
	case 2:
		objectName = c.Arg(1).String()
		container = c.Arg(0).String()
	}
	if blank(container) || blank(objectName) {
		log.Fatal(errorNotEnough)
	}
	if blank(path) {
		path = objectName
	}
	reader, err := api.Container(container).Object(objectName).GetReader()
	if err != nil {
		log.Fatal(err)
	}
	defer reader.Close()
	fmt.Printf("downloading %s->%s from %s\n", objectName, path, container)
	f, err := os.Create(path)
	if err != nil {
		log.Fatal(err)
	}
	n, err := io.Copy(f, reader)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("downloaded %s, %d bytes\n", objectName, n)
}
開發者ID:ernado,項目名稱:selectel,代碼行數:35,代碼來源:main.go

示例2: roleRm

func roleRm(c cli.Command) {
	rmRoles := c.Args().Strings()
	if len(rmRoles) == 0 {
		log.Fatalln("Must specify some role[s] to remove")
	}

	nodeRoles, err := allNodeRoles()
	if err != nil {
		log.Fatalln("err: ", err)
	}

	myKey, err := selfKey()
	if err != nil {
		log.Fatalln("err: ", err)
	}

	var finalSet []string
	for _, role := range nodeRoles[myKey] {
		if !StrContains(rmRoles, role) {
			finalSet = append(finalSet, role)
		} else {
			fmt.Printf("removing role `%s`\n", role)
		}
	}
	roleActualSet(finalSet, c)
}
開發者ID:jen20,項目名稱:cascade,代碼行數:26,代碼來源:role.go

示例3: Run

func (v *Run) Run(c cli.Command) {

	jobName := c.Param("jobname").String()
	log.WithFields(
		log.Fields{
			"pkg":  "command",
			"func": "Run",
			"job":  jobName,
		},
	).Info("Starting job")

	j := job.New(metl.GetJobFilePath(jobName))

	j.Lock()

	jf, err := j.Fetch()
	if err != nil {
		log.Fatal("Error fetching job:", err)
	}

	jf.Run()

	j.Unlock()
	j.Done(jf)

	// log stats, notify of errors etc
	// notify of any errors

	// log stats to dashboard, number of processed, rejected rows etc.

	// if parsing option is empty then, we just download the file
}
開發者ID:JustAdam,項目名稱:metl,代碼行數:32,代碼來源:Run.go

示例4: cmRoll

func cmRoll(c cli.Command) {
	role := c.Flag("role").String()
	if len(role) == 0 && c.Flag("force").Get() != true {
		log.Fatalln("Must specify -f option to run with no `role` filter specified")
	} else {
		cmRunRoll(role, "")
	}
}
開發者ID:jen20,項目名稱:cascade,代碼行數:8,代碼來源:cm.go

示例5: nodeRun

func nodeRun(c cli.Command) {
	switch c.Param("action").String() {
	case "list":
		nodeList(c)
	default:
		cli.ShowUsage(c)
	}
}
開發者ID:jen20,項目名稱:cascade,代碼行數:8,代碼來源:node.go

示例6: Run

func (v *Add) Run(c cli.Command) {
	jobName := c.Param("jobname").String()
	var job job.Job
	if _, err := toml.DecodeFile(metl.GetJobFilePath(jobName)+".toml", &job); err != nil {
		log.Fatal(err)
	}

	cronfile := filepath.Join(metl.Etl.GetLocalStoragePath(), crontabFile)

	file, err := os.Open(cronfile)
	if err != nil {
		file, err = os.Create(cronfile)
		if err != nil {
			log.WithFields(
				log.Fields{
					"filename": cronfile,
				},
			).Fatal("Unable to create cronfile: ", err)
		}
	}
	defer file.Close()

	err = syscall.Flock(int(file.Fd()), syscall.LOCK_EX)
	if err != nil {
		log.Fatal("Failed to lock file")
	}

	defer func() {
		err = syscall.Flock(int(file.Fd()), syscall.LOCK_UN)
		if err != nil {
			log.Fatal("Failed to unlock file")
		}
	}()

	buffer := make([]string, 0)
	if err = jobIsInFile(file, jobName, &buffer); err != nil {
		log.Fatal(err)
	}
	buffer = append(buffer, fmt.Sprintf("%s %s >> %s%s.log", cmd, jobName, logDir, jobName))

	tmpf, err := ioutil.TempFile(metl.Etl.GetLocalStoragePath(), "tmp")
	if err != nil {
		log.Fatal("Unable to create temporary file.")
	}

	for _, line := range buffer {
		if _, err := tmpf.WriteString(line + "\n"); err != nil {
			log.Fatal("Unable to write to temporary file")
		}
	}

	if err := os.Rename(tmpf.Name(), cronfile); err != nil {
		log.Fatal("Failed to rename temporary lock file:", err)
	}

	// execute /usr/bin/env crontab cronfile
}
開發者ID:JustAdam,項目名稱:metl,代碼行數:57,代碼來源:Add.go

示例7: runner

func (etl *metl) runner(c cli.Command) {
	etl.preRunnerTasks()

	runnable := c.Name()
	if runner, ok := etl.runnables[runnable]; ok {
		runner.Run(c)
	} else {
		panic(fmt.Sprintf("Runnable %s not defined!", runnable))
	}
}
開發者ID:JustAdam,項目名稱:metl,代碼行數:10,代碼來源:Metl.go

示例8: create

func create(c cli.Command) {
	if len(c.Args()) == 0 {
		log.Fatal(errorNotEnough)
	}
	var name = c.Arg(0).String()
	if _, err := api.CreateContainer(name, false); err != nil {
		log.Fatal(err)
	}
	fmt.Printf("created container %s\n", name)
}
開發者ID:ernado,項目名稱:selectel,代碼行數:10,代碼來源:main.go

示例9: roleRun

func roleRun(c cli.Command) {
	switch c.Param("action").String() {
	case "list":
		roleList(c)
	case "set":
		roleSet(c)
	default:
		cli.ShowUsage(c)
	}
}
開發者ID:edwardt,項目名稱:cascade,代碼行數:10,代碼來源:role.go

示例10: cmRun

func cmRun(c cli.Command) {
	switch c.Param("action").String() {
	case "local":
		cmLocal(c)
	case "roll":
		cmRoll(c)
	case "single":
		cmSingle(c)
	default:
		cli.ShowUsage(c)
	}
}
開發者ID:edwardt,項目名稱:cascade,代碼行數:12,代碼來源:cm.go

示例11: serviceRun

func serviceRun(c cli.Command) {
	switch c.Param("action").String() {
	case "list":
		serviceList(c)
	case "local":
		serviceLocal(c)
	case "find":
		serviceFind(c)
	default:
		cli.ShowUsage(c)
	}
}
開發者ID:jen20,項目名稱:cascade,代碼行數:12,代碼來源:service.go

示例12: greetGreetee

func greetGreetee(c cli.Command) {
	greeting := c.Parent().Param("greeting")
	greetee := c.Param("greetee")
	str := fmt.Sprintf("%s %s", greeting, greetee)
	str = styleByFlags(str, c)
	c.Println(str, strings.Join(c.Args().Strings(), " "))
}
開發者ID:spekode,項目名稱:odin,代碼行數:7,代碼來源:main.go

示例13: upload

func upload(c cli.Command) {
	var path string
	switch len(c.Args()) {
	case 1:
		path = c.Arg(0).String()
	case 2:
		container = c.Arg(0).String()
		path = c.Arg(1).String()
	}
	if blank(container) || blank(path) {
		log.Fatal(errorNotEnough)
	}

	f, err := os.Open(path)
	if err != nil {
		log.Fatal(err)
	}

	stat, err := os.Stat(path)
	if err != nil {
		log.Fatal(err)
	}
	ext := filepath.Ext(path)
	mimetype := mime.TypeByExtension(ext)
	bar := pb.New64(stat.Size()).SetUnits(pb.U_BYTES)
	bar.Start()
	reader := io.TeeReader(f, bar)
	if err := api.Container(container).Upload(reader, stat.Name(), mimetype); err != nil {
		log.Fatal(err)
	}
	fmt.Printf("uploaded to %s\n", container)
}
開發者ID:ernado,項目名稱:selectel,代碼行數:32,代碼來源:main.go

示例14: roleSet

func roleSet(c cli.Command) {
	client, _ := api.NewClient(api.DefaultConfig())
	agent := client.Agent()

	reg := &api.AgentServiceRegistration{
		Name: "cascade",
		Tags: c.Args().Strings(),
	}

	if err := agent.ServiceRegister(reg); err != nil {
		log.Fatalln("err: ", err)
	}

	roleList(c)
}
開發者ID:edwardt,項目名稱:cascade,代碼行數:15,代碼來源:role.go

示例15: nodeList

func nodeList(c cli.Command) {
	client, _ := api.NewClient(api.DefaultConfig())
	catalog := client.Catalog()

	nodes, _, err := catalog.Service("cascade", c.Flag("role").String(), nil)

	if err != nil {
		log.Fatalln("Err: ", err)
	}

	for _, node := range nodes {
		fmt.Println(node.Node, node.Address+":")
		for _, role := range node.ServiceTags {
			fmt.Println("  -", role)
		}
	}
}
開發者ID:jen20,項目名稱:cascade,代碼行數:17,代碼來源:node.go


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