moonmath/moonmath.go

43 lines
812 B
Go
Raw Permalink Normal View History

2024-03-17 02:10:05 -07:00
package main
import (
"fmt"
"os"
2024-03-21 17:39:10 -07:00
"strings"
2024-03-17 02:10:05 -07:00
2024-03-21 17:39:10 -07:00
"code.humancabbage.net/sam/moonmath/coindesk"
2024-03-19 21:44:11 -07:00
"code.humancabbage.net/sam/moonmath/config"
2024-03-19 18:38:46 -07:00
"code.humancabbage.net/sam/moonmath/tui"
2024-03-19 21:44:11 -07:00
"github.com/alecthomas/kong"
2024-03-17 02:10:05 -07:00
)
2024-03-19 21:44:11 -07:00
var CLI struct {
2024-03-21 17:39:10 -07:00
Asset string `short:"a" default:"BTC" help:"Asset to project."`
ConfigFile string `short:"c" help:"Path to YAML configuration file."`
2024-03-19 21:44:11 -07:00
}
2024-03-17 02:10:05 -07:00
func main() {
2024-03-19 21:44:11 -07:00
ctx := kong.Parse(&CLI)
if ctx.Error != nil {
fail(ctx.Error)
}
2024-03-21 17:39:10 -07:00
allCfg, err := config.Load(CLI.ConfigFile)
if err != nil {
fail(err)
}
CLI.Asset = strings.ToUpper(CLI.Asset)
cfg, err := allCfg.GetData(coindesk.Asset(CLI.Asset))
2024-03-19 21:44:11 -07:00
if err != nil {
fail(err)
}
p := tui.New(cfg)
2024-03-17 02:10:05 -07:00
if _, err := p.Run(); err != nil {
2024-03-19 21:44:11 -07:00
fail(err)
2024-03-17 02:10:05 -07:00
}
}
2024-03-19 21:44:11 -07:00
func fail(err error) {
fmt.Printf("program error: %v\n", err)
os.Exit(1)
}