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


Golang Settings.Default方法代码示例

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


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

示例1: DeleteBreadcrumb

// DeleteBreadcrumb removes the config file at LocalSettingsPath
func DeleteBreadcrumb(alias string, settings *models.Settings) {
	env := settings.Environments[alias]
	dir := env.Directory
	dir = filepath.Join(dir, ".git", LocalSettingsFile)
	defer os.Remove(dir)

	delete(settings.Environments, alias)
	if settings.Default == alias {
		settings.Default = ""
	}
	os.Remove(dir)
	SaveSettings(settings)
}
开发者ID:jkoelndorfer,项目名称:cli,代码行数:14,代码来源:settings.go

示例2: SetDefault

// SetDefault sets the default environment. This environment must already be
// associated. Any commands run outside of a git directory will use the default
// environment for context.
func SetDefault(alias string, settings *models.Settings) {
	var found bool
	for name := range settings.Environments {
		if name == alias {
			found = true
			break
		}
	}
	if !found {
		fmt.Printf("No environment with an alias of \"%s\" has been associated. Please run \"catalyze associate\" first\n", alias)
		os.Exit(1)
	}
	settings.Default = alias
	config.SaveSettings(settings)
	fmt.Printf("%s is now the default environment\n", alias)
}
开发者ID:jkoelndorfer,项目名称:cli,代码行数:19,代码来源:associate.go

示例3: Associate

// Associate an environment so that commands can be run against it. This command
// no longer adds a git remote. See commands.AddRemote().
func Associate(envLabel string, serviceLabel string, alias string, remote string, defaultEnv bool, settings *models.Settings) {
	if _, err := os.Stat(".git"); os.IsNotExist(err) {
		fmt.Println("Not git repo found in the current directory")
		os.Exit(1)
	}
	helpers.SignIn(settings)
	envs := helpers.ListEnvironments("pod", settings)
	for _, env := range *envs {
		if env.Data.Name == envLabel {
			if env.State == "defined" {
				fmt.Printf("Your environment is not yet provisioned. Please visit https://dashboard.catalyze.io/environments/update/%s to finish provisioning your environment\n", env.ID)
				return
			}
			// would be nice to have some sort of global filter() function
			var chosenService models.Service
			if serviceLabel != "" {
				labels := []string{}
				for _, service := range *env.Data.Services {
					if service.Type == "code" {
						labels = append(labels, service.Label)
						if service.Label == serviceLabel {
							chosenService = service
							break
						}
					}
				}
				if chosenService.Type == "" {
					fmt.Printf("No code service found with name '%s'. Code services found: %s\n", serviceLabel, strings.Join(labels, ", "))
					os.Exit(1)
				}
			} else {
				for _, service := range *env.Data.Services {
					if service.Type == "code" {
						chosenService = service
						break
					}
				}
				if chosenService.Type == "" {
					fmt.Printf("No code service found for \"%s\" environment (ID = %s)\n", envLabel, settings.EnvironmentID)
					os.Exit(1)
				}
			}
			for _, r := range helpers.ListGitRemote() {
				if r == remote {
					helpers.RemoveGitRemote(remote)
					break
				}
			}
			helpers.AddGitRemote(remote, chosenService.Source)
			fmt.Printf("\"%s\" remote added.\n", remote)
			dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
			if err != nil {
				panic(err)
			}
			name := alias
			if name == "" {
				name = envLabel
			}
			settings.Environments[name] = models.AssociatedEnv{
				EnvironmentID: env.ID,
				ServiceID:     chosenService.ID,
				Directory:     dir,
				Name:          envLabel,
			}
			if defaultEnv {
				settings.Default = name
			}
			config.DropBreadcrumb(name, settings)
			config.SaveSettings(settings)
			if len(settings.Environments) > 1 && settings.Default == "" {
				fmt.Printf("You now have %d environments associated. Consider running \"catalyze default ENV_NAME\" to set a default\n", len(settings.Environments))
			}
			return
		}
	}
	fmt.Printf("No environment with label \"%s\" found\n", envLabel)
	os.Exit(1)
}
开发者ID:jkoelndorfer,项目名称:cli,代码行数:80,代码来源:associate.go


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