Skip to content

Commit

Permalink
feat/ export command added
Browse files Browse the repository at this point in the history
  • Loading branch information
sinabehmanesh committed Aug 1, 2024
1 parent 5a24195 commit 33c51be
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
# Change Log
All notable changes to this project will be documented in this file.

## [v2.1]
## [v2.2]
### Upcoming changes:
- introduce editing tasks, you can edit task description/name using edit command
- ability to delete all tasks at once, also exporting them into a file.
- auto installation for this task

## [v2.1]
- ability to export tasks into a file, export command.

## [v2.0]
- Language will be changed to Golang
Expand Down
1 change: 1 addition & 0 deletions command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ func Help() {
fmt.Println("\t\t add [TASK DESCRIPTION]\t Add tasks with name/description")
fmt.Println("\t\t del, rm [ID] \t\t Delete tasks by ID")
fmt.Println("\t\t done [ID] \t\t Update task status from todo to Done")
fmt.Println("\t\t export \t\t export tasks into a file, file format: [dump]-[RFC date]")
}
39 changes: 39 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@ import (
"fmt"
"log"
"os"
"os/user"
"strconv"
"strings"
"time"

cmd "main/command"
db "main/database"
)

func main() {
user, err := user.Current()
if err != nil {
log.Fatal(err)
}

configdir := user.HomeDir + "/.RTM"

if len(os.Args) <= 1 {
log.Fatal("Wrong input. Run rtm --help")
}
Expand Down Expand Up @@ -75,6 +85,35 @@ func main() {
fmt.Println("Task", task_id, "is now Done! Good Job.")
}

//Export
case "export":

var temp_task []db.Task
data := local_db.Find(&temp_task)
if data.Error != nil {
log.Fatal(data.Error)
}

now := time.Now()
timenow := now.Format(time.RFC3339)
export_file := configdir + "/dump-" + timenow

//File
file, err := os.Create(export_file)
if err != nil {
log.Fatal(err)
} else {

for _, item := range temp_task {
recordID := strconv.FormatUint(uint64(item.ID), 10)
record := fmt.Sprintf("%s \t %s \t %s \n", recordID, item.Status, item.Name)
_, err := file.WriteString(record)
if err != nil {
log.Fatal(err)
}
}
}

//Help
case "--help", "help", "-h":
cmd.Help()
Expand Down

0 comments on commit 33c51be

Please sign in to comment.