2022-06-11 01:07:40 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-07-31 04:41:18 +03:00
|
|
|
"errors"
|
2022-07-14 17:37:22 +03:00
|
|
|
"fmt"
|
2022-07-31 04:10:36 +03:00
|
|
|
"os"
|
2022-07-28 21:10:43 +03:00
|
|
|
"runtime/debug"
|
2022-07-14 17:37:22 +03:00
|
|
|
|
2022-06-11 01:07:40 +03:00
|
|
|
"github.com/alecthomas/kong"
|
2022-07-06 19:51:12 +03:00
|
|
|
"github.com/charmbracelet/lipgloss"
|
2023-03-24 23:59:41 +03:00
|
|
|
"github.com/muesli/termenv"
|
2022-08-05 01:45:19 +03:00
|
|
|
|
|
|
|
"github.com/charmbracelet/gum/internal/exit"
|
2022-06-11 01:07:40 +03:00
|
|
|
)
|
|
|
|
|
2022-08-05 01:45:19 +03:00
|
|
|
const shaLen = 7
|
|
|
|
|
2022-07-28 21:10:43 +03: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 = ""
|
|
|
|
)
|
|
|
|
|
2022-07-14 17:37:22 +03:00
|
|
|
var bubbleGumPink = lipgloss.NewStyle().Foreground(lipgloss.Color("212"))
|
|
|
|
|
2022-06-11 01:07:40 +03:00
|
|
|
func main() {
|
2023-11-28 20:34:50 +03:00
|
|
|
lipgloss.SetColorProfile(termenv.NewOutput(os.Stderr).Profile)
|
2023-03-24 23:59:41 +03:00
|
|
|
|
2022-07-28 21:10:43 +03: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 01:45:19 +03:00
|
|
|
if len(CommitSHA) >= shaLen {
|
|
|
|
version += " (" + CommitSHA[:shaLen] + ")"
|
2022-07-28 21:10:43 +03:00
|
|
|
}
|
|
|
|
|
2022-07-07 20:26:35 +03:00
|
|
|
gum := &Gum{}
|
2022-07-13 05:12:02 +03:00
|
|
|
ctx := kong.Parse(
|
|
|
|
gum,
|
2022-08-02 23:48:43 +03:00
|
|
|
kong.Description(fmt.Sprintf("A tool for %s shell scripts.", bubbleGumPink.Render("glamorous"))),
|
2022-06-11 01:07:40 +03:00
|
|
|
kong.UsageOnError(),
|
2022-07-13 05:12:02 +03:00
|
|
|
kong.ConfigureHelp(kong.HelpOptions{
|
2023-11-28 22:17:57 +03:00
|
|
|
Compact: true,
|
|
|
|
Summary: false,
|
|
|
|
NoExpandSubcommands: true,
|
2022-07-13 05:12:02 +03:00
|
|
|
}),
|
2022-07-21 18:27:36 +03:00
|
|
|
kong.Vars{
|
2022-09-30 21:30:52 +03:00
|
|
|
"version": version,
|
2022-10-01 01:40:10 +03:00
|
|
|
"defaultHeight": "0",
|
|
|
|
"defaultWidth": "0",
|
|
|
|
"defaultAlign": "left",
|
2022-09-30 21:30:52 +03:00
|
|
|
"defaultBorder": "none",
|
|
|
|
"defaultBorderForeground": "",
|
2022-10-01 01:40:10 +03:00
|
|
|
"defaultBorderBackground": "",
|
2022-09-30 21:30:52 +03:00
|
|
|
"defaultBackground": "",
|
|
|
|
"defaultForeground": "",
|
|
|
|
"defaultMargin": "0 0",
|
|
|
|
"defaultPadding": "0 0",
|
|
|
|
"defaultUnderline": "false",
|
2022-10-01 01:40:10 +03:00
|
|
|
"defaultBold": "false",
|
|
|
|
"defaultFaint": "false",
|
|
|
|
"defaultItalic": "false",
|
|
|
|
"defaultStrikethrough": "false",
|
2022-07-21 18:27:36 +03:00
|
|
|
},
|
2022-07-12 23:05:40 +03:00
|
|
|
)
|
2022-07-31 04:10:36 +03:00
|
|
|
if err := ctx.Run(); err != nil {
|
2022-07-31 04:41:18 +03:00
|
|
|
if errors.Is(err, exit.ErrAborted) {
|
|
|
|
os.Exit(exit.StatusAborted)
|
|
|
|
}
|
2023-11-29 19:00:43 +03:00
|
|
|
fmt.Println(err)
|
2022-07-31 04:10:36 +03:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
2022-06-11 01:07:40 +03:00
|
|
|
}
|