Display script list

This commit is contained in:
Wancat
2022-10-19 09:32:20 +08:00
parent 25503867f9
commit 1f82bd4bcb
3 changed files with 30 additions and 14 deletions

View File

@@ -1,17 +1,23 @@
package main
import (
"fmt"
"io"
"os/exec"
)
var SCRIPTS = map[string][]string{
"balance": {"b"},
"register": {"r"},
"balance": {"b"},
"register": {"r"},
"expenses this month": {"b", "expenses", "-b", "this month"},
}
func executeScript(w io.Writer, name string) (err error) {
cmd := exec.Command("ledger", append([]string{"-f", LEDGER_FILE}, SCRIPTS[name]...)...)
script, ok := SCRIPTS[name]
if !ok {
return fmt.Errorf("%s script not found", name)
}
cmd := exec.Command("ledger", append([]string{"-f", LEDGER_FILE}, script...)...)
cmd.Stdout = w
cmd.Stderr = w
return cmd.Run()