feat(cli): add flag to filter logs by exit codes

web-stuff
Jef Roosens 2022-12-23 08:18:49 +01:00
parent 3342eedfa4
commit 641cf22669
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
3 changed files with 16 additions and 2 deletions

View File

@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* API route for removing logs & accompanying CLI command * API route for removing logs & accompanying CLI command
* Daemon for periodically removing old logs * Daemon for periodically removing old logs
* CLI flag to filter logs by specific exit codes
### Changed ### Changed

View File

@ -24,11 +24,13 @@ pub fn cmd() cli.Command {
flags: [ flags: [
cli.Flag{ cli.Flag{
name: 'limit' name: 'limit'
abbrev: 'l'
description: 'How many results to return.' description: 'How many results to return.'
flag: cli.FlagType.int flag: cli.FlagType.int
}, },
cli.Flag{ cli.Flag{
name: 'offset' name: 'offset'
abbrev: 'o'
description: 'Minimum index to return.' description: 'Minimum index to return.'
flag: cli.FlagType.int flag: cli.FlagType.int
}, },
@ -39,16 +41,18 @@ pub fn cmd() cli.Command {
}, },
cli.Flag{ cli.Flag{
name: 'today' name: 'today'
description: 'Only list logs started today.' abbrev: 't'
description: 'Only list logs started today. This flag overwrites any other date-related flag.'
flag: cli.FlagType.bool flag: cli.FlagType.bool
}, },
cli.Flag{ cli.Flag{
name: 'failed' name: 'failed'
description: 'Only list logs with non-zero exit codes.' description: 'Only list logs with non-zero exit codes. This flag overwrites the --code flag.'
flag: cli.FlagType.bool flag: cli.FlagType.bool
}, },
cli.Flag{ cli.Flag{
name: 'day' name: 'day'
abbrev: 'd'
description: 'Only list logs started on this day. (format: YYYY-MM-DD)' description: 'Only list logs started on this day. (format: YYYY-MM-DD)'
flag: cli.FlagType.string flag: cli.FlagType.string
}, },
@ -62,6 +66,11 @@ pub fn cmd() cli.Command {
description: 'Only list logs started after this timestamp. (format: YYYY-MM-DD HH:mm:ss)' description: 'Only list logs started after this timestamp. (format: YYYY-MM-DD HH:mm:ss)'
flag: cli.FlagType.string flag: cli.FlagType.string
}, },
cli.Flag{
name: 'code'
description: 'Only return logs with the given exit code. Prepend with `!` to exclude instead of include. Can be specified multiple times.'
flag: cli.FlagType.string_array
},
] ]
execute: fn (cmd cli.Command) ! { execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')! config_file := cmd.flags.get_string('config-file')!
@ -131,6 +140,8 @@ pub fn cmd() cli.Command {
filter.exit_codes = [ filter.exit_codes = [
'!0', '!0',
] ]
} else {
filter.exit_codes = cmd.flags.get_strings('code')!
} }
raw := cmd.flags.get_bool('raw')! raw := cmd.flags.get_bool('raw')!

View File

@ -25,11 +25,13 @@ pub fn cmd() cli.Command {
flags: [ flags: [
cli.Flag{ cli.Flag{
name: 'limit' name: 'limit'
abbrev: 'l'
description: 'How many results to return.' description: 'How many results to return.'
flag: cli.FlagType.int flag: cli.FlagType.int
}, },
cli.Flag{ cli.Flag{
name: 'offset' name: 'offset'
abbrev: 'o'
description: 'Minimum index to return.' description: 'Minimum index to return.'
flag: cli.FlagType.int flag: cli.FlagType.int
}, },