当前位置: 首页>>代码示例>>Golang>>正文


Golang cli.NewExitError函数代码示例

本文整理汇总了Golang中github.com/codegangsta/cli.NewExitError函数的典型用法代码示例。如果您正苦于以下问题:Golang NewExitError函数的具体用法?Golang NewExitError怎么用?Golang NewExitError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewExitError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: cmdRun

func cmdRun(c *cli.Context) error {
	s, err := openAndCheck(c)
	if err != nil {
		return cli.NewExitError(err.Error(), 3)
	}

	webAddr := c.String("web-addr")
	saslPaths := c.StringSlice("sock")

	var wg sync.WaitGroup
	if webAddr != "" {
		wg.Add(1)
		go func() {
			defer wg.Done()
			if err := runWebAddr(webAddr, s.GetInterface(), c.GlobalString("web-static-dir")); err != nil {
				fmt.Printf("warning running web interface failed: %s\n", err)
			}
		}()
	}
	for _, path := range saslPaths {
		p := path
		wg.Add(1)
		go func() {
			defer wg.Done()
			if err := runSaslAuthSocket(p, s.GetInterface()); err != nil {
				fmt.Printf("warning running auth agent(%s) failed: %s\n", p, err)
			}
		}()
	}
	wg.Wait()

	return cli.NewExitError(fmt.Sprintf("shutting down since all auth sockets have closed."), 0)
}
开发者ID:whawty,项目名称:auth,代码行数:33,代码来源:main.go

示例2: upAction

func upAction(c *cli.Context) error {
	// TODO: get port from args
	port := "3000"
	consPort, err := getConsolePort(port)
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}

	// TODO:
	apiServerURL := "https://api.leancloud.cn"

	appInfo, err := apps.CurrentAppInfo(".")
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}

	rtm, err := apps.DetectRuntime(".")
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}

	rtm.Envs["LC_APP_ID"] = appInfo.AppID
	rtm.Envs["LC_APP_KEY"] = appInfo.AppKey
	rtm.Envs["LC_APP_MASTER_KEY"] = appInfo.MasterKey
	rtm.Envs["LC_APP_PORT"] = port
	rtm.Envs["LC_API_SERVER"] = apiServerURL
	rtm.Envs["LEANCLOUD_APP_ID"] = appInfo.AppID
	rtm.Envs["LEANCLOUD_APP_KEY"] = appInfo.AppKey
	rtm.Envs["LEANCLOUD_APP_MASTER_KEY"] = appInfo.MasterKey
	rtm.Envs["LEANCLOUD_APP_PORT"] = port
	rtm.Envs["LEANCLOUD_API_SERVER"] = apiServerURL

	go func() {
		err := rtm.Run()
		if err != nil {
			panic(err)
		}
	}()

	cons := &console.Server{
		AppID:       appInfo.AppID,
		AppKey:      appInfo.AppKey,
		MasterKey:   appInfo.MasterKey,
		AppPort:     port,
		ConsolePort: consPort,
	}

	cons.Run()
	return nil
}
开发者ID:aisk,项目名称:lean-cli-backup,代码行数:50,代码来源:up_action.go

示例3: cmdCheck

func cmdCheck(c *cli.Context) error {
	s, err := NewStore(c.GlobalString("store"), c.GlobalString("do-upgrades"),
		c.GlobalString("policy-type"), c.GlobalString("policy-condition"), c.GlobalString("hooks-dir"))
	if err != nil {
		return cli.NewExitError(fmt.Sprintf("Error opening whawty store: %s", err), 3)
	}
	ok, err := s.GetInterface().Check()
	if err != nil {
		return cli.NewExitError(fmt.Sprintf("Error checking whawty store: %s", err), 3)
	}
	if !ok {
		return cli.NewExitError(fmt.Sprintf("whawty store is invalid!"), 1)
	}
	return cli.NewExitError(fmt.Sprintf("whawty store is ok!"), 0)
}
开发者ID:whawty,项目名称:auth,代码行数:15,代码来源:main.go

示例4: jobs_push

func jobs_push(c *cli.Context) error {
	// push the image
	docker_image, err := get_docker_image_name(c)
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}
	log.Info("Pushing", docker_image)
	cmd := exec.Command("docker", "push", docker_image)
	output, err := cmd.CombinedOutput()
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}
	log.Info(string(output))
	return nil
}
开发者ID:ngageoint,项目名称:scale,代码行数:15,代码来源:jobs.go

示例5: cmdList

func cmdList(c *cli.Context) error {
	s, err := openAndCheck(c)
	if err != nil {
		return cli.NewExitError(err.Error(), 3)
	}

	if c.Bool("full") {
		err = cmdListFull(s.GetInterface())
	} else {
		err = cmdListSupported(s.GetInterface())
	}
	if err != nil {
		return cli.NewExitError(err.Error(), 3)
	}
	return cli.NewExitError("", 0)
}
开发者ID:whawty,项目名称:auth,代码行数:16,代码来源:main.go

示例6: loginAction

func loginAction(c *cli.Context) error {
	email, password := inputAccountInfo()
	info, err := api.Login(email, password)
	if err != nil {
		switch e := err.(type) {
		case api.Error:
			return cli.NewExitError(e.Content, 1)
		default:
			return cli.NewExitError(e.Error(), 1)
		}
	}
	fmt.Println("登录成功:")
	fmt.Printf("用户名: %s\r\n", info.Get("username").MustString())
	fmt.Printf("邮箱: %s\r\n", info.Get("email").MustString())
	return nil
}
开发者ID:aisk,项目名称:lean-cli-backup,代码行数:16,代码来源:login_action.go

示例7: cmdRunSa

func cmdRunSa(c *cli.Context) error {
	s, err := openAndCheck(c)
	if err != nil {
		return cli.NewExitError(err.Error(), 3)
	}

	listeners, err := activation.Listeners(true)
	if err != nil {
		return cli.NewExitError(fmt.Sprintf("fetching socket listeners from systemd failed: %s", err), 2)
	}

	fmt.Printf("got %d sockets from systemd\n", len(listeners))
	if len(listeners) == 0 {
		return cli.NewExitError("shutting down since there are no sockets to lissten on.", 2)
	}

	var wg sync.WaitGroup
	for idx, listener := range listeners {
		switch listener.(type) {
		case *net.UnixListener:
			fmt.Printf("listener[%d]: is a UNIX socket (-> saslauthd)\n", idx)
			wg.Add(1)
			ln := listener.(*net.UnixListener)
			go func() {
				defer wg.Done()
				if err := runSaslAuthSocketListener(ln, s.GetInterface()); err != nil {
					fmt.Printf("warning running auth agent failed: %s\n", err)
				}
			}()
		case *net.TCPListener:
			fmt.Printf("listener[%d]: is a TCP socket (-> HTTP)\n", idx)
			wg.Add(1)
			ln := listener.(*net.TCPListener)
			go func() {
				defer wg.Done()
				if err := runWebListener(ln, s.GetInterface(), c.GlobalString("web-static-dir")); err != nil {
					fmt.Printf("error running web-api: %s", err)
				}
			}()
		default:
			fmt.Printf("listener[%d]: has type %T (ingnoring)\n", idx, listener)
		}
	}
	wg.Wait()

	return cli.NewExitError(fmt.Sprintf("shutting down since all auth sockets have closed."), 0)
}
开发者ID:whawty,项目名称:auth,代码行数:47,代码来源:main.go

示例8: cmdRemove

func cmdRemove(c *cli.Context) error {
	s, err := openAndCheck(c)
	if err != nil {
		return cli.NewExitError(err.Error(), 3)
	}

	username := c.Args().First()
	if username == "" {
		cli.ShowCommandHelp(c, "remove")
		return cli.NewExitError("", 0)
	}

	if err := s.GetInterface().Remove(username); err != nil {
		return cli.NewExitError(fmt.Sprintf("Error removing user '%s': %s", username, err), 3)
	}
	return cli.NewExitError(fmt.Sprintf("user '%s' successfully removed!", username), 0)
}
开发者ID:whawty,项目名称:auth,代码行数:17,代码来源:main.go

示例9: jobs_commit

func jobs_commit(c *cli.Context) error {
	// push json into Dockerfile
	var job_type scalecli.JobType
	err := Parse_json_or_yaml("job_type", &job_type)
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}
	registry := c.GlobalString("registry")
	if registry != "" {
		if !strings.HasPrefix(job_type.DockerImage, registry) {
			job_type.DockerImage = registry + "/" + job_type.DockerImage
		}
	}
	tag := c.GlobalString("tag")
	if tag != "" {
		if !strings.HasSuffix(job_type.DockerImage, tag) {
			job_type.DockerImage = job_type.DockerImage + ":" + tag
		}
	}
	json_data, err := json.Marshal(job_type)
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}
	err = set_label_value("Dockerfile", "com.ngageoint.scale.job-type", string(json_data))
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}

	// build the docker image
	docker_image, err := get_docker_image_name(c)
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}
	log.Info("Building", docker_image)
	cmd := exec.Command("docker", "build", "-t", docker_image, ".")
	output, err := cmd.CombinedOutput()
	if err != nil {
		return cli.NewExitError(string(output), 1)
	}
	log.Info(string(output))

	if c.Bool("push") {
		jobs_push(c)
	}
	return nil
}
开发者ID:ngageoint,项目名称:scale,代码行数:46,代码来源:jobs.go

示例10: strike_create

func strike_create(c *cli.Context) error {
	url := c.GlobalString("url")
	if url == "" {
		return cli.NewExitError("A URL must be provided with the SCALE_URL environment variable or the --url argument", 1)
	}
	data_file := c.String("data")
	var strike_data scalecli.StrikeData
	err := Parse_json_or_yaml(data_file, &strike_data)
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}
	strike_process_id, err := scalecli.CreateStrikeProcess(url, strike_data)
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}
	color.Blue(fmt.Sprintf("Strike process %d created.", strike_process_id))
	return nil
}
开发者ID:ngageoint,项目名称:scale,代码行数:18,代码来源:strike.go

示例11: workspaces_list

func workspaces_list(c *cli.Context) error {
	max := c.Int("max")
	url := c.GlobalString("url")
	if url == "" {
		return cli.NewExitError("A URL must be provided with the SCALE_URL environment variable or the --url argument", 1)
	}
	workspaces, err := scalecli.GetWorkspaceList(url, max)
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}
	for _, workspace := range workspaces {
		if workspace.Is_active {
			color.Green(workspace.String())
		} else {
			color.White(workspace.String())
		}
	}
	return nil
}
开发者ID:ngageoint,项目名称:scale,代码行数:19,代码来源:workspaces.go

示例12: cmdSetAdmin

func cmdSetAdmin(c *cli.Context) error {
	s, err := openAndCheck(c)
	if err != nil {
		return cli.NewExitError(err.Error(), 3)
	}

	username := c.Args().First()
	if username == "" {
		cli.ShowCommandHelp(c, "set-admin")
		return cli.NewExitError("", 0)
	}

	isAdmin, err := strconv.ParseBool(c.Args().Get(1))
	if err != nil {
		cli.ShowCommandHelp(c, "set-admin")
		return cli.NewExitError("", 0)
	}

	if err := s.GetInterface().SetAdmin(username, isAdmin); err != nil {
		return cli.NewExitError(fmt.Sprintf("Error changing admin status of user '%s': %s", username, err), 3)
	}

	if isAdmin {
		return cli.NewExitError(fmt.Sprintf("user '%s' is now an admin!", username), 0)
	} else {
		return cli.NewExitError(fmt.Sprintf("user '%s' is now a normal user!", username), 0)
	}
}
开发者ID:whawty,项目名称:auth,代码行数:28,代码来源:main.go

示例13: cmdUpdate

func cmdUpdate(c *cli.Context) error {
	s, err := openAndCheck(c)
	if err != nil {
		return cli.NewExitError(err.Error(), 3)
	}

	username := c.Args().First()
	if username == "" {
		cli.ShowCommandHelp(c, "update")
		return cli.NewExitError("", 0)
	}

	password := c.Args().Get(1)
	if password == "" {
		pwd, err := askPass()
		if err != nil {
			if err != gopass.ErrInterrupted {
				return cli.NewExitError(err.Error(), 2)
			}
			return cli.NewExitError("", 2)
		}
		password = pwd
	}

	if err := s.GetInterface().Update(username, password); err != nil {
		return cli.NewExitError(fmt.Sprintf("Error updating user '%s': %s", username, err), 3)
	}
	return cli.NewExitError(fmt.Sprintf("user '%s' successfully updated!", username), 0)
}
开发者ID:whawty,项目名称:auth,代码行数:29,代码来源:main.go

示例14: cmdInit

func cmdInit(c *cli.Context) error {
	username := c.Args().First()
	if username == "" {
		cli.ShowCommandHelp(c, "init")
		return cli.NewExitError("", 0)
	}

	password := c.Args().Get(1)
	if password == "" {
		pwd, err := askPass()
		if err != nil {
			if err != gopass.ErrInterrupted {
				return cli.NewExitError(err.Error(), 2)
			}
			return cli.NewExitError("", 2)
		}
		password = pwd
	}

	s, err := NewStore(c.GlobalString("store"), c.GlobalString("do-upgrades"),
		c.GlobalString("policy-type"), c.GlobalString("policy-condition"), c.GlobalString("hooks-dir"))
	if err != nil {
		return cli.NewExitError(fmt.Sprintf("Error initializing whawty store: %s", err), 3)
	}
	if err := s.GetInterface().Init(username, password); err != nil {
		return cli.NewExitError(fmt.Sprintf("Error initializing whawty store: %s", err), 3)
	}
	return cli.NewExitError(fmt.Sprintf("whawty store successfully initialized!"), 0)
}
开发者ID:whawty,项目名称:auth,代码行数:29,代码来源:main.go

示例15: jobs_validate

func jobs_validate(c *cli.Context) error {
	var job_type scalecli.JobType
	err := Parse_json_or_yaml("job_type", &job_type)
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}

	url := c.GlobalString("url")
	if url == "" {
		return cli.NewExitError("A URL must be provided with the SCALE_URL environment variable or the --url argument", 1)
	}
	warnings, err := scalecli.ValidateJobType(url, job_type)
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}
	if warnings == "" {
		color.White("Job type specification is valid.")
	} else {
		color.Yellow(warnings)
	}
	return nil
}
开发者ID:ngageoint,项目名称:scale,代码行数:22,代码来源:jobs.go


注:本文中的github.com/codegangsta/cli.NewExitError函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。