-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
By default, if a path does not match any formatter a log message at WARN level will be emitted. A user can change this by providing the `--on-unmatched` or `-u` flag and specifying a log level `debug,info,warn,error,fatal`. If fatal, the process will exit with an error on the first unmatched path encountered. Closes #302 Signed-off-by: Brian McGee <brian@bmcgee.ie>
- Loading branch information
1 parent
6cf9524
commit 1b517c6
Showing
7 changed files
with
124 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
|
||
"github.com/alecthomas/kong" | ||
"github.com/charmbracelet/log" | ||
) | ||
|
||
var Options []kong.Option | ||
|
||
func init() { | ||
Options = []kong.Option{ | ||
kong.TypeMapper(reflect.TypeOf(log.DebugLevel), logLevelDecoder()), | ||
} | ||
} | ||
|
||
func logLevelDecoder() kong.MapperFunc { | ||
return func(ctx *kong.DecodeContext, target reflect.Value) error { | ||
t, err := ctx.Scan.PopValue("string") | ||
if err != nil { | ||
return err | ||
} | ||
var str string | ||
switch v := t.Value.(type) { | ||
case string: | ||
str = v | ||
default: | ||
return fmt.Errorf("expected a string but got %q (%T)", t, t.Value) | ||
} | ||
level, err := log.ParseLevel(str) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse '%v' as log level: %w", level, err) | ||
} | ||
target.Set(reflect.ValueOf(level)) | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters