summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go37
1 files changed, 3 insertions, 34 deletions
diff --git a/main.go b/main.go
index f8dacf8..9ce095b 100644
--- a/main.go
+++ b/main.go
@@ -5,46 +5,15 @@ import (
"log/slog"
"os"
- "github.com/ChausseBenjamin/termpicker/internal/logging"
- "github.com/ChausseBenjamin/termpicker/internal/switcher"
+ "github.com/ChausseBenjamin/termpicker/internal/app"
"github.com/ChausseBenjamin/termpicker/internal/util"
- tea "github.com/charmbracelet/bubbletea"
- "github.com/urfave/cli/v3"
)
-// Set by the build system
var version = "compiled"
-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 := cmd.String("color"); colorStr != "" {
- sw.NewNotice(sw.SetColorFromText(colorStr))
- }
-
- p := tea.NewProgram(sw)
- if _, err := p.Run(); err != nil {
- return err
- }
- return nil
-}
-
func main() {
- 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(context.Background(), os.Args); err != nil {
+ cmd := app.Command(version)
+ if err := cmd.Run(context.Background(), os.Args); err != nil {
slog.Error("Program crashed", util.ErrKey, err.Error())
os.Exit(1)
}