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


Golang util.Settings类代码示例

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


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

示例1: guessProjectURL

func guessProjectURL(c util.Settings, e *util.Environment) string {
	target, _ := c.String("target")
	if !looksLikeURL(target) {
		return ""
	}
	return target
}
开发者ID:umcodemonkey,项目名称:wercker,代码行数:7,代码来源:options.go

示例2: guessApplicationName

// Some logic to guess the application name
func guessApplicationName(c util.Settings, e *util.Environment) (string, error) {
	applicationName, _ := c.String("application-name")
	if applicationName != "" {
		return applicationName, nil
	}

	// Otherwise, check our build target, it can be a url...
	target, _ := c.String("target")
	projectURL := ""
	if strings.HasPrefix(target, "http://") || strings.HasPrefix(target, "https://") {
		projectURL = target
		base := path.Base(projectURL)
		// Special handling for github tarballs
		if base == "tarball" {
			base = path.Base(path.Dir(projectURL))
		}
		ext := path.Ext(base)
		base = base[:len(ext)]
		return base, nil
	}

	// ... or a file path
	if target == "" {
		target = "."
	}
	stat, err := os.Stat(target)
	if err != nil || !stat.IsDir() {
		return "", fmt.Errorf("target '%s' is not a directory", target)
	}
	abspath, err := filepath.Abs(target)
	if err != nil {
		return "", err
	}
	return filepath.Base(abspath), nil
}
开发者ID:umcodemonkey,项目名称:wercker,代码行数:36,代码来源:options.go

示例3: guessGitCommit

func guessGitCommit(c util.Settings, e *util.Environment) string {
	commit, _ := c.String("git-commit")
	if commit != "" {
		return commit
	}

	projectPath := guessProjectPath(c, e)
	if projectPath == "" {
		return ""
	}
	cwd, err := os.Getwd()
	if err != nil {
		return ""
	}
	defer os.Chdir(cwd)
	os.Chdir(projectPath)

	git, err := exec.LookPath("git")
	if err != nil {
		return ""
	}

	var out bytes.Buffer
	cmd := exec.Command(git, "rev-parse", "HEAD")
	cmd.Stdout = &out
	err = cmd.Run()
	if err != nil {
		return ""
	}
	return strings.Trim(out.String(), "\n")
}
开发者ID:umcodemonkey,项目名称:wercker,代码行数:31,代码来源:options.go

示例4: NewGlobalOptions

// NewGlobalOptions constructor
func NewGlobalOptions(c util.Settings, e *util.Environment) (*GlobalOptions, error) {
	baseURL, _ := c.GlobalString("base-url", DEFAULT_BASE_URL)
	baseURL = strings.TrimRight(baseURL, "/")
	debug, _ := c.GlobalBool("debug")
	journal, _ := c.GlobalBool("journal")
	verbose, _ := c.GlobalBool("verbose")
	// TODO(termie): switch negative flag
	showColors, _ := c.GlobalBool("no-colors")
	showColors = !showColors

	authTokenStore, _ := c.GlobalString("auth-token-store")
	authTokenStore = util.ExpandHomePath(authTokenStore, e.Get("HOME"))
	authToken := guessAuthToken(c, e, authTokenStore)

	// If debug is true, than force verbose and do not use colors.
	if debug {
		verbose = true
		showColors = false
	}

	return &GlobalOptions{
		BaseURL:    baseURL,
		Debug:      debug,
		Journal:    journal,
		Verbose:    verbose,
		ShowColors: showColors,

		AuthToken:      authToken,
		AuthTokenStore: authTokenStore,
	}, nil
}
开发者ID:umcodemonkey,项目名称:wercker,代码行数:32,代码来源:options.go

示例5: guessApplicationID

func guessApplicationID(c util.Settings, e *util.Environment, name string) string {
	id, _ := c.String("application-id")
	if id == "" {
		id = name
	}
	return id
}
开发者ID:umcodemonkey,项目名称:wercker,代码行数:7,代码来源:options.go

示例6: NewDeployOptions

// NewDeployOptions constructor
func NewDeployOptions(c util.Settings, e *util.Environment) (*PipelineOptions, error) {
	pipelineOpts, err := NewPipelineOptions(c, e)
	if err != nil {
		return nil, err
	}
	// default to last build output if none defined
	target, _ := c.String("target")
	if target == "" {
		found, err := util.Exists("./.wercker/latest/output")
		if err == nil && found {
			util.RootLogger().Println("No target specified, using recent build output.")
			pipelineOpts.ProjectPath, _ = filepath.Abs("./.wercker/latest/output")
		}
	}

	// if the deploy target path does not have a wercker.yml, use the current one
	werckerYml, _ := c.String("wercker-yml")
	if werckerYml == "" {
		found, _ := util.Exists(filepath.Join(pipelineOpts.ProjectPath, "wercker.yml"))
		if !found {
			pipelineOpts.WerckerYml = "./wercker.yml"
		}
	}

	if pipelineOpts.RunID == "" {
		pipelineOpts.RunID = uuid.NewRandom().String()
	}
	return pipelineOpts, nil
}
开发者ID:wercker,项目名称:wercker,代码行数:30,代码来源:options.go

示例7: guessTag

func guessTag(c util.Settings, e *util.Environment) string {
	tag, _ := c.String("tag")
	if tag == "" {
		tag = guessGitBranch(c, e)
	}
	tag = strings.Replace(tag, "/", "_", -1)
	return tag
}
开发者ID:umcodemonkey,项目名称:wercker,代码行数:8,代码来源:options.go

示例8: guessProjectID

func guessProjectID(c util.Settings, e *util.Environment) string {
	projectID, _ := c.String("project-id")
	if projectID != "" {
		return projectID
	}

	// If this was going to fail it already failed and we exited
	name, _ := guessApplicationName(c, e)
	return name
}
开发者ID:umcodemonkey,项目名称:wercker,代码行数:10,代码来源:options.go

示例9: guessGitRepository

func guessGitRepository(c util.Settings, e *util.Environment) string {
	repository, _ := c.String("git-repository")
	if repository != "" {
		return repository
	}
	// repository, err := guessApplicationName(c, env)
	// if err != nil {
	//   return ""
	// }
	return repository
}
开发者ID:umcodemonkey,项目名称:wercker,代码行数:11,代码来源:options.go

示例10: NewVersionOptions

// NewVersionOptions constructor
func NewVersionOptions(c util.Settings, e *util.Environment) (*VersionOptions, error) {
	json, _ := c.Bool("json")
	beta, _ := c.Bool("beta")
	noUpdateCheck, _ := c.Bool("no-update-check")

	return &VersionOptions{
		OutputJSON:     json,
		BetaChannel:    beta,
		CheckForUpdate: !noUpdateCheck,
	}, nil
}
开发者ID:umcodemonkey,项目名称:wercker,代码行数:12,代码来源:options.go

示例11: guessProjectPath

func guessProjectPath(c util.Settings, e *util.Environment) string {
	target, _ := c.String("target")
	if looksLikeURL(target) {
		return ""
	}
	if target == "" {
		target = "."
	}
	abs, _ := filepath.Abs(target)
	return abs
}
开发者ID:umcodemonkey,项目名称:wercker,代码行数:11,代码来源:options.go

示例12: guessGitOwner

func guessGitOwner(c util.Settings, e *util.Environment) string {
	owner, _ := c.String("git-owner")
	if owner != "" {
		return owner
	}

	u, err := user.Current()
	if err == nil {
		owner = u.Username
	}
	return owner
}
开发者ID:umcodemonkey,项目名称:wercker,代码行数:12,代码来源:options.go

示例13: guessApplicationOwnerName

func guessApplicationOwnerName(c util.Settings, e *util.Environment) string {
	name, _ := c.String("application-owner-name")
	if name == "" {
		u, err := user.Current()
		if err == nil {
			name = u.Username
		}
	}
	if name == "" {
		name = "wercker"
	}
	return name
}
开发者ID:umcodemonkey,项目名称:wercker,代码行数:13,代码来源:options.go

示例14: guessAuthToken

// guessAuthToken will attempt to read from the token store location if
// no auth token was provided
func guessAuthToken(c util.Settings, e *util.Environment, authTokenStore string) string {
	token, _ := c.GlobalString("auth-token")
	if token != "" {
		return token
	}
	if foundToken, _ := util.Exists(authTokenStore); !foundToken {
		return ""
	}

	tokenBytes, err := ioutil.ReadFile(authTokenStore)
	if err != nil {
		util.RootLogger().WithField("Logger", "Options").Errorln(err)
		return ""
	}
	return strings.TrimSpace(string(tokenBytes))
}
开发者ID:umcodemonkey,项目名称:wercker,代码行数:18,代码来源:options.go

示例15: NewGitOptions

// NewGitOptions constructor
func NewGitOptions(c util.Settings, e *util.Environment, globalOpts *GlobalOptions) (*GitOptions, error) {
	gitBranch := guessGitBranch(c, e)
	gitCommit := guessGitCommit(c, e)
	gitDomain, _ := c.String("git-domain")
	gitOwner := guessGitOwner(c, e)
	gitRepository := guessGitRepository(c, e)

	return &GitOptions{
		GlobalOptions: globalOpts,
		GitBranch:     gitBranch,
		GitCommit:     gitCommit,
		GitDomain:     gitDomain,
		GitOwner:      gitOwner,
		GitRepository: gitRepository,
	}, nil
}
开发者ID:umcodemonkey,项目名称:wercker,代码行数:17,代码来源:options.go


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