print as html
This commit is contained in:
1 parent
62fe1a7076
commit
6703481dbb
9 files changed
+339
-20
No files matched your search
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/nmoniz/any2anexoj/internal/trading212"
|
||||
"github.com/nmoniz/any2anexoj/internal/writing"
|
||||
"github.com/nmoniz/any2anexoj/internal/writing/csv"
|
||||
"github.com/nmoniz/any2anexoj/internal/writing/html"
|
||||
"github.com/nmoniz/any2anexoj/internal/writing/pretty"
|
||||
"github.com/spf13/pflag"
|
||||
"golang.org/x/text/language"
|
||||
@@ -26,7 +27,7 @@ var (
|
||||
platform = pflag.StringP("platform", "p", "trading212", "One of the supported platforms")
|
||||
lang = pflag.StringP("language", "l", language.Portuguese.String(), "The 2 letter language code")
|
||||
debug = pflag.BoolP("debug", "d", false, "Activate to log debug messages")
|
||||
format = pflag.StringP("format", "f", "table", "Output format: table or csv")
|
||||
format = pflag.StringP("format", "f", "table", "Output format: table, csv or html")
|
||||
ofAPIKey = pflag.String("open-figi-api-key", "", "An OpenFIGI API key for faster report generation (better rate api rate limits)")
|
||||
selectors = pflag.StringSlice("selectors", nil, "Only process entries that conform to all the selectors: code, assetCountry")
|
||||
stateFile = pflag.String("state-file", "", "Path to a state file for incremental processing")
|
||||
@@ -109,8 +110,18 @@ func runWithIO(ctx context.Context, stdin io.Reader, stdout io.Writer) error {
|
||||
}
|
||||
pretty.NewPrettyPrinter(stdout, loc).Render(writer)
|
||||
return nil
|
||||
case "html":
|
||||
loc, err := writing.NewLocalizer(*lang)
|
||||
if err != nil {
|
||||
return fmt.Errorf("create localizer: %w", err)
|
||||
}
|
||||
// RenderHTML never writes to the printer's output writer, so
|
||||
// io.Discard is safe here.
|
||||
printer := pretty.NewPrettyPrinter(io.Discard, loc)
|
||||
title := loc.Translate("report_title", 1, nil)
|
||||
return html.NewHTMLWriter(stdout, printer, title, *lang).Render(writer)
|
||||
default:
|
||||
return fmt.Errorf("unsupported format %q: must be table or csv", *format)
|
||||
return fmt.Errorf("unsupported format %q: must be table, csv or html", *format)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user