3 Commits

Author SHA1 Message Date
Bel LaPointe
f7dac79233 pttodo-cli default file via env 2021-12-31 22:07:16 -05:00
Bel LaPointe
8c45d4a7df pttodo-cli works even if file does not initially exist 2021-12-31 22:05:47 -05:00
Bel LaPointe
1e3f24b4d5 rename gomod, root project 2021-12-31 21:58:02 -05:00
4 changed files with 16 additions and 10 deletions

View File

@@ -22,7 +22,11 @@ func main() {
} }
func _main() error { func _main() error {
filepath := flag.String("f", "-", "path to yaml file") defaultFilepath, ok := os.LookupEnv("PTTODO_FILE")
if !ok {
defaultFilepath = "-"
}
filepath := flag.String("f", defaultFilepath, "($PTTODO_FILE) path to yaml file")
e := flag.Bool("e", false, "edit file") e := flag.Bool("e", false, "edit file")
flag.Parse() flag.Parse()
if *e { if *e {
@@ -40,14 +44,16 @@ func edit(filepath string) error {
if err != nil { if err != nil {
return err return err
} }
g, err := os.Open(filepath) if _, err := os.Stat(filepath); err == nil {
if err != nil { g, err := os.Open(filepath)
return err if err != nil {
return err
}
if _, err := io.Copy(f, g); err != nil {
return err
}
g.Close()
} }
if _, err := io.Copy(f, g); err != nil {
return err
}
g.Close()
f.Close() f.Close()
tempFile = f.Name() tempFile = f.Name()
return nil return nil

View File

@@ -1,4 +1,4 @@
module pttodo module pttodo-cli
go 1.17 go 1.17

2
go.mod
View File

@@ -1,4 +1,4 @@
module local/pt-todo-server module pttodo
go 1.17 go 1.17