cli: implement --size
authorJo-Philipp Wich <jo@mein.io>
Fri, 10 Feb 2017 09:57:45 +0000 (10:57 +0100)
committerJo-Philipp Wich <jo@mein.io>
Fri, 10 Feb 2017 09:57:45 +0000 (10:57 +0100)
Implement a new switch "--size" which causes opkg to print the package size
in the listing output.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
libopkg/opkg_cmd.c
libopkg/opkg_conf.c
libopkg/opkg_conf.h
src/opkg-cl.c

index 60ffee3e25de51c4d4502bfac4a52b7905e58cf3..fa434784437cb2c6f35073d1cde48330020bfc7d 100644 (file)
@@ -47,10 +47,12 @@ static void
 print_pkg(pkg_t *pkg)
 {
        char *version = pkg_version_str_alloc(pkg);
+       printf("%s - %s", pkg->name, version);
+       if (conf->size)
+               printf(" - %lu", pkg->size);
        if (pkg->description)
-               printf("%s - %s - %s\n", pkg->name, version, pkg->description);
-       else
-               printf("%s - %s\n", pkg->name, version);
+               printf(" - %s", pkg->description);
+       printf("\n");
        free(version);
 }
 
index ee32b23827afd50fe037cfdaabde96166c38e1cd..3a99935b619d58de3cb6603d8cb37b15315b3526 100644 (file)
@@ -69,6 +69,7 @@ opkg_option_t options[] = {
          { "proxy_passwd", OPKG_OPT_TYPE_STRING, &_conf.proxy_passwd },
          { "proxy_user", OPKG_OPT_TYPE_STRING, &_conf.proxy_user },
          { "query-all", OPKG_OPT_TYPE_BOOL, &_conf.query_all },
+         { "size", OPKG_OPT_TYPE_BOOL, &_conf.size },
          { "tmp_dir", OPKG_OPT_TYPE_STRING, &_conf.tmp_dir },
          { "verbosity", OPKG_OPT_TYPE_INT, &_conf.verbosity },
 #if defined(HAVE_OPENSSL)
index ca77c88fb914b0647c1453430640cd0cb380a655..ab629eab1093ce61f9e6ef89b1813ba0b56ae183 100644 (file)
@@ -88,6 +88,7 @@ struct opkg_conf
      int query_all;
      int verbosity;
      int noaction;
+     int size;
      int download_only;
      char *cache;
 
index d70ad50d9e3b41e5d9fe0298a3fdf6b09bae2135..8a395789b313d8a1e30d1140074e88c29da60a32 100644 (file)
@@ -52,6 +52,7 @@ enum {
        ARGS_OPT_AUTOREMOVE,
        ARGS_OPT_CACHE,
        ARGS_OPT_FORCE_SIGNATURE,
+       ARGS_OPT_SIZE,
 };
 
 static struct option long_options[] = {
@@ -98,6 +99,7 @@ static struct option long_options[] = {
        {"offline-root", 1, 0, 'o'},
        {"add-arch", 1, 0, ARGS_OPT_ADD_ARCH},
        {"add-dest", 1, 0, ARGS_OPT_ADD_DEST},
+       {"size", 0, 0, ARGS_OPT_SIZE},
        {"test", 0, 0, ARGS_OPT_NOACTION},
        {"tmp-dir", 1, 0, 't'},
        {"tmp_dir", 1, 0, 't'},
@@ -212,6 +214,9 @@ args_parse(int argc, char *argv[])
                        }
                        free(tuple);
                        break;
+               case ARGS_OPT_SIZE:
+                       conf->size = 1;
+                       break;
                case ARGS_OPT_NOACTION:
                        conf->noaction = 1;
                        break;
@@ -315,6 +320,7 @@ usage()
        printf("\t--download-only       No action -- download only\n");
        printf("\t--nodeps              Do not follow dependencies\n");
        printf("\t--nocase              Perform case insensitive pattern matching\n");
+       printf("\t--size                        Print package size when listing available packages\n");
        printf("\t--force-removal-of-dependent-packages\n");
        printf("\t                      Remove package and all dependencies\n");
        printf("\t--autoremove          Remove packages that were installed\n");