summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorBenjamin Chausse <benjamin@chausse.xyz>2024-12-27 02:00:21 -0500
committerBenjamin Chausse <benjamin@chausse.xyz>2024-12-27 02:00:21 -0500
commitaa323b86f979936cb1c8eda3301e13683f4c5a0f (patch)
tree1815b9b27c3ff2abc91e63b9fd927e5047b56c5f /main.go
parentf438213c56fb072bbd3dc1aed0fd7e901181a7b9 (diff)
migrate to urfave/cli V3
Diffstat (limited to 'main.go')
-rw-r--r--main.go37
1 files changed, 16 insertions, 21 deletions
diff --git a/main.go b/main.go
index 5511ac6..f8dacf8 100644
--- a/main.go
+++ b/main.go
@@ -1,31 +1,29 @@
package main
import (
+ "context"
"log/slog"
"os"
- "time"
"github.com/ChausseBenjamin/termpicker/internal/logging"
"github.com/ChausseBenjamin/termpicker/internal/switcher"
"github.com/ChausseBenjamin/termpicker/internal/util"
tea "github.com/charmbracelet/bubbletea"
- "github.com/urfave/cli/v2"
+ "github.com/urfave/cli/v3"
)
-var ( // Set by the build system
- version = "compiled"
- date = ""
-)
+// Set by the build system
+var version = "compiled"
-func AppAction(ctx *cli.Context) error {
- logfile := logging.Setup(ctx.String("logfile"))
+func AppAction(ctx context.Context, cmd *cli.Command) error {
+ logfile := logging.Setup(cmd.String("logfile"))
defer logfile.Close()
slog.Info("Starting Termpicker")
sw := switcher.New()
- if colorStr := ctx.String("color"); colorStr != "" {
+ if colorStr := cmd.String("color"); colorStr != "" {
sw.NewNotice(sw.SetColorFromText(colorStr))
}
@@ -37,19 +35,16 @@ func AppAction(ctx *cli.Context) error {
}
func main() {
- compileDate, _ := time.Parse(time.RFC3339, date)
- app := &cli.App{
- Name: "Termpicker",
- Usage: "A terminal-based color picker",
- Action: AppAction,
- Authors: []*cli.Author{
- {Name: "Benjamin Chausse", Email: "benjamin@chausse.xyz"},
- },
- Version: version,
- Flags: AppFlags,
- Compiled: compileDate,
+ app := &cli.Command{
+ Name: "Termpicker",
+ Usage: "A terminal-based color picker",
+ Action: AppAction,
+ Authors: []any{"Benjamin Chausse <benjamin@chausse.xhz>"},
+ Version: version,
+ Flags: AppFlags,
+ EnableShellCompletion: true,
}
- if err := app.Run(os.Args); err != nil {
+ if err := app.Run(context.Background(), os.Args); err != nil {
slog.Error("Program crashed", util.ErrKey, err.Error())
os.Exit(1)
}