Skip to content
This repository has been archived by the owner on Nov 8, 2020. It is now read-only.

Commit

Permalink
update to v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mrinjamul committed Sep 15, 2020
1 parent b7e7982 commit e75ff67
Show file tree
Hide file tree
Showing 9 changed files with 281 additions and 11 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Clone repository

`git clone [repo location]`
`git clone https://github.com/mrinjamul/gtodo`

`cd gtodo`

Expand All @@ -16,14 +16,14 @@ Build

`go build`

Create data files

`touch $HOME/.gtodo.json`

Run ,

`./gtodo`

Install

`go install gtodo`

If you want you can install by copying into any \$PATH

For example,
Expand Down Expand Up @@ -62,6 +62,9 @@ command and flag definitions are needed.
done Mark Item as Done
help Help about any command
list list all todos
modify edit a todo
remove Remove a todo
undone Mark Item as UnDone
version Print the version number of gtodo

Flags:
Expand Down
2 changes: 1 addition & 1 deletion cmd/done.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func doneRun(cmd *cobra.Command, args []string) {
i, err := strconv.Atoi(args[0])

if err != nil {
log.Fatalln(args[0], "is not a valid label\n", err)
log.Fatalln(args[0], "is not a valid label\ninvalid syntax")
}
if i > 0 && i <= len(items) {
items[i-1].Done = true
Expand Down
2 changes: 1 addition & 1 deletion cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ func init() {
// is called directly, e.g.:
// listCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
listCmd.Flags().BoolVarP(&doneOpt, "done", "d", false, "Show 'Done' Todos")
listCmd.Flags().BoolVarP(&allOpt, "all", "a", false, "Show all TOdos")
listCmd.Flags().BoolVarP(&allOpt, "all", "a", false, "Show All Todos")

}
72 changes: 72 additions & 0 deletions cmd/modify.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
Copyright © 2020 Injamul Mohammad Mollah
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cmd

import (
"log"
"sort"
"strconv"

"github.com/mrinjamul/gtodo/todo"
"github.com/spf13/cobra"
)

// modifyCmd represents the modify command
var modifyCmd = &cobra.Command{
Use: "modify",
Aliases: []string{"mod", "ed"},
Short: "edit a todo",
Long: ``,
Run: modifyRun,
}

func modifyRun(cmd *cobra.Command, args []string) {
items, err := todo.ReadItems(dataFile)
i, err := strconv.Atoi(args[0])
if err != nil {
log.Fatalln(args[0], "is not a valid label\ninvalid syntax")
}
if len(args) == 1 {
log.Fatalln("todo name is empty")
}
if len(args) > 2 {
log.Fatalln("Too much arguments")
}
text := args[1]
if i > 0 && i <= len(items) {
items[i-1].Text = text
sort.Sort(todo.ByPri(items))
todo.SaveItems(dataFile, items)
} else {
log.Println(i, "doesn't match any items")
}

}

func init() {
rootCmd.AddCommand(modifyCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// modifyCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// modifyCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
68 changes: 68 additions & 0 deletions cmd/remove.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
Copyright © 2020 Injamul Mohammad Mollah
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cmd

import (
"fmt"
"log"
"sort"
"strconv"

"github.com/mrinjamul/gtodo/todo"
"github.com/spf13/cobra"
)

// removeCmd represents the remove command
var removeCmd = &cobra.Command{
Use: "remove",
Aliases: []string{"rm"},
Short: "Remove a todo",
Long: `Remove will remove a todo item from the list by Label(index)`,
Run: removeRun,
}

func removeRun(cmd *cobra.Command, args []string) {
items, err := todo.ReadItems(dataFile)
i, err := strconv.Atoi(args[0])

if err != nil {
log.Fatalln(args[0], "is not a valid label\ninvalid syntax")
}
if i > 0 && i <= len(items) {
text := items[i-1].Text
items = todo.RemoveItem(items, i-1)
fmt.Println("- " + "\"" + strconv.Itoa(i) + ". " + text + "\"" + " has been removed")
sort.Sort(todo.ByPri(items))
todo.SaveItems(dataFile, items)
} else {
log.Println(i, "doesn't match any items")
}
}

func init() {
rootCmd.AddCommand(removeCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// removeCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// removeCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
68 changes: 68 additions & 0 deletions cmd/undone.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
Copyright © 2020 Injamul Mohammad Mollah
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cmd

import (
"fmt"
"log"
"sort"
"strconv"

"github.com/mrinjamul/gtodo/todo"
"github.com/spf13/cobra"
)

// undoneCmd represents the undone command
var undoneCmd = &cobra.Command{
Use: "undone",
Aliases: []string{"undo"},
Short: "Mark Item as UnDone",
Long: ``,
Run: undoneRun,
}

func undoneRun(cmd *cobra.Command, args []string) {
items, err := todo.ReadItems(dataFile)
i, err := strconv.Atoi(args[0])

if err != nil {
log.Fatalln(args[0], "is not a valid label\ninvalid syntax")
}
if i > 0 && i <= len(items) {
items[i-1].Done = false
fmt.Printf("%q %v\n", items[i-1].Text, "marked undone")

sort.Sort(todo.ByPri(items))
todo.SaveItems(dataFile, items)
} else {
log.Println(i, "doesn't match any items")
}
}

func init() {
rootCmd.AddCommand(undoneCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// undoneCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// undoneCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
56 changes: 55 additions & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ command and flag definitions are needed.
done Mark Item as Done
help Help about any command
list list all todos
modify edit a todo
remove Remove a todo
undone Mark Item as UnDone
version Print the version number of gtodo

Flags:
Expand Down Expand Up @@ -43,6 +46,40 @@ command and flag definitions are needed.
--config string config file (default is $HOME/.gtodo.yaml)
--datafile string data file to store todos (default "$HOME/.gtodo.json")

### remove

Remove will remove a todo item from the list by Label(index)

Usage:
gtodo remove [flags]

Aliases:
remove, rm

Flags:
-h, --help help for remove

Global Flags:
--config string config file (default is $HOME/.gtodo.yaml)
--datafile string data file to store todos (default "$HOME/.gtodo.json")

### modify

edit a todo

Usage:
gtodo modify [flags]

Aliases:
modify, mod, ed

Flags:
-h, --help help for modify

Global Flags:
--config string config file (default is $HOME/.gtodo.yaml)
--datafile string data file to store todos (default "$HOME/.gtodo.json")

### clear

Clear all todos
Expand Down Expand Up @@ -75,6 +112,23 @@ Mark Item as Done
--config string config file (default is $HOME/.gtodo.yaml)
--datafile string data file to store todos (default "$HOME/.gtodo.json")

### undo

Mark Item as UnDone

Usage:
gtodo undone [flags]

Aliases:
undone, undo

Flags:
-h, --help help for undone

Global Flags:
--config string config file (default is $HOME/.gtodo.yaml)
--datafile string data file to store todos (default "$HOME/.gtodo.json")

### list

list all todos
Expand All @@ -96,4 +150,4 @@ Mark Item as Done

### version

Prints current version of gtodo
Prints current version of gtodo
9 changes: 7 additions & 2 deletions todo/todo.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Item struct {
Done bool
}

var version string = "v0.1.1"
var version string = "v0.2.0"

// GetVersion : returns version info
func GetVersion() string {
Expand Down Expand Up @@ -63,7 +63,7 @@ func ReadItems(filename string) ([]Item, error) {
if err := json.Unmarshal(b, &items); err != nil {
return []Item{}, err
}
for i, _ := range items {
for i := range items {
items[i].position = i + 1
}
return items, nil
Expand Down Expand Up @@ -122,3 +122,8 @@ func (i *Item) PrettyDone() string {
}
return ""
}

// RemoveItem removes todo from list
func RemoveItem(slice []Item, s int) []Item {
return append(slice[:s], slice[s+1:]...)
}
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.1.1
v0.2.0

0 comments on commit e75ff67

Please sign in to comment.