cmd/cli/main.go
cmd/cli/main.goBrowse 1970 files
537 tokens
1,947 bytes
Token encoding: o200k_base
Snapshot 21a254f
← Back to SKILL.md
1package main2 3import (4 "context"5 "os"6 7 "github.com/charmbracelet/lipgloss"8 "github.com/charmbracelet/log"9 "github.com/muesli/termenv"10 "github.com/railwayapp/railpack/cli"11 urfave "github.com/urfave/cli/v3"12)13 14var (15 verbose bool16 version = "dev" // This will be overwritten by goreleaser17)18 19func main() {20 cli.Version = version21 22 logger := log.Default()23 logger.SetTimeFormat("")24 urfaveLogWriter := logger.StandardLog(log.StandardLogOptions{25 ForceLevel: log.ErrorLevel,26 }).Writer()27 urfave.ErrWriter = urfaveLogWriter28 29 if os.Getenv("FORCE_COLOR") != "" {30 lipgloss.SetColorProfile(termenv.TrueColor)31 }32 33 // https://no-color.org34 if os.Getenv("NO_COLOR") != "" {35 lipgloss.SetColorProfile(termenv.Ascii)36 }37 38 commands := []*urfave.Command{39 cli.BuildCommand,40 cli.PrepareCommand,41 cli.InfoCommand,42 cli.PlanCommand,43 cli.SchemaCommand,44 cli.FrontendCommand,45 }46 47 // Disable the slice flag separator for all commands48 for _, command := range commands {49 command.DisableSliceFlagSeparator = true50 }51 52 cmd := &urfave.Command{53 Name: "railpack",54 Usage: "Automatically analyze and generate build plans for applications",55 EnableShellCompletion: true,56 ConfigureShellCompletionCommand: func(c *urfave.Command) {57 c.Hidden = false58 },59 Version: cli.Version,60 Flags: []urfave.Flag{61 &urfave.BoolFlag{62 Name: "verbose",63 Usage: "Enable verbose logging",64 Sources: urfave.EnvVars("RAILPACK_VERBOSE"),65 Value: false,66 Destination: &verbose,67 },68 },69 Before: func(ctx context.Context, cmd *urfave.Command) (context.Context, error) {70 configureLogging(verbose)71 72 return ctx, nil73 },74 Commands: commands,75 }76 77 if err := cmd.Run(context.Background(), os.Args); err != nil {78 log.Fatal(err)79 }80}81 82func configureLogging(verbose bool) {83 log.SetTimeFormat("")84 85 if verbose {86 log.SetLevel(log.DebugLevel)87 } else {88 log.SetLevel(log.InfoLevel)89 }90}91