Exemple #1
0
package commands

import (
	"fmt"
	"os"

	"github.com/bryanl/doit/Godeps/_workspace/src/github.com/fatih/color"
	"github.com/bryanl/doit/Godeps/_workspace/src/github.com/spf13/cobra"
)

var (
	colorErr = color.New(color.FgRed).SprintFunc()("Error")
)

func checkErr(err error, cmd ...*cobra.Command) {
	if err == nil {
		return
	}

	if len(cmd) > 0 {
		cmd[0].Help()
	}

	fmt.Fprintf(color.Output, "\n%s: %v\n", colorErr, err)
	os.Exit(1)
}
Exemple #2
0
	configFile = ".doitcfg"
)

var (
	// DoitCmd is the base command.
	DoitCmd = &cobra.Command{
		Use: "doit",
	}

	// Token holds the global authorization token.
	Token string

	// Output holds the global output format.
	Output string

	requiredColor = color.New(color.Bold, color.FgWhite).SprintfFunc()

	writer = os.Stdout
)

func init() {
	viper.SetConfigType("yaml")

	DoitCmd.PersistentFlags().StringVarP(&Token, "access-token", "t", "", "DigtialOcean API V2 Access Token")
	DoitCmd.PersistentFlags().StringVarP(&Output, "output", "o", "text", "output formt [text|json]")
}

// LoadConfig loads out configuration.
func LoadConfig() error {
	fp, err := configFilePath()
	if err != nil {