1
0
Fork 0
mirror of https://github.com/chainguard-dev/clog synced 2026-07-06 22:12:46 +00:00

slag: support cobra's pflag interface (#24)

Signed-off-by: Jason Hall <jason@chainguard.dev>
This commit is contained in:
Jason Hall 2024-08-11 14:59:37 -04:00 committed by GitHub
parent d36bc967c6
commit 4c523ae459
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,7 +13,18 @@
//
// $ ./myprogram -log-level=debug
//
// The slag.Level type is a wrapper around slog.Level that implements the flag.Value interface.
// The slag.Level type is a wrapper around slog.Level that implements the flag.Value interface,
// as well as Cobra's pflag.Value interface.
//
// func main() {
// var level slag.Level
// cmd := &cobra.Command{
// Use: "myprogram",
// ...
// }
// cmd.PersistentFlags().Var(&level, "log-level", "log level")
// cmd.Execute()
// }
package slag
import "log/slog"
@ -30,3 +41,6 @@ func (l *Level) Set(s string) error {
}
func (l *Level) String() string { return slog.Level(*l).String() }
func (l *Level) Level() slog.Level { return slog.Level(*l) }
// Implements https://pkg.go.dev/github.com/spf13/pflag#Value
func (l *Level) Type() string { return "string" }