示例#1
0
// 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
}