本文整理汇总了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)
}
}
示例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)
}
}
示例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)
}
}
示例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()
}
示例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))
}
}
示例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
}
示例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)
}
示例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")
}
}
}
示例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")
}
}
}
示例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()
}
示例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.")
}
示例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
}
示例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
}
示例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
}
示例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)
}