Skip to content

Commit

Permalink
add --debug flag
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiwara committed Jul 3, 2024
1 parent c1c8810 commit 6417015
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 4 additions & 2 deletions cmd/awslim/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ package main

import (
"context"
"log"
"log/slog"
"os"

app "github.com/fujiwara/awslim"
)

func main() {
ctx := context.TODO()
if err := run(ctx); err != nil {
log.Fatal(err)
slog.Error(err.Error())
os.Exit(1)
}
}

Expand Down
14 changes: 11 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ var LogLevel = new(slog.LevelVar)
func init() {
opts := &slog.HandlerOptions{Level: LogLevel}
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, opts)))
if os.Getenv("DEBUG") != "" {
LogLevel.Set(slog.LevelDebug)
}
}

var Version = "HEAD"
Expand Down Expand Up @@ -58,12 +55,23 @@ type CLI struct {

DryRun bool `short:"n" help:"dry-run mode"`
Version bool `short:"v" help:"show version"`
Debug bool `help:"turn on debug logging"`

w io.Writer
rc *RuntimeConfig
}

func enableDebug(args []string) {
for _, arg := range args {
if arg == "--debug" {
LogLevel.Set(slog.LevelDebug)
return
}
}
}

func Run(ctx context.Context) error {
enableDebug(os.Args[1:])
var c CLI
if rc, err := loadRuntimeConfig(); err != nil {
return fmt.Errorf("failed to load runtime config: %w", err)
Expand Down

0 comments on commit 6417015

Please sign in to comment.