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


Golang cli.NewExitError函數代碼示例

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


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

示例1: execApplyCommand

// Executes the "apply" command
func execApplyCommand(c *cli.Context) error {
	if len(c.Args()) < 1 {
		return cli.NewExitError(errNoModuleName.Error(), 64)
	}

	L := lua.NewState()
	defer L.Close()
	config := &catalog.Config{
		Module:   c.Args()[0],
		DryRun:   c.Bool("dry-run"),
		Logger:   resource.DefaultLogger,
		SiteRepo: c.String("siterepo"),
		L:        L,
	}

	katalog := catalog.New(config)
	if err := katalog.Load(); err != nil {
		if err != nil {
			return cli.NewExitError(err.Error(), 1)
		}
	}

	if err := katalog.Run(); err != nil {
		return cli.NewExitError(err.Error(), 1)
	}

	return nil
}
開發者ID:ycaille,項目名稱:gru,代碼行數:29,代碼來源:apply.go

示例2: ProjectDelete

// ProjectDelete deletes services.
func ProjectDelete(p project.APIProject, c *cli.Context) error {
	options := options.Delete{
		RemoveVolume: c.Bool("v"),
	}
	if !c.Bool("force") {
		stoppedContainers, err := p.Containers(context.Background(), project.Filter{
			State: project.Stopped,
		}, c.Args()...)
		if err != nil {
			return cli.NewExitError(err.Error(), 1)
		}
		if len(stoppedContainers) == 0 {
			fmt.Println("No stopped containers")
			return nil
		}
		fmt.Printf("Going to remove %v\nAre you sure? [yN]\n", strings.Join(stoppedContainers, ", "))
		var answer string
		_, err = fmt.Scanln(&answer)
		if err != nil {
			return cli.NewExitError(err.Error(), 1)
		}
		if answer != "y" && answer != "Y" {
			return nil
		}
	}
	err := p.Delete(context.Background(), options, c.Args()...)
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}
	return nil
}
開發者ID:vdemeester,項目名稱:libcompose,代碼行數:32,代碼來源:app.go

示例3: statusRequest

func statusRequest() (*VMStatus, *cli.ExitError) {
	user := getUser()
	req, err := http.NewRequest("GET", "http://127.0.0.1:1050/status", nil)
	if err != nil {
		return nil, cli.NewExitError(err.Error(), 1)
	}

	req.Header.Add("X-Username", user.Name)
	client := &http.Client{}
	res, err := client.Do(req)
	if err != nil {
		return nil, cli.NewExitError(getRequestError(err), 1)
	}

	defer res.Body.Close()
	decoder := json.NewDecoder(res.Body)
	if res.StatusCode < 200 || res.StatusCode >= 400 {
		status := VMStatusError{}
		err := decoder.Decode(&status)
		if err != nil {
			return nil, cli.NewExitError(err.Error(), 1)
		}

		return nil, cli.NewExitError(status.Message, 1)
	}

	status := VMStatus{}
	err = decoder.Decode(&status)
	if err != nil {
		return nil, cli.NewExitError(err.Error(), 1)
	}

	return &status, nil
}
開發者ID:nlf,項目名稱:dlite,代碼行數:34,代碼來源:helpers.go

示例4: stringRequest

func stringRequest(action string) *cli.ExitError {
	user := getUser()
	req, err := http.NewRequest("POST", fmt.Sprintf("http://127.0.0.1:1050/%s", action), nil)
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}

	req.Header.Add("X-Username", user.Name)
	client := &http.Client{}
	res, err := client.Do(req)
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}

	defer res.Body.Close()
	body, err := ioutil.ReadAll(res.Body)
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}

	code := 0
	if res.StatusCode < 200 || res.StatusCode >= 400 {
		code = 1
	}

	return cli.NewExitError(string(body), code)
}
開發者ID:nlf,項目名稱:dlite,代碼行數:27,代碼來源:helpers.go

示例5: execListCommand

// Executes the "list" command
func execListCommand(c *cli.Context) error {
	klient := newEtcdMinionClientFromFlags(c)

	cFlag := c.String("with-classifier")
	minions, err := parseClassifierPattern(klient, cFlag)

	// Ignore errors about missing minion directory
	if err != nil {
		if eerr, ok := err.(client.Error); !ok || eerr.Code != client.ErrorCodeKeyNotFound {
			return cli.NewExitError(err.Error(), 1)
		}
	}

	if len(minions) == 0 {
		return nil
	}

	table := uitable.New()
	table.MaxColWidth = 80
	table.AddRow("MINION", "NAME")
	for _, minion := range minions {
		name, err := klient.MinionName(minion)
		if err != nil {
			return cli.NewExitError(err.Error(), 1)
		}

		table.AddRow(minion, name)
	}

	fmt.Println(table)

	return nil
}
開發者ID:dnaeon,項目名稱:gru,代碼行數:34,代碼來源:list.go

示例6: execLastseenCommand

// Executes the "lastseen" command
func execLastseenCommand(c *cli.Context) error {
	client := newEtcdMinionClientFromFlags(c)

	cFlag := c.String("with-classifier")
	minions, err := parseClassifierPattern(client, cFlag)

	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}

	table := uitable.New()
	table.MaxColWidth = 80
	table.AddRow("MINION", "LASTSEEN")
	for _, minion := range minions {
		lastseen, err := client.MinionLastseen(minion)
		if err != nil {
			return cli.NewExitError(err.Error(), 1)
		}

		table.AddRow(minion, time.Unix(lastseen, 0))
	}

	fmt.Println(table)

	return nil
}
開發者ID:dnaeon,項目名稱:gru,代碼行數:27,代碼來源:lastseen.go

示例7: execQueueCommand

// Executes the "queue" command
func execQueueCommand(c *cli.Context) error {
	if len(c.Args()) == 0 {
		return cli.NewExitError(errNoMinion.Error(), 64)
	}

	minion := uuid.Parse(c.Args()[0])
	if minion == nil {
		return cli.NewExitError(errInvalidUUID.Error(), 64)
	}

	klient := newEtcdMinionClientFromFlags(c)

	// Ignore errors about missing queue directory
	queue, err := klient.MinionTaskQueue(minion)
	if err != nil {
		if eerr, ok := err.(client.Error); !ok || eerr.Code != client.ErrorCodeKeyNotFound {
			return cli.NewExitError(err.Error(), 1)
		}
	}

	if len(queue) == 0 {
		return nil
	}

	table := uitable.New()
	table.MaxColWidth = 40
	table.AddRow("TASK", "STATE", "RECEIVED")
	for _, t := range queue {
		table.AddRow(t.ID, t.State, time.Unix(t.TimeReceived, 0))
	}

	fmt.Println(table)

	return nil
}
開發者ID:dnaeon,項目名稱:gru,代碼行數:36,代碼來源:queue.go

示例8: TestProcess

func TestProcess(t *testing.T) {
	passwd := "pass"
	url1, _ := soap.ParseURL("127.0.0.1")
	url2, _ := soap.ParseURL("root:@127.0.0.1")
	url3, _ := soap.ParseURL("line:[email protected]")
	url4, _ := soap.ParseURL("root:[email protected]")
	result, _ := url.Parse("https://root:[email protected]/sdk")
	passEmpty := ""
	result1, _ := url.Parse("https://root:@127.0.0.1/sdk")
	tests := []struct {
		URL      *url.URL
		User     string
		Password *string

		err    error
		result *url.URL
	}{
		{nil, "", nil, cli.NewExitError("--target argument must be specified", 1), nil},
		{nil, "root", nil, cli.NewExitError("--target argument must be specified", 1), nil},
		{nil, "root", &passwd, cli.NewExitError("--target argument must be specified", 1), nil},
		{url1, "root", &passwd, nil, result},
		{url4, "", nil, nil, result},
		{url3, "root", &passwd, nil, result},
		{url2, "", &passwd, nil, result},
		{url1, "root", &passEmpty, nil, result1},
	}

	for _, test := range tests {
		target := NewTarget()
		target.URL = test.URL
		target.User = test.User
		target.Password = test.Password
		if target.URL != nil {
			t.Logf("Before processing, url: %s", target.URL.String())
		}
		e := target.HasCredentials()
		if test.err != nil {
			if e == nil {
				t.Errorf("Empty error")
			}
			if e.Error() != test.err.Error() {
				t.Errorf("Unexpected error message: %s", e.Error())
			}
		} else if e != nil {
			t.Errorf("Unexpected error %s", e.Error())
		} else {
			if target.URL != test.URL {
				t.Errorf("unexpected result url: %s", target.URL.String())
			} else {
				t.Logf("result url: %s", target.URL.String())
			}
		}
	}
}
開發者ID:vmware,項目名稱:vic,代碼行數:54,代碼來源:target_test.go

示例9: ensureRoot

func ensureRoot() *cli.ExitError {
	if uid := os.Geteuid(); uid != 0 {
		return cli.NewExitError("This command requires sudo", 1)
	}

	if uid := os.Getenv("SUDO_UID"); uid == "" {
		return cli.NewExitError("This command requires sudo", 1)
	}

	return nil
}
開發者ID:nlf,項目名稱:dlite,代碼行數:11,代碼來源:helpers.go

示例10: validate

func validate(ip string, port int, c *cli.Context) *cli.ExitError {
	if strings.TrimSpace(ip) == "" {
		return cli.NewExitError("IP address is required. `hdp -h` for usage info.", 1)
	}
	if net.ParseIP(ip) == nil {
		return cli.NewExitError("Invalid IP address", 1)
	}
	if port < 0 || port > 65535 {
		return cli.NewExitError("Invalid port", 2)
	}
	return nil
}
開發者ID:vincer,項目名稱:hdp,代碼行數:12,代碼來源:hdp.go

示例11: runCleanup

func runCleanup(hostname, home string) *cli.ExitError {
	exe, err := osext.Executable()
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}

	output, err := exec.Command("sudo", exe, "cleanup", "--hostname", hostname, "--home", home).Output()
	code := 0
	if err != nil {
		code = 1
	}
	return cli.NewExitError(string(output), code)
}
開發者ID:nlf,項目名稱:dlite,代碼行數:13,代碼來源:helpers.go

示例12: execServeCommand

// Executes the "serve" command
func execServeCommand(c *cli.Context) error {
	name, err := os.Hostname()
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}

	concurrency := c.Int("concurrency")
	if concurrency < 0 {
		concurrency = runtime.NumCPU()
	}

	if c.String("siterepo") == "" {
		return cli.NewExitError(errNoSiteRepo.Error(), 64)
	}

	nameFlag := c.String("name")
	if nameFlag != "" {
		name = nameFlag
	}

	etcdCfg := etcdConfigFromFlags(c)
	minionCfg := &minion.EtcdMinionConfig{
		Concurrency: concurrency,
		Name:        name,
		SiteRepo:    c.String("siterepo"),
		EtcdConfig:  etcdCfg,
	}

	m, err := minion.NewEtcdMinion(minionCfg)
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}

	// Channel on which the shutdown signal is sent
	quit := make(chan os.Signal, 1)
	signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)

	// Start minion
	err = m.Serve()
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}

	// Block until a shutdown signal is received
	<-quit
	m.Stop()

	return nil
}
開發者ID:dnaeon,項目名稱:gru,代碼行數:50,代碼來源:serve.go

示例13: ProjectPull

// ProjectPull pulls images for services.
func ProjectPull(p project.APIProject, c *cli.Context) error {
	err := p.Pull(context.Background(), c.Args()...)
	if err != nil && !c.Bool("ignore-pull-failures") {
		return cli.NewExitError(err.Error(), 1)
	}
	return nil
}
開發者ID:vdemeester,項目名稱:rancher-compose,代碼行數:8,代碼來源:app.go

示例14: ProjectKill

// ProjectKill forces stop service containers.
func ProjectKill(p project.APIProject, c *cli.Context) error {
	err := p.Kill(context.Background(), c.String("signal"), c.Args()...)
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}
	return nil
}
開發者ID:vdemeester,項目名稱:rancher-compose,代碼行數:8,代碼來源:app.go

示例15: ProjectStop

// ProjectStop stops all services.
func ProjectStop(p project.APIProject, c *cli.Context) error {
	err := p.Stop(context.Background(), c.Int("timeout"), c.Args()...)
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}
	return nil
}
開發者ID:vdemeester,項目名稱:rancher-compose,代碼行數:8,代碼來源:app.go


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