From: Michael Tremer Date: Fri, 20 Oct 2023 13:47:25 +0000 (+0000) Subject: cli: repos: Require distro for listing repos X-Git-Tag: 0.9.30~1408 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf4a4d8ee680cf560e3cbc541c7b03ece292f5dc;p=pakfire.git cli: repos: Require distro for listing repos Signed-off-by: Michael Tremer --- diff --git a/src/cli/lib/repo.c b/src/cli/lib/repo.c index 0ac440c1e..0cbd111f1 100644 --- a/src/cli/lib/repo.c +++ b/src/cli/lib/repo.c @@ -35,7 +35,7 @@ int cli_repo(void* data, int argc, char* argv[]) { int cli_repo_client(void* data, int argc, char* argv[]) { static const struct command commands[] = { - { "list", cli_repo_list, 0, 0, 0 }, + { "list", cli_repo_list, 1, 1, 0 }, { "show", cli_repo_show, 2, 2, 0 }, { NULL }, }; diff --git a/src/cli/lib/repo_list.c b/src/cli/lib/repo_list.c index 091e46192..fa82897ec 100644 --- a/src/cli/lib/repo_list.c +++ b/src/cli/lib/repo_list.c @@ -29,15 +29,39 @@ static const char* doc = "Lists all repositories"; +struct config { + const char* distro; +}; + +static error_t parse(int key, char* arg, struct argp_state* state, void* data) { + struct config* config = data; + + switch (key) { + case ARGP_KEY_ARG: + if (!config->distro) + config->distro = arg; + + else + argp_usage(state); + break; + + default: + return ARGP_ERR_UNKNOWN; + } + + return 0; +} + int cli_repo_list(void* data, int argc, char* argv[]) { struct pakfire_buildservice* service = NULL; struct json_object* repos = NULL; + struct config config = {}; int r; struct cli_config* cli_config = data; // Parse the command line - r = cli_parse(NULL, NULL, NULL, doc, NULL, argc, argv, NULL); + r = cli_parse(NULL, NULL, NULL, doc, parse, argc, argv, &config); if (r) goto ERROR; @@ -47,7 +71,7 @@ int cli_repo_list(void* data, int argc, char* argv[]) { goto ERROR; // List repos - r = pakfire_buildservice_list_repos(service, cli_config->distro, &repos); + r = pakfire_buildservice_list_repos(service, config.distro, &repos); if (r) goto ERROR; diff --git a/src/cli/lib/repo_show.c b/src/cli/lib/repo_show.c index a5eb9d6e0..18e18180e 100644 --- a/src/cli/lib/repo_show.c +++ b/src/cli/lib/repo_show.c @@ -57,6 +57,7 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) { return 0; } + int cli_repo_show(void* data, int argc, char* argv[]) { struct pakfire_buildservice* service = NULL; struct json_object* repo = NULL;