From 641cf22669b8e75618b72ae8002f68c760748314 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Fri, 23 Dec 2022 08:18:49 +0100 Subject: [PATCH] feat(cli): add flag to filter logs by exit codes --- CHANGELOG.md | 1 + src/console/logs/logs.v | 15 +++++++++++++-- src/console/targets/targets.v | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e615698..3e67899 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 * Daemon for periodically removing old logs +* CLI flag to filter logs by specific exit codes ### Changed diff --git a/src/console/logs/logs.v b/src/console/logs/logs.v index 19c46f6..35ce4d7 100644 --- a/src/console/logs/logs.v +++ b/src/console/logs/logs.v @@ -24,11 +24,13 @@ pub fn cmd() cli.Command { flags: [ cli.Flag{ name: 'limit' + abbrev: 'l' description: 'How many results to return.' flag: cli.FlagType.int }, cli.Flag{ name: 'offset' + abbrev: 'o' description: 'Minimum index to return.' flag: cli.FlagType.int }, @@ -39,16 +41,18 @@ pub fn cmd() cli.Command { }, cli.Flag{ 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 }, cli.Flag{ 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 }, cli.Flag{ name: 'day' + abbrev: 'd' description: 'Only list logs started on this day. (format: YYYY-MM-DD)' 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)' 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) ! { config_file := cmd.flags.get_string('config-file')! @@ -131,6 +140,8 @@ pub fn cmd() cli.Command { filter.exit_codes = [ '!0', ] + } else { + filter.exit_codes = cmd.flags.get_strings('code')! } raw := cmd.flags.get_bool('raw')! diff --git a/src/console/targets/targets.v b/src/console/targets/targets.v index 94deebd..3c0d755 100644 --- a/src/console/targets/targets.v +++ b/src/console/targets/targets.v @@ -25,11 +25,13 @@ pub fn cmd() cli.Command { flags: [ cli.Flag{ name: 'limit' + abbrev: 'l' description: 'How many results to return.' flag: cli.FlagType.int }, cli.Flag{ name: 'offset' + abbrev: 'o' description: 'Minimum index to return.' flag: cli.FlagType.int },