From b79b82798ddb3976e9c9420e26c180de4f7477c8 Mon Sep 17 00:00:00 2001 From: Wancat Date: Wed, 19 Oct 2022 10:15:59 +0800 Subject: [PATCH] Add ledger initial file option, add meta viewport --- .gitignore | 1 + config.go | 7 +++++++ main.go | 7 ++++++- scripts.go | 8 +------- templates/index.html | 1 + templates/new.html | 1 + templates/success.html | 1 + 7 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 config.go diff --git a/.gitignore b/.gitignore index 90cefae..6382695 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .env test.txt +ledger-quicknote diff --git a/config.go b/config.go new file mode 100644 index 0000000..5fe6c7c --- /dev/null +++ b/config.go @@ -0,0 +1,7 @@ +package main + +var SCRIPTS = map[string][]string{ + "balance assets": {"b", "assets", "-X", "$"}, + "register": {"r", "--tail", "10"}, + "balance this month": {"b", "-b", "this month"}, +} diff --git a/main.go b/main.go index 213e5e6..f0ce57e 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "flag" "io" "log" "net/http" @@ -15,7 +16,8 @@ import ( var ledgerTpl *template.Template var htmlTpl *template.Template -const LEDGER_FILE = "test.txt" +var LEDGER_FILE string +var LEDGER_INIT string type TxData struct { Name string @@ -27,6 +29,9 @@ type TxData struct { func init() { ledgerTpl = template.Must(template.ParseGlob("tx/*")) htmlTpl = template.Must(template.ParseGlob("templates/*.html")) + flag.StringVar(&LEDGER_FILE, "f", "example.txt", "ledger journal file") + flag.StringVar(&LEDGER_INIT, "i", "~/.ledgerrc", "ledger initiation file") + flag.Parse() } func main() { diff --git a/scripts.go b/scripts.go index d775026..c6a6db8 100644 --- a/scripts.go +++ b/scripts.go @@ -6,18 +6,12 @@ import ( "os/exec" ) -var SCRIPTS = map[string][]string{ - "balance": {"b"}, - "register": {"r"}, - "expenses this month": {"b", "expenses", "-b", "this month"}, -} - func executeScript(w io.Writer, name string) (err error) { 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 := exec.Command("ledger", append([]string{"--init-file", LEDGER_INIT}, script...)...) cmd.Stdout = w cmd.Stderr = w return cmd.Run() diff --git a/templates/index.html b/templates/index.html index f619a54..f8d13f8 100644 --- a/templates/index.html +++ b/templates/index.html @@ -2,6 +2,7 @@ Ledger Quick Note +

Ledger Quick Note

diff --git a/templates/new.html b/templates/new.html index bb42f1f..21cf00a 100644 --- a/templates/new.html +++ b/templates/new.html @@ -2,6 +2,7 @@ Ledger Quick Note +

Comfirm new Tx

diff --git a/templates/success.html b/templates/success.html index 81c5ecd..02d3460 100644 --- a/templates/success.html +++ b/templates/success.html @@ -2,6 +2,7 @@ Ledger Quick Note +

Ledger Quick Note