feat(cli): added more advanced date flags for BuildLog CLI
ci/woodpecker/pr/docs Pipeline was successful Details
ci/woodpecker/pr/lint Pipeline was successful Details
ci/woodpecker/pr/build Pipeline was successful Details
ci/woodpecker/pr/docker Pipeline was successful Details
ci/woodpecker/pr/test Pipeline was successful Details

Jef Roosens 2022-05-29 22:16:39 +02:00
parent 401e0291e3
commit 113dcb7a64
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
3 changed files with 48 additions and 3 deletions

View File

@ -10,8 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
* Database migrations * Database migrations
* Query parameters for GitRepo API to filter responses * Query parameters for GitRepo & BuildLog API to filter responses
* Respective CLI flags for new GitRepo API parameters * Respective CLI flags for new GitRepo & BuildLog API parameters
### Changed ### Changed

View File

@ -47,6 +47,21 @@ pub fn cmd() cli.Command {
description: 'Only list logs with non-zero exit codes.' description: 'Only list logs with non-zero exit codes.'
flag: cli.FlagType.bool 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) ? { execute: fn (cmd cli.Command) ? {
config_file := cmd.flags.get_string('config-file')? config_file := cmd.flags.get_string('config-file')?
@ -79,9 +94,37 @@ pub fn cmd() cli.Command {
}) })
filter.before = filter.after.add_days(1) 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')? { if cmd.flags.get_bool('failed')? {
filter.exit_codes = ['!0'] filter.exit_codes = [
'!0',
]
} }
list(conf, filter)? list(conf, filter)?

View File

@ -68,6 +68,8 @@ pub fn init(db_path string) ?VieterDb {
} }
} }
// row_into<T> converts an sqlite.Row into a given type T by parsing each field
// from a string according to its type.
pub fn row_into<T>(row sqlite.Row) T { pub fn row_into<T>(row sqlite.Row) T {
mut i := 0 mut i := 0
mut out := T{} mut out := T{}