@@ -2,6 +2,8 @@ package cmd
22
33import (
44 "context"
5+ "log/slog"
6+ "os"
57
68 "github.com/coreruleset/albedo/server"
79 "github.com/spf13/cobra"
@@ -18,19 +20,23 @@ func NewRootCommand() *cobra.Command {
1820 Short : "HTTP reflector and black hole" ,
1921 RunE : runE ,
2022 }
21- port := new (int )
22- binding := new (string )
23- rootCmd .PersistentFlags ().IntVarP (port , "port" , "p" , 8080 , "port to listen on" )
24- rootCmd .PersistentFlags ().StringVarP (binding , "bind" , "b" , "0.0.0.0" , "address to bind to" )
23+ rootCmd .PersistentFlags ().IntP ("port" , "p" , 8080 , "port to listen on" )
24+ rootCmd .PersistentFlags ().StringP ("bind" , "b" , "0.0.0.0" , "address to bind to" )
25+ rootCmd .PersistentFlags ().Bool ("debug" , false , "Log debugging information" )
2526
2627 return rootCmd
2728}
2829
2930func runE (cmd * cobra.Command , _ []string ) error {
3031 port , _ := cmd .Flags ().GetInt ("port" )
3132 binding , _ := cmd .Flags ().GetString ("bind" )
33+ debug , _ := cmd .Flags ().GetBool ("debug" )
34+ if debug {
35+ handler := slog .NewTextHandler (os .Stdout , & slog.HandlerOptions {Level : slog .LevelDebug })
36+ logger := slog .New (handler )
37+ slog .SetDefault (logger )
38+ }
3239
33- _ = server .Start (binding , port )
34-
40+ server .Start (binding , port )
3541 return nil
3642}
0 commit comments