Exemplo n.º 1
0
func readDropBoxAppConfig(appName string) (*DropBoxAppConfig, error) {
	s := scan.CliScan{
		Scans: []scan.Scan{
			{Name: "token",
				Value: "",
				Usage: "please your dropbox accessToken",
				Env:   "",
			},
		},
	}

	ac := appConfig.NewDefaultAppConfig(appName)
	data, err := ac.ReadAppConfig()
	accessToken := string(data)
	if err != nil || accessToken == "" {

		// OAuth jump
		open.Run(accessTokenURL)

		// Scan accessToken
		accessToken = s.Scan("token")

		// config write
		if err := ac.WriteAppConfig([]byte(accessToken)); err != nil {
			return nil, err
		}
	}

	return &DropBoxAppConfig{*ac}, nil
}
Exemplo n.º 2
0
Arquivo: main.go Projeto: kyokomi/scan
func main() {
	c := scan.CliScan{Scans: []scan.Scan{
		{
			Name:  "hoge",
			Value: "fuga",
			Usage: "input pleese [hoge or fuga]",
			Env:   "HOGE",
		},
	}}

	fmt.Println(c.Get("hoge"))

	if err := os.Setenv("HOGE", "test"); err != nil {
		log.Fatalln(err)
	}
	c.Reset("hoge")

	fmt.Println(c.Get("hoge"))
	fmt.Println("scan => ", c.Scan("hoge"))
	fmt.Println(c.Get("hoge"))
}