Skip to content

Commit

Permalink
allow input to be from stdin
Browse files Browse the repository at this point in the history
fixes #21
  • Loading branch information
howeyc committed Dec 5, 2020
1 parent f214710 commit a59591c
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions cmd/ledger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"flag"
"fmt"
"io"
"os"
"strings"
"time"

Expand Down Expand Up @@ -67,13 +69,20 @@ func main() {
return
}

ledgerFileReader, err := ledger.NewLedgerReader(ledgerFileName)
if err != nil {
fmt.Println(err)
return
var lreader io.Reader

if ledgerFileName == "-" {
lreader = os.Stdin
} else {
ledgerFileReader, err := ledger.NewLedgerReader(ledgerFileName)
if err != nil {
fmt.Println(err)
return
}
lreader = ledgerFileReader
}

generalLedger, parseError := ledger.ParseLedger(ledgerFileReader)
generalLedger, parseError := ledger.ParseLedger(lreader)
if parseError != nil {
fmt.Printf("%s\n", parseError.Error())
return
Expand Down

0 comments on commit a59591c

Please sign in to comment.