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


Golang Context.IsSet方法代码示例

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


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

示例1: parseOptions

func parseOptions(c *cli.Context) {
	port = strconv.Itoa(c.Int("port"))

	if c.IsSet("config") {
		configFile = c.String("config")
	}
	config, err := readConfigurationFile(configFile)
	if err != nil {
		log.Fatalf("Could not read configuration file: %v", err)
		return
	}

	if c.IsSet("file") {
		// overwrite configuration file setting for todo.txt file, if given as commandline parameter
		config.TodoTxtFilename = c.String("file")
		if err := config.writeConfigurationFile(configFile); err != nil {
			log.Fatalf("Could not update configuration file: %v", err)
		}
	}

	// check if file actually exists, otherwise create new file
	if err := checkAndCreateFile(config.TodoTxtFilename); err != nil {
		log.Fatal(err)
	}
}
开发者ID:JamesClonk,项目名称:todoapp,代码行数:25,代码来源:todoapp.go

示例2: add

func add(c *cli.Context) {
	log.Debugln("[ENVMAN] - Work path:", envman.CurrentEnvStoreFilePath)

	key := c.String(KeyKey)
	expand := !c.Bool(NoExpandKey)
	replace := !c.Bool(AppendKey)

	var value string
	if stdinValue != "" {
		value = stdinValue
	} else if c.IsSet(ValueKey) {
		value = c.String(ValueKey)
	} else if c.String(ValueFileKey) != "" {
		if v, err := loadValueFromFile(c.String(ValueFileKey)); err != nil {
			log.Fatal("[ENVMAN] - Failed to read file value: ", err)
		} else {
			value = v
		}
	}

	if err := addEnv(key, value, expand, replace); err != nil {
		log.Fatal("[ENVMAN] - Failed to add env:", err)
	}

	log.Debugln("[ENVMAN] - Env added")

	if err := logEnvs(); err != nil {
		log.Fatal("[ENVMAN] - Failed to print:", err)
	}
}
开发者ID:bazscsa,项目名称:envman,代码行数:30,代码来源:add.go

示例3: runUpdate

func runUpdate(c *cli.Context) {
	if c.IsSet("config") {
		setting.CustomConf = c.String("config")
	}

	setup("update.log")

	if len(os.Getenv("SSH_ORIGINAL_COMMAND")) == 0 {
		log.GitLogger.Trace("SSH_ORIGINAL_COMMAND is empty")
		return
	}

	args := c.Args()
	if len(args) != 3 {
		log.GitLogger.Fatal(2, "Arguments received are not equal to three")
	} else if len(args[0]) == 0 {
		log.GitLogger.Fatal(2, "First argument 'refName' is empty, shouldn't use")
	}

	task := models.UpdateTask{
		UUID:        os.Getenv("uuid"),
		RefName:     args[0],
		OldCommitID: args[1],
		NewCommitID: args[2],
	}

	if err := models.AddUpdateTask(&task); err != nil {
		log.GitLogger.Fatal(2, "AddUpdateTask: %v", err)
	}
}
开发者ID:sillydong,项目名称:gogs,代码行数:30,代码来源:update.go

示例4: cmdCreate

func cmdCreate(c *cli.Context) {
	utils.FlagsRequired(c, []string{"name", "description", "code"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	v := make(map[string]string)

	v["name"] = c.String("name")
	v["description"] = c.String("description")
	v["code"] = c.String("code")
	if c.IsSet("parameters") {
		v["parameters"] = c.String("parameters")
	}

	jsonBytes, err := json.Marshal(v)
	utils.CheckError(err)
	err, res, code := webservice.Post("/v1/blueprint/scripts", jsonBytes)
	if res == nil {
		log.Fatal(err)
	}
	utils.CheckError(err)
	utils.CheckReturnCode(code, res)

	var new_script Script
	err = json.Unmarshal(res, &new_script)
	utils.CheckError(err)
	w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
	fmt.Fprintln(w, "ID\tNAME\tDESCRIPTION\tCODE\tPARAMETERS\r")
	fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", new_script.Id, new_script.Name, new_script.Description, new_script.Code, new_script.Parameters)

	w.Flush()

}
开发者ID:odacremolbap,项目名称:concerto,代码行数:33,代码来源:scripts.go

示例5: list

func list(c *cli.Context) {
	var (
		err error
	)

	hosts := c.StringSlice("host")
	if c.IsSet("host") || c.IsSet("H") {
		hosts = hosts[1:]
	}

	client, err := proton.GetRaftClient(hosts[0], 2*time.Second)
	if err != nil {
		log.Fatal("couldn't initialize client connection")
	}

	resp, err := client.ListObjects(context.TODO(), &proton.ListObjectsRequest{})
	if err != nil {
		log.Fatal("Can't list objects in the cluster")
	}

	fmt.Println("Keys:")

	for _, obj := range resp.Objects {
		fmt.Println(":", obj.Key, ":", string(obj.Value))
	}
}
开发者ID:abronan,项目名称:proton,代码行数:26,代码来源:list.go

示例6: getRequiredOption

func getRequiredOption(ctx *cli.Context, flag string) string {
	option := ctx.String(flag)
	if !ctx.IsSet(flag) || strings.TrimSpace(option) == "" {
		exitOnError(fmt.Errorf("--%s option is required", flag))
	}
	return option
}
开发者ID:1and1,项目名称:oneandone-cloudserver-cli,代码行数:7,代码来源:main.go

示例7: cmdRackScale

func cmdRackScale(c *cli.Context) {
	count := 0
	typ := ""

	if c.IsSet("count") {
		count = c.Int("count")
	}

	if c.IsSet("type") {
		typ = c.String("type")
	}

	system, err := rackClient(c).ScaleSystem(count, typ)

	if err != nil {
		stdcli.Error(err)
		return
	}

	fmt.Printf("Name     %s\n", system.Name)
	fmt.Printf("Status   %s\n", system.Status)
	fmt.Printf("Version  %s\n", system.Version)
	fmt.Printf("Count    %d\n", system.Count)
	fmt.Printf("Type     %s\n", system.Type)
}
开发者ID:nicolas-brousse,项目名称:rack,代码行数:25,代码来源:rack.go

示例8: httpapiConfFromFlags

func httpapiConfFromFlags(c *cli.Context) func(*dagger.HttpAPIConfig) {
	return func(conf *dagger.HttpAPIConfig) {
		if c.IsSet("api-port") {
			conf.Port = c.String("api-port")
		}
	}
}
开发者ID:nsaje,项目名称:dagger,代码行数:7,代码来源:config.go

示例9: persisterConfFromFlags

func persisterConfFromFlags(c *cli.Context) func(*dagger.PersisterConfig) {
	return func(conf *dagger.PersisterConfig) {
		if c.IsSet("data-dir") {
			conf.Dir = c.String("data-dir")
		}
	}
}
开发者ID:nsaje,项目名称:dagger,代码行数:7,代码来源:config.go

示例10: cmdUpdate

func cmdUpdate(c *cli.Context) {
	utils.FlagsRequired(c, []string{"id"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	v := make(map[string]string)

	if c.IsSet("name") {
		v["name"] = c.String("name")
	}
	if c.IsSet("fqdn") {
		v["fqdn"] = c.String("fqdn")
	}

	jsonBytes, err := json.Marshal(v)
	utils.CheckError(err)
	err, res, code := webservice.Put(fmt.Sprintf("/v1/cloud/servers/%s", c.String("id")), jsonBytes)
	utils.CheckError(err)
	utils.CheckReturnCode(code, res)

	var server Server
	err = json.Unmarshal(res, &server)
	utils.CheckError(err)

	w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
	fmt.Fprintln(w, "ID\tNAME\tFQDN\tSTATE\tPUBLIC IP\tWORKSPACE ID\tTEMPLATE ID\tSERVER PLAN ID\tSSH PROFILE ID\r")
	fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", server.Id, server.Name, server.Fqdn, server.State, server.Public_ip, server.Workspace_id, server.Template_id, server.Server_plan_id, server.Ssh_profile_id)

	w.Flush()
}
开发者ID:odacremolbap,项目名称:concerto,代码行数:30,代码来源:servers.go

示例11: keypairsCreateCmd

func keypairsCreateCmd(c *CLI, ctx *cli.Context) {
	usage := func(msg string) {
		fmt.Printf("Usage: %s keypairs create --name=<keypair-name> <private-key-path> <certificate-path>\n", c.Name)
		fatal(msg)
	}
	if len(ctx.Args()) < 2 {
		usage("too few arguments")
	}
	if !ctx.IsSet("name") || ctx.String("name") == "" {
		usage("--name is required")
	}
	api := c.GetAPIClient(ctx)
	resourceGroup := c.GetResourceGroup(ctx)
	name := ctx.String("name")
	privateKeyPath := ctx.Args()[0]
	certPath := ctx.Args()[1]
	privateKey, err := ioutil.ReadFile(privateKeyPath)
	if err != nil {
		fatal(err.Error())
	}
	cert, err := ioutil.ReadFile(certPath)
	if err != nil {
		fatal(err.Error())
	}
	keypair := gondor.KeyPair{
		ResourceGroup: resourceGroup.URL,
		Name:          &name,
		Key:           privateKey,
		Certificate:   cert,
	}
	if err := api.KeyPairs.Create(&keypair); err != nil {
		fatal(err.Error())
	}
	success("keypair created.")
}
开发者ID:eldarion-gondor,项目名称:gondor,代码行数:35,代码来源:keypairs.go

示例12: configfile

func configfile(c *cli.Context, have map[string]authCred, need map[string]string) error {
	dir, err := util.RackDir()
	if err != nil {
		// return fmt.Errorf("Error retrieving rack directory: %s\n", err)
		return nil
	}
	f := path.Join(dir, "config")
	cfg, err := ini.Load(f)
	if err != nil {
		// return fmt.Errorf("Error loading config file: %s\n", err)
		return nil
	}
	cfg.BlockMode = false
	var profile string
	if c.GlobalIsSet("profile") {
		profile = c.GlobalString("profile")
	} else if c.IsSet("profile") {
		profile = c.String("profile")
	}
	section, err := cfg.GetSection(profile)
	if err != nil && profile != "" {
		return fmt.Errorf("Invalid config file profile: %s\n", profile)
	}

	for opt := range need {
		if val := section.Key(opt).String(); val != "" {
			have[opt] = authCred{value: val, from: fmt.Sprintf("config file (profile: %s)", section.Name())}
			delete(need, opt)
		}
	}
	return nil
}
开发者ID:flazz,项目名称:rack,代码行数:32,代码来源:configfile.go

示例13: SetParam

func (r *Request) SetParam(c *cli.Context) error {
	p := &r.Params
	if len(c.String("email")) != 0 {
		p.Email = c.String("email")
	}

	if len(c.String("password")) != 0 {
		p.Password = c.String("password")
	}

	if c.IsSet("token-timeout-seconds") {
		p.TokenTimeoutSeconds = c.Int("token-timeout-seconds")
	} else {
		p.TokenTimeoutSeconds = 86400
	}

	if len(c.String("token")) != 0 {
		p.OneTimeToken = c.String("token")
	}

	if len(c.String("new-password")) != 0 {
		p.NewPassword = c.String("new-password")
	}

	if len(c.String("verify-token")) != 0 {
		p.VerifyToken = c.String("verify-token")
	}

	return nil
}
开发者ID:futoase,项目名称:soracom-go,代码行数:30,代码来源:param.go

示例14: initClient

func initClient(c *cli.Context) error {
	configFile := c.String("config_file")
	var config *gitkit.Config
	var err error
	if configFile != "" {
		config, err = gitkit.LoadConfig(configFile)
		if err != nil {
			return err
		}
	} else {
		config = &gitkit.Config{}
	}
	// It is required but not used.
	config.WidgetURL = "http://localhost"
	// Command line flags overwrite the values in config file.
	if c.IsSet("client_id") {
		config.ClientID = c.String("client_id")
	}
	if c.IsSet("google_app_credentials_path") {
		config.GoogleAppCredentialsPath = c.String("google_app_credentials_path")
	}

	if client, err = gitkit.New(context.Background(), config); err != nil {
		return err
	}
	return nil
}
开发者ID:vasistbhargav,项目名称:identity-toolkit-go,代码行数:27,代码来源:gitkitcli.go

示例15: renew

func renew(c *cli.Context) {
	conf, _, client := setup(c)

	if len(c.GlobalStringSlice("domains")) <= 0 {
		logger().Fatal("Please specify at least one domain.")
	}

	domain := c.GlobalStringSlice("domains")[0]

	// load the cert resource from files.
	// We store the certificate, private key and metadata in different files
	// as web servers would not be able to work with a combined file.
	certPath := path.Join(conf.CertPath(), domain+".crt")
	privPath := path.Join(conf.CertPath(), domain+".key")
	metaPath := path.Join(conf.CertPath(), domain+".json")

	certBytes, err := ioutil.ReadFile(certPath)
	if err != nil {
		logger().Fatalf("Error while loading the certificate for domain %s\n\t%s", domain, err.Error())
	}

	if c.IsSet("days") {
		expTime, err := acme.GetPEMCertExpiration(certBytes)
		if err != nil {
			logger().Printf("Could not get Certification expiration for domain %s", domain)
		}

		if int(expTime.Sub(time.Now()).Hours()/24.0) > c.Int("days") {
			return
		}
	}

	metaBytes, err := ioutil.ReadFile(metaPath)
	if err != nil {
		logger().Fatalf("Error while loading the meta data for domain %s\n\t%s", domain, err.Error())
	}

	var certRes acme.CertificateResource
	err = json.Unmarshal(metaBytes, &certRes)
	if err != nil {
		logger().Fatalf("Error while marshalling the meta data for domain %s\n\t%s", domain, err.Error())
	}

	if c.Bool("reuse-key") {
		keyBytes, err := ioutil.ReadFile(privPath)
		if err != nil {
			logger().Fatalf("Error while loading the private key for domain %s\n\t%s", domain, err.Error())
		}
		certRes.PrivateKey = keyBytes
	}

	certRes.Certificate = certBytes

	newCert, err := client.RenewCertificate(certRes, true)
	if err != nil {
		logger().Fatalf("%s", err.Error())
	}

	saveCertRes(newCert, conf)
}
开发者ID:willglynn,项目名称:lego,代码行数:60,代码来源:cli_handlers.go


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