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

pull/206/head
Jef Roosens 2022-05-29 22:16:39 +02:00
parent 401e0291e3
commit a4ffc2c0e3
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
3 changed files with 51 additions and 7 deletions

View File

@ -10,12 +10,11 @@ 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
### Changed
* Refactor of main types into `models` module
* Improved GitRepo & BuildLog API
* Pagination using `limit` & `offset` query params
* GitRepo: filter by repo
* BuildLog: filter by start & end date, repo, exit code & arch
* CLI flags to take advantage of above API improvements
## [0.3.0-alpha.2](https://git.rustybever.be/vieter/vieter/src/tag/0.3.0-alpha.2)

View File

@ -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)?

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 {
mut i := 0
mut out := T{}