feat: partially added filters to GitRepo CLI

This commit is contained in:
Jef Roosens 2022-05-18 08:22:13 +02:00
parent 1e079143cd
commit 5e81dadce3
Signed by untrusted user: Jef Roosens
GPG key ID: B580B976584B5F30
5 changed files with 60 additions and 6 deletions

View file

@ -5,6 +5,7 @@ import env
import cron.expression { parse_expression }
import client
import console
import db { GitRepoFilter }
struct Config {
address string [required]
@ -21,11 +22,50 @@ pub fn cmd() cli.Command {
cli.Command{
name: 'list'
description: 'List the current repos.'
flags: [
cli.Flag{
name: 'limit'
description: 'How many results to return.'
flag: cli.FlagType.int
},
cli.Flag{
name: 'offset'
description: 'Minimum index to return.'
flag: cli.FlagType.int
},
cli.Flag{
name: 'repo'
description: 'Only return Git repos that publish to this repo.'
flag: cli.FlagType.string
},
cli.Flag{
name: 'arch'
description: 'Only return repos enabled for this architecture.'
flag: cli.FlagType.string
},
]
execute: fn (cmd cli.Command) ? {
config_file := cmd.flags.get_string('config-file')?
conf := env.load<Config>(config_file)?
list(conf)?
mut filter := GitRepoFilter{}
if limit := cmd.flags.get_int('limit') {
println('limit = $limit')
filter.limit = u64(limit)
}
if offset := cmd.flags.get_int('offset') {
filter.limit = u64(offset)
}
if repo := cmd.flags.get_string('repo') {
filter.repo = repo
}
dump(filter)
list(conf, filter)?
}
},
cli.Command{
@ -133,9 +173,9 @@ pub fn cmd() cli.Command {
// ID. If multiple or none are found, an error is raised.
// list prints out a list of all repositories.
fn list(conf Config) ? {
fn list(conf Config, filter GitRepoFilter) ? {
c := client.new(conf.address, conf.api_key)
repos := c.get_git_repos()?
repos := c.get_git_repos(filter)?
data := repos.map([it.id.str(), it.url, it.branch, it.repo])
println(console.pretty_table(['id', 'url', 'branch', 'repo'], data)?)