From 113dcb7a64e898bc0729f02c45eba69f9b74ff29 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Sun, 29 May 2022 22:16:39 +0200 Subject: [PATCH] feat(cli): added more advanced date flags for BuildLog CLI --- CHANGELOG.md | 4 ++-- src/console/logs/logs.v | 45 ++++++++++++++++++++++++++++++++++++++++- src/db/db.v | 2 ++ 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 170c97c..eadd5f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,8 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added * Database migrations -* Query parameters for GitRepo API to filter responses -* Respective CLI flags for new GitRepo API parameters +* Query parameters for GitRepo & BuildLog API to filter responses +* Respective CLI flags for new GitRepo & BuildLog API parameters ### Changed diff --git a/src/console/logs/logs.v b/src/console/logs/logs.v index 48b9df9..3b1c756 100644 --- a/src/console/logs/logs.v +++ b/src/console/logs/logs.v @@ -47,6 +47,21 @@ pub fn cmd() cli.Command { description: 'Only list logs with non-zero exit codes.' flag: cli.FlagType.bool }, + cli.Flag{ + name: 'day' + description: 'Only list logs started on this day. Format is YYYY-MM-DD.' + flag: cli.FlagType.string + }, + cli.Flag{ + name: 'before' + description: 'Only list logs started before this timestamp. Accepts any RFC 3339 date.' + flag: cli.FlagType.string + }, + cli.Flag{ + name: 'after' + description: 'Only list logs started after this timestamp. Accepts any RFC 3339 date.' + flag: cli.FlagType.string + }, ] execute: fn (cmd cli.Command) ? { config_file := cmd.flags.get_string('config-file')? @@ -79,9 +94,37 @@ pub fn cmd() cli.Command { }) filter.before = filter.after.add_days(1) } + // The -today flag overwrites any of the other date flags. + else { + day_str := cmd.flags.get_string('day')? + before_str := cmd.flags.get_string('before')? + after_str := cmd.flags.get_string('after')? + + if day_str != '' { + day := time.parse_rfc3339(day_str)? + + filter.after = time.new_time(time.Time{ + year: day.year + month: day.month + day: day.day + }) + + filter.before = filter.after.add_days(1) + } else { + if before_str != '' { + filter.before = time.parse_rfc3339(before_str)? + } + + if after_str != '' { + filter.after = time.parse_rfc3339(after_str)? + } + } + } if cmd.flags.get_bool('failed')? { - filter.exit_codes = ['!0'] + filter.exit_codes = [ + '!0', + ] } list(conf, filter)? diff --git a/src/db/db.v b/src/db/db.v index d6cc057..fac1458 100644 --- a/src/db/db.v +++ b/src/db/db.v @@ -68,6 +68,8 @@ pub fn init(db_path string) ?VieterDb { } } +// row_into converts an sqlite.Row into a given type T by parsing each field +// from a string according to its type. pub fn row_into(row sqlite.Row) T { mut i := 0 mut out := T{}