From d313c5b786d0cab578aacb158eb7a196d39a9db1 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Sun, 1 May 2022 13:06:57 +0200 Subject: [PATCH] feat(cli): added command to show detailed repo info --- src/git/cli.v | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/src/git/cli.v b/src/git/cli.v index 9ad2dc3..3a1f2e3 100644 --- a/src/git/cli.v +++ b/src/git/cli.v @@ -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_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') + } +}