Skip to content

Commit

Permalink
Merge pull request #4 from briandowns/change_weight_to_priority
Browse files Browse the repository at this point in the history
Change weight to priority
  • Loading branch information
briandowns committed May 16, 2016
2 parents 9069508 + 2aa22b2 commit 7859f11
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 54 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Example:
TODO(briandowns) this is an example todo format 2016-05-13T18:54 4
```

## Weighting
## Priorities

```sh
todo-view weights:
todo-view priorities:

1 Extremely important
2 Somewhat important
Expand All @@ -29,7 +29,7 @@ todo-view weights:
* User
* File
* Timestamp
* Weight
* Priority

## Usage

Expand Down
4 changes: 2 additions & 2 deletions command/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (e *Export) csv() {
}
for _, todo := range todos {
fmt.Fprintf(os.Stdout, "%s,%s,%s,%v,%d\n",
todo.User(), todo.File(), todo.Message(), todo.Timestamp(), todo.Weight())
todo.User(), todo.File(), todo.Message(), todo.Timestamp(), todo.Priority())
}
}

Expand Down Expand Up @@ -110,6 +110,6 @@ func (e *Export) jira() {
fmt.Fprintln(os.Stdout, "Summary,Assignee,Reporter,Priority")
for _, todo := range todos {
fmt.Fprintf(os.Stdout, "%s,%s,%s,%d\n",
todo.Message(), todo.User(), todo.User(), todo.Weight())
todo.Message(), todo.User(), todo.User(), todo.Priority())
}
}
44 changes: 22 additions & 22 deletions command/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ type Parser interface {
byUser()
byFile()
byDate()
byWeight()
byPriority()
}

// regex holds the pattern necessary to match the todo in the
// files parsed
var regex = regexp.MustCompile(`TODO\((?P<user>[a-z].+)\)(?P<msg>.+)(?P<timestamp>\d\d\d\d\D?\d\d\D?\d\d\D?\d\d\D?\d\d\D?(\d\d\.?(\d*))?(\d\d(:\d\d)?)?).(?P<weight>\d)`)
var regex = regexp.MustCompile(`TODO\((?P<user>[a-z].+)\)(?P<msg>.+)(?P<timestamp>\d\d\d\d\D?\d\d\D?\d\d\D?\d\d\D?\d\d\D?(\d\d\.?(\d*))?(\d\d(:\d\d)?)?).(?P<priority>\d)`)

// Parse type for command
type Parse struct{}
Expand Down Expand Up @@ -74,15 +74,15 @@ func (p *Parse) Run(args []string) int {
}
}
p.byDate(true)
case "by-weight":
case "by-priority":
if len(args) == 2 {
switch args[1] {
case "-d":
p.byWeight(false)
p.byPriority(false)
return 1
}
}
p.byWeight(true)
p.byPriority(true)
default:
fmt.Println("ERROR: invalid option for parse\n")
}
Expand All @@ -97,7 +97,7 @@ Options:
by-user [-d decending] Parse todo's by user
by-file [-d decending] Parse todo's by file
by-date [-d decending] Parse todo's by date
by-weight [-d decending] Parse todo's by weight
by-priority [-d decending] Parse todo's by priority
`
}
Expand All @@ -116,22 +116,22 @@ func printOutput(ot string, t sort.Interface) {
case UserTodos:
for _, todo := range todoerType {
fmt.Fprintf(w, "%s\t%s\t%s\t%v\t%d\n",
todo.User(), todo.File(), todo.Message(), todo.Timestamp(), todo.Weight())
todo.User(), todo.File(), todo.Message(), todo.Timestamp(), todo.Priority())
}
case FileTodos:
for _, todo := range todoerType {
fmt.Fprintf(w, "%s\t%s\t%s\t%v\t%d\n",
todo.User(), todo.File(), todo.Message(), todo.Timestamp(), todo.Weight())
todo.User(), todo.File(), todo.Message(), todo.Timestamp(), todo.Priority())
}
case TimestampTodos:
for _, todo := range todoerType {
fmt.Fprintf(w, "%s\t%s\t%s\t%v\t%d\n",
todo.User(), todo.File(), todo.Message(), todo.Timestamp(), todo.Weight())
todo.User(), todo.File(), todo.Message(), todo.Timestamp(), todo.Priority())
}
case WeightTodos:
case PriorityTodos:
for _, todo := range todoerType {
fmt.Fprintf(w, "%s\t%s\t%s\t%v\t%d\n",
todo.User(), todo.File(), todo.Message(), todo.Timestamp(), todo.Weight())
todo.User(), todo.File(), todo.Message(), todo.Timestamp(), todo.Priority())
}
}
fmt.Fprintf(w, "\n")
Expand Down Expand Up @@ -194,7 +194,7 @@ func (p *Parse) byDate(decending bool) {
switch decending {
case true:
sort.Sort(timestampTodos)
printOutput("weight", timestampTodos)
printOutput("priority", timestampTodos)
return
case false:
sort.Sort(sort.Reverse(timestampTodos))
Expand All @@ -203,24 +203,24 @@ func (p *Parse) byDate(decending bool) {
}
}

// byWeight outputs the data by weight
func (p *Parse) byWeight(decending bool) {
// byPriority outputs the data by priority
func (p *Parse) byPriority(decending bool) {
todos, err := search()
if err != nil {
log.Fatalln(err)
}
weightTodos := make(WeightTodos, len(todos))
priorityTodos := make(PriorityTodos, len(todos))
for i := 0; i <= len(todos)-1; i++ {
weightTodos[i] = todos[i]
priorityTodos[i] = todos[i]
}
switch decending {
case true:
sort.Sort(weightTodos)
printOutput("weight", weightTodos)
sort.Sort(priorityTodos)
printOutput("priority", priorityTodos)
return
case false:
sort.Sort(sort.Reverse(weightTodos))
printOutput("weight", weightTodos)
sort.Sort(sort.Reverse(priorityTodos))
printOutput("priority", priorityTodos)
return
}
}
Expand Down Expand Up @@ -276,12 +276,12 @@ func search() ([]Todo, error) {
return nil, err
}
todo.timestamp = ts
case "weight":
case "priority":
s, err := strconv.Atoi(match[i])
if err != nil {
return nil, err
}
todo.weight = s
todo.priority = s
}
}
todos = append(todos, todo)
Expand Down
6 changes: 3 additions & 3 deletions command/weight.go → command/priority.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package command

var Weights = map[int]string{
var Priorities = map[int]string{
5: "Not at all important",
4: "Slightly important",
3: "Moderately important",
2: "Somewhat important",
1: "Extremely important",
}

// Weight is holds a weight
type Weight struct {
// Priority holds an individual priority
type Priority struct {
Value int
Description string
}
18 changes: 9 additions & 9 deletions command/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func (s *Show) Run(args []string) int {
switch args[0] {
case "format":
s.showFormat()
case "weights":
s.showWeights()
case "priorities":
s.showPriorities()
default:
fmt.Println("ERROR: invalid option for show\n")
}
Expand All @@ -43,8 +43,8 @@ func (s *Show) Help() string {
return `Usage: todo-view show <option> <arguments>
Show a resource
Options:
format Display todo-view todo format
weights Display todo-view weights
format Display todo-view format
priorities Display todo-view priorities
`
}
Expand All @@ -66,19 +66,19 @@ func (s *Show) showFormat() {
w.Flush()
}

// showWeights shows all configured weights
func (s *Show) showWeights() {
fmt.Print("\ntodo-view weights:\n\n")
// showPriorities shows all configured priorities
func (s *Show) showPriorities() {
fmt.Print("\ntodo-view priorities:\n\n")
w := NewTabWriter()

var keys []int
for k := range Weights {
for k := range Priorities {
keys = append(keys, k)
}
sort.Ints(keys)

for _, k := range keys {
fmt.Fprintf(w, "%d\t%s\n", k, Weights[k])
fmt.Fprintf(w, "%d\t%s\n", k, Priorities[k])
}

fmt.Fprintf(w, "\n")
Expand Down
30 changes: 15 additions & 15 deletions command/todo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import "time"

// Format represents how timestamps show look
var Format = "2006-01-02T15:04"
var todoFormat = "TODO(<user>) <message> <timestamp> <weight>"
var todoFormat = "TODO(<user>) <message> <timestamp> <priority>"

// Todoer implements the functionality to view todos
type Todoer interface {
User() string
File() string
Message() string
Timestamp() time.Time
Weight() int
priority() int
}

// Todo represents a todo
Expand All @@ -21,16 +21,16 @@ type Todo struct {
file string
message string
timestamp time.Time
weight int
priority int
}

// NewTodo creates a new reference of a todo
func NewTodo(u, m, ts, f string, w int) (*Todo, error) {
todo := &Todo{
user: u,
file: f,
message: m,
weight: w,
user: u,
file: f,
message: m,
priority: w,
}
timestamp, err := time.Parse(Format, ts)
if err != nil {
Expand All @@ -56,8 +56,8 @@ func (t *Todo) Timestamp() time.Time {
return t.timestamp
}

func (t *Todo) Weight() int {
return t.weight
func (t *Todo) Priority() int {
return t.priority
}

// UserTodos is a slice type made for easier sorting
Expand Down Expand Up @@ -119,20 +119,20 @@ func (t TimestampTodos) Swap(i, j int) {
t[i], t[j] = t[j], t[i]
}

// WeightTodos is a slice type made for easier sorting
type WeightTodos []Todo
// PriorityTodos is a slice type made for easier sorting
type PriorityTodos []Todo

// Len gets the length of the slice
func (w WeightTodos) Len() int {
func (w PriorityTodos) Len() int {
return len(w)
}

// Less does a comparison of the 2 given arguments
func (w WeightTodos) Less(i, j int) bool {
return w[i].weight < w[j].weight
func (w PriorityTodos) Less(i, j int) bool {
return w[i].priority < w[j].priority
}

// Swap switchs the place in the slice for the 2 given arguments
func (w WeightTodos) Swap(i, j int) {
func (w PriorityTodos) Swap(i, j int) {
w[i], w[j] = w[j], w[i]
}

0 comments on commit 7859f11

Please sign in to comment.