]> git.ipfire.org Git - pakfire.git/commitdiff
cli: repos: Require distro for listing repos
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 20 Oct 2023 13:47:25 +0000 (13:47 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 20 Oct 2023 13:47:25 +0000 (13:47 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/lib/repo.c
src/cli/lib/repo_list.c
src/cli/lib/repo_show.c

index 0ac440c1ef3b5d830c08a825b0ad1ed652fadb3a..0cbd111f13a993e3d462c41e00f45f05781a2e8f 100644 (file)
@@ -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 },
        };
index 091e46192cf07b929302c612c5b451ca8ae07889..fa82897eca8d337976c2ea224b04bd6e4f4fe44b 100644 (file)
 
 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;
 
index a5eb9d6e08287e41a0b23514575a5ae84b270ef5..18e18180eda75de9c46230b73dc2c0e8e4e460c5 100644 (file)
@@ -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;