chore: cleanup

Signed-off-by: jolheiser <john.olheiser@gmail.com>
main
jolheiser 2024-06-06 20:49:33 -05:00
parent b4097abed2
commit 48b98f65aa
Signed by: jolheiser
GPG Key ID: B853ADA5DA7BBF7A
1 changed files with 8 additions and 4 deletions

View File

@ -24,7 +24,7 @@ func maine() error {
unmarshal = e.Unmarshal
return nil
}
fs.Func("from", "The format to convert from", fromFunc)
fs.Func("from", "The format to convert from [json(c), yaml, toml, nix, dhall]", fromFunc)
fs.Func("f", "--from", fromFunc)
toFunc := func(s string) error {
e, err := cfg.ParseEncoding(s)
@ -34,7 +34,7 @@ func maine() error {
marshal = e.Marshal
return nil
}
fs.Func("to", "The format to convert to", toFunc)
fs.Func("to", "The format to convert to [json, yaml, toml, nix]", toFunc)
fs.Func("t", "--to", toFunc)
if err := fs.Parse(os.Args[1:]); err != nil {
return err
@ -44,9 +44,13 @@ func maine() error {
return errors.New("cfg requires at least an input file")
}
cleanArg := func(arg string) string {
return strings.TrimPrefix(filepath.Ext(arg), ".")
}
in := fs.Arg(0)
if unmarshal == nil {
if err := fromFunc(strings.TrimPrefix(filepath.Ext(fs.Arg(0)), ".")); err != nil {
if err := fromFunc(cleanArg(fs.Arg(0))); err != nil {
return err
}
}
@ -61,7 +65,7 @@ func maine() error {
out = fi
if marshal == nil {
if err := toFunc(strings.TrimPrefix(filepath.Ext(fs.Arg(1)), ".")); err != nil {
if err := toFunc(cleanArg(fs.Arg(1))); err != nil {
return err
}
}