Exemplo n.º 1
0
func main() {
	var shouldInit bool
	var flagTags string
	var priority = workspace.PriorityNormal.String()

	flag.Usage = usage
	flag.BoolVar(&shouldInit, "i", false, "Initialise new workspace if needed.")
	flag.StringVar(&priority, "p", priority, "Specify the priority for new tasks.")
	flag.StringVar(&flagTags, "t", "", "Specify tags to be applied to new tasks.")
	flag.Parse()

	if flag.NArg() == 0 {
		usage()
		return
	}

	pri := workspace.PriorityFromString(priority)
	if pri == workspace.PriorityUnknown {
		usage()
		os.Exit(1)
	}

	tags := workspace.Tokenize(flagTags, ",")

	ws, err := workspace.ReadFile(flag.Arg(0), shouldInit)
	die.If(err)

	entryID := ws.NewEntry()
	entry := ws.Entries[entryID]

	for {
		tasks := ws.EntryTasks(entryID).Sort()
		fmt.Printf("TODO %s (%d tasks):\n",
			workspace.Today().Format(workspace.DateFormat),
			len(tasks))
		for _, task := range tasks {
			fmt.Println(task)
		}

		fmt.Printf("New task: ")
		line := readline()
		if line == "" {
			break
		}

		id := workspace.NewTaskID()
		task := workspace.NewTask(id, line)
		task.Priority = pri
		entry.Tasks = append(entry.Tasks, id)
		ws.Tasks[id] = task
		ws.Entries[entryID] = entry

		for i := range tags {
			ws.Tag(task.ID, tags[i])
		}

		err = workspace.WriteFile(ws)
		die.If(err)
	}
}
Exemplo n.º 2
0
func readPriority() workspace.Priority {
	for {
		fmt.Printf("Priority: ")
		line := readline()
		if line == "" {
			os.Exit(0)
		}
		pri := workspace.PriorityFromString(line)
		if pri == workspace.PriorityUnknown {
			fmt.Println("Invalid priority.")
			fmt.Println(workspace.PriorityStrings)
			continue
		}

		return pri
	}
}