feat(cli): added command to show detailed repo info

cli-docs
Jef Roosens 2022-05-01 13:06:57 +02:00
parent 92b8f1fb93
commit d313c5b786
Signed by untrusted user: Jef Roosens
GPG Key ID: B75D4F293C7052DB
1 changed files with 33 additions and 9 deletions

View File

@ -49,6 +49,18 @@ pub fn cmd() cli.Command {
remove(conf, cmd.args[0]) ?
}
},
cli.Command{
name: 'info'
required_args: 1
usage: 'id'
description: 'Show detailed information for the repo matching the ID prefix.'
execute: fn (cmd cli.Command) ? {
config_file := cmd.flags.get_string('config-file') ?
conf := env.load<Config>(config_file) ?
info(conf, cmd.args[0]) ?
}
},
cli.Command{
name: 'edit'
required_args: 1
@ -102,16 +114,16 @@ pub fn cmd() cli.Command {
}
}
// get_repo_id_by_prefix tries to find the repo with the given prefix in its
// get_repo_by_prefix tries to find the repo with the given prefix in its
// ID. If multiple or none are found, an error is raised.
fn get_repo_id_by_prefix(conf Config, id_prefix string) ?string {
fn get_repo_by_prefix(conf Config, id_prefix string) ?(string, GitRepo) {
repos := get_repos(conf.address, conf.api_key) ?
mut res := []string{}
mut res := map[string]GitRepo{}
for id, _ in repos {
for id, repo in repos {
if id.starts_with(id_prefix) {
res << id
res[id] = repo
}
}
@ -123,7 +135,7 @@ fn get_repo_id_by_prefix(conf Config, id_prefix string) ?string {
return error('Multiple repos found for given prefix.')
}
return res[0]
return res.keys()[0], res[res.keys()[0]]
}
// list prints out a list of all repositories.
@ -131,7 +143,7 @@ fn list(conf Config) ? {
repos := get_repos(conf.address, conf.api_key) ?
for id, details in repos {
println('${id[..8]}\t$details.url\t$details.branch\t$details.repo\t$details.arch\t$details.schedule')
println('${id[..8]}\t$details.url\t$details.branch\t$details.repo')
}
}
@ -144,7 +156,7 @@ fn add(conf Config, url string, branch string, repo string) ? {
// remove removes a repository from the server's list.
fn remove(conf Config, id_prefix string) ? {
id := get_repo_id_by_prefix(conf, id_prefix) ?
id, _ := get_repo_by_prefix(conf, id_prefix) ?
res := remove_repo(conf.address, conf.api_key, id) ?
println(res.message)
@ -160,8 +172,20 @@ fn patch(conf Config, id_prefix string, params map[string]string) ? {
}
}
id := get_repo_id_by_prefix(conf, id_prefix) ?
id, _ := get_repo_by_prefix(conf, id_prefix) ?
res := patch_repo(conf.address, conf.api_key, id, params) ?
println(res.message)
}
// info shows detailed information for a given repo.
fn info(conf Config, id_prefix string) ? {
id, repo := get_repo_by_prefix(conf, id_prefix) ?
println('id: $id')
$for field in GitRepo.fields {
val := repo.$(field.name)
println('$field.name: $val')
}
}