Пример #1
0
func FindTaskId(index string, autoFirst bool, withProject bool) string {
	if index == "" {
		if autoFirst == false {
			log.Fatal("fatal: Task index is required.")
		} else {
			index = "0"
		}
	}

	var id string
	txt, err := ioutil.ReadFile(utils.CacheFile())

	if err != nil { // cache file not exist
		ind, parseErr := strconv.Atoi(index)
		utils.Check(parseErr)
		task := Tasks(url.Values{}, false, withProject)[ind]
		id = strconv.Itoa(task.Id)
	} else {
		lines := regexp.MustCompile("\n").Split(string(txt), -1)
		for i, line := range lines {
			if index == strconv.Itoa(i) {
				line = regexp.MustCompile("^[0-9]*:").ReplaceAllString(line, "") // remove index
				id = regexp.MustCompile("^[0-9]*").FindString(line)
			}
		}
	}
	return id
}
Пример #2
0
func Tasks(c *cli.Context, withProject bool) {
	if c.Bool("no-cache") {
		fromAPI(false, withProject)
	} else {
		if utils.Older(CacheDuration, utils.CacheFile()) || c.Bool("refresh") {
			fromAPI(true, withProject)
		} else {
			txt, err := ioutil.ReadFile(utils.CacheFile())
			if err == nil {
				lines := regexp.MustCompile("\n").Split(string(txt), -1)
				for _, line := range lines {
					if line != "" {
						format(line)
					}
				}
			} else {
				fromAPI(true, withProject)
			}
		}
	}
	if !withProject {
		ClearConfig()
	}
}
Пример #3
0
func cache(tasks []api.Task_t) {
	f, _ := os.Create(utils.CacheFile())
	defer f.Close()

	blue := ansi.ColorCode("blue")
	reset := ansi.ColorCode("reset")

	for i, t := range tasks {
		f.WriteString(strconv.Itoa(i) + ":")
		f.WriteString(strconv.Itoa(t.Id) + ":")
		f.WriteString(t.Due_on + ":")
		f.WriteString(t.Assignee.Name + ":")
		for _, p := range t.Projects {
			f.WriteString(blue + "#" + p.Name + " " + reset)
		}

		for _, ta := range t.Tags {
			f.WriteString(blue + "#" + ta.Name + " " + reset)
		}
		f.WriteString(t.Name + " ")
		f.WriteString("\n")
	}
}