當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。