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:
parent
d36bc967c6
commit
4c523ae459
1 changed files with 15 additions and 1 deletions
16
slag/flag.go
16
slag/flag.go
|
|
@ -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" }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue