Add basic argument parser, add tasks to csv file, help function to print commands
This commit is contained in:
42
godo.go
Normal file
42
godo.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/csv"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
args := os.Args
|
||||||
|
if len(args) < 2 {
|
||||||
|
fmt.Println("Use godo ? or help for the help menu")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
switch args[1] {
|
||||||
|
case "?", "help":
|
||||||
|
help()
|
||||||
|
case "a", "add":
|
||||||
|
add(args[2])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func help() {
|
||||||
|
fmt.Println("?/help - help menu")
|
||||||
|
fmt.Println("a/add - add new task")
|
||||||
|
fmt.Println("l/list - add new task")
|
||||||
|
}
|
||||||
|
|
||||||
|
func add(task string) {
|
||||||
|
file, err := os.OpenFile("tasks.csv", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error Creating File;", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
writer := csv.NewWriter(file)
|
||||||
|
defer writer.Flush()
|
||||||
|
var taskWrite []string
|
||||||
|
taskWrite = append(taskWrite, task)
|
||||||
|
writer.Write(taskWrite)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user