Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mkobetic committed Nov 14, 2023
1 parent bfb4907 commit 802a844
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions cmd/coin/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"path"

"github.com/mkobetic/coin"
"github.com/mkobetic/coin/check"
)

func init() {
Expand Down Expand Up @@ -42,22 +43,18 @@ func (cmd *cmdFormat) execute(f io.Writer) {
coin.ResolveTransactions(false)
if cmd.replace {
tf, err = os.CreateTemp(path.Dir(fn), path.Base(fn))
if err != nil {
panic(err)
}
check.NoError(err, "creating temp file")
f = tf
}
for _, t := range coin.Transactions {
t.Write(f, cmd.ledger)
fmt.Fprintln(f)
}
if cmd.replace {
if err = os.Remove(fn); err != nil {
panic(err)
}
if err = os.Rename(tf.Name(), fn); err != nil {
panic(err)
}
err = os.Remove(fn)
check.NoError(err, "deleting old file")
err = os.Rename(tf.Name(), fn)
check.NoError(err, "renaming temp file")
}
// Note that this doesn't properly get rid of transactions,
// postings are still referenced through the accounts,
Expand Down

0 comments on commit 802a844

Please sign in to comment.