Files
pack/cmd/cli/main.go
T
Michael BiancoandGitHub a35128351b fix: --verbose enables mise verbose logging (#248)
* build: add bin/ to $PATH for local railpack usage

this is helpful when needing or run a local `railpack` build, without mise,
to avoid injecting mise environment variables.

* fix: support NO_COLOR

* fix: enable MISE_VERBOSE when --verbose is enabled

* fix: case insensitive truthy environment vars

* docs: helpful railpack dev tips
2025-09-03 16:17:30 -06:00

87 lines
1.8 KiB
Go

package main
import (
"context"
"os"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/log"
"github.com/muesli/termenv"
"github.com/railwayapp/railpack/cli"
urfave "github.com/urfave/cli/v3"
)
var (
verbose bool
version = "dev" // This will be overwritten by goreleaser
)
func main() {
cli.Version = version
logger := log.Default()
logger.SetTimeFormat("")
urfaveLogWriter := logger.StandardLog(log.StandardLogOptions{
ForceLevel: log.ErrorLevel,
}).Writer()
urfave.ErrWriter = urfaveLogWriter
if os.Getenv("FORCE_COLOR") != "" {
lipgloss.SetColorProfile(termenv.TrueColor)
}
// https://no-color.org
if os.Getenv("NO_COLOR") != "" {
lipgloss.SetColorProfile(termenv.Ascii)
}
commands := []*urfave.Command{
cli.BuildCommand,
cli.PrepareCommand,
cli.InfoCommand,
cli.PlanCommand,
cli.SchemaCommand,
cli.FrontendCommand,
}
// Disable the slice flag separator for all commands
for _, command := range commands {
command.DisableSliceFlagSeparator = true
}
cmd := &urfave.Command{
Name: "railpack",
Usage: "Automatically analyze and generate build plans for applications",
EnableShellCompletion: true,
Version: cli.Version,
Flags: []urfave.Flag{
&urfave.BoolFlag{
Name: "verbose",
Usage: "Enable verbose logging",
Value: false,
Destination: &verbose,
},
},
Before: func(ctx context.Context, cmd *urfave.Command) (context.Context, error) {
configureLogging(verbose)
return ctx, nil
},
Commands: commands,
}
if err := cmd.Run(context.Background(), os.Args); err != nil {
log.Fatal(err)
}
}
func configureLogging(verbose bool) {
log.SetTimeFormat("")
if verbose {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}
}