clitask

package module
v0.0.0-...-4b2da47 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2022 License: GPL-3.0 Imports: 9 Imported by: 0

README

CLI Task Manager

Exercise details

In this exercise we are going to be building a CLI tool that can be used to manage your TODOs in the terminal. The basic usage of the tool is going to look roughly like this:

$ task
task is a CLI for managing your TODOs.

Usage:
  task [command]

Available Commands:
  add         Add a new task to your TODO list
  do          Mark a task on your TODO list as complete
  list        List all of your incomplete tasks

Use "task [command] --help" for more information about a command.

$ task add review talk proposal
Added "review talk proposal" to your task list.

$ task add clean dishes
Added "clean dishes" to your task list.

$ task list
You have the following tasks:
1. review talk proposal
2. some task description

$ task do 1
You have completed the "review talk proposal" task.

$ task list
You have the following tasks:
1. some task description

Note: Lines prefixed with $ are lines where we type into the terminal, and other lines are output from our program.

1. Build the CLI shell

Your final CLI won't need to look exactly like this, but this is what I roughly expect mine to look like. In the bonus section we will also discuss a few extra features we could add, but for now we will stick with the three show above:

  • add - adds a new task to our list
  • list - lists all of our incomplete tasks
  • do - marks a task as complete
2. Write the BoltDB interactions

After stubbing out your CLI commands, try writing code that will read, add, and delete data in a BoltDB database. You can find more information about using Bolt here: https://github.com/etcd-io/bbolt

For now, don't worry about where you store the database that bolt connects to. At this stage I intend to just use whatever directory the task command was run from, so I will be using code roughly like this:

db, err := bolt.Open("tasks.db", 0600, nil)

Later you can dig into how to install the application so that it can be run from anywhere and it will persist our tasks regardless of where we run the CLI.

Documentation

Index

Constants

View Source
const (
	EmptyBacklog string = "your backlog is empty.\n"
	Greeting     string = "$ "
)
View Source
const HelpMsg string = `` /* 304-byte string literal not displayed */

Variables

View Source
var ErrIncorrectId = errors.New("incorrect task id. id must be positibe integer value.")
View Source
var ErrUnexpectedId = errors.New("task id must be greater than zero.")
View Source
var ErrUnknownCmd = errors.New("unsupported command.")

Functions

func Itob

func Itob(v int) []byte

itob returns an 8-byte big endian representation of v.

Types

type DbStore

type DbStore struct {
	DbFile string
	Bucket string
}

func NewDbStore

func NewDbStore(dbFile, bucket string) *DbStore

func (*DbStore) Add

func (s *DbStore) Add(taskMsg string) error

func (*DbStore) Do

func (s *DbStore) Do(id int) (Task, error)

func (*DbStore) ToDo

func (s *DbStore) ToDo() ([]Task, error)

func (*DbStore) Update

func (s *DbStore) Update(task Task) error

type Manager

type Manager struct {
	// reader for output data
	Input io.Reader
	// command result writer
	Output io.Writer
	Store  Storer
}

func NewManager

func NewManager(in io.Reader, out io.Writer, store Storer) *Manager

func (*Manager) Work

func (m *Manager) Work() error

type MemStore

type MemStore struct {
	Todo []Task
	Done []Task
}

func NewMemStore

func NewMemStore() *MemStore

func (*MemStore) Add

func (s *MemStore) Add(task string) error

func (*MemStore) AllTasks

func (s *MemStore) AllTasks() []Task

func (*MemStore) Completed

func (s *MemStore) Completed() []Task

func (*MemStore) Do

func (s *MemStore) Do(id int) (Task, error)

func (*MemStore) ToDo

func (s *MemStore) ToDo() ([]Task, error)

type Storer

type Storer interface {
	ToDo() ([]Task, error)
	Add(string) error
	Do(int) (Task, error)
}

type Task

type Task struct {
	Id   int
	Name string
	Done bool
}

func (Task) String

func (t Task) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL