gum/main.go

82 lines
2 KiB
Go
Raw Normal View History

2022-06-11 00:07:40 +02:00
package main
import (
2022-07-31 03:41:18 +02:00
"errors"
"fmt"
2022-07-31 03:10:36 +02:00
"os"
2022-07-28 20:10:43 +02:00
"runtime/debug"
2022-06-11 00:07:40 +02:00
"github.com/alecthomas/kong"
"github.com/charmbracelet/lipgloss"
2023-03-24 21:59:41 +01:00
"github.com/muesli/termenv"
2022-08-05 00:45:19 +02:00
"github.com/charmbracelet/gum/internal/exit"
2022-06-11 00:07:40 +02:00
)
2022-08-05 00:45:19 +02:00
const shaLen = 7
2022-07-28 20:10:43 +02:00
var (
// Version contains the application version number. It's set via ldflags
// when building.
Version = ""
// CommitSHA contains the SHA of the commit that this application was built
// against. It's set via ldflags when building.
CommitSHA = ""
)
var bubbleGumPink = lipgloss.NewStyle().Foreground(lipgloss.Color("212"))
2022-06-11 00:07:40 +02:00
func main() {
lipgloss.SetColorProfile(termenv.NewOutput(os.Stderr).Profile)
2023-03-24 21:59:41 +01:00
2022-07-28 20:10:43 +02:00
if Version == "" {
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" {
Version = info.Main.Version
} else {
Version = "unknown (built from source)"
}
}
version := fmt.Sprintf("gum version %s", Version)
2022-08-05 00:45:19 +02:00
if len(CommitSHA) >= shaLen {
version += " (" + CommitSHA[:shaLen] + ")"
2022-07-28 20:10:43 +02:00
}
2022-07-07 19:26:35 +02:00
gum := &Gum{}
ctx := kong.Parse(
gum,
kong.Description(fmt.Sprintf("A tool for %s shell scripts.", bubbleGumPink.Render("glamorous"))),
2022-06-11 00:07:40 +02:00
kong.UsageOnError(),
kong.ConfigureHelp(kong.HelpOptions{
Compact: true,
Summary: false,
NoExpandSubcommands: true,
}),
kong.Vars{
"version": version,
2022-10-01 00:40:10 +02:00
"defaultHeight": "0",
"defaultWidth": "0",
"defaultAlign": "left",
"defaultBorder": "none",
"defaultBorderForeground": "",
2022-10-01 00:40:10 +02:00
"defaultBorderBackground": "",
"defaultBackground": "",
"defaultForeground": "",
"defaultMargin": "0 0",
"defaultPadding": "0 0",
"defaultUnderline": "false",
2022-10-01 00:40:10 +02:00
"defaultBold": "false",
"defaultFaint": "false",
"defaultItalic": "false",
"defaultStrikethrough": "false",
},
)
2022-07-31 03:10:36 +02:00
if err := ctx.Run(); err != nil {
2022-07-31 03:41:18 +02:00
if errors.Is(err, exit.ErrAborted) {
os.Exit(exit.StatusAborted)
}
2023-11-29 17:00:43 +01:00
fmt.Println(err)
2022-07-31 03:10:36 +02:00
os.Exit(1)
}
2022-06-11 00:07:40 +02:00
}