Esempio n. 1
0
func Config(c *cli.Context) {
	_, err := ioutil.ReadFile(utils.Home() + "/.asana.yml")
	if err != nil || config.Load().Api_key == "" {
		println("visit: http://app.asana.com/-/account_api")
		print("paste your api_key: ")
		var s string
		fmt.Scanf("%s", &s)

		f, _ := os.Create(utils.Home() + "/.asana.yml")
		defer f.Close()
		f.WriteString("api_key: " + s + "\n")
	}

	ws := api.Me().Workspaces
	index := 0

	cyan := ansi.ColorCode("cyan")
	reset := ansi.ColorCode("reset")
	if len(ws) > 1 {
		fmt.Println("\n" + strconv.Itoa(len(ws)) + " workspaces found.")
		for i, w := range ws {
			fmt.Printf("%s[%d]%s %s\n", cyan, i, reset, w.Name)
		}
		index = utils.EndlessSelect(len(ws)-1, index)
	}
	apiKey := config.Load().Api_key
	f, _ := os.Create(utils.Home() + "/.asana.yml")
	f.WriteString("api_key: " + apiKey + "\n")
	f.WriteString("workspace: " + strconv.Itoa(ws[index].Id) + "\n")
}
Esempio n. 2
0
func Projects(c *cli.Context) {
	projects := api.Projects()
	index := 0
	cyan := ansi.ColorCode("cyan")
	reset := ansi.ColorCode("reset")
	if len(projects) > 0 {
		fmt.Println("\n" + strconv.Itoa(len(projects)) + " projects found.")
		for i, p := range projects {
			fmt.Printf("%s[%2d]%s %s\n", cyan, i, reset, p.Name)
		}
		index = utils.EndlessSelect(len(projects)-1, index)
	}

	workspace := config.Load().Workspace
	apiKey := config.Load().Api_key
	proj := strconv.Itoa(projects[index].Id)

	f, _ := os.Create(utils.Home() + "/.asana.yml")
	f.WriteString("api_key: " + apiKey + "\n")
	f.WriteString("workspace: " + strconv.Itoa(workspace) + "\n")
	f.WriteString("project: " + proj + "\n")
}