From 7a29678aac20ac9e113704f8a5743f6051edef8d Mon Sep 17 00:00:00 2001 From: Timo Teras Date: Thu, 25 Jun 2009 15:14:07 +0300 Subject: help: auto construct help And add some more verbosity to the help message. --- src/add.c | 90 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 44 insertions(+), 46 deletions(-) (limited to 'src/add.c') diff --git a/src/add.c b/src/add.c index 91f9380..bc9f042 100644 --- a/src/add.c +++ b/src/add.c @@ -4,7 +4,7 @@ * Copyright (C) 2008 Timo Teräs * All rights reserved. * - * This program is free software; you can redistribute it and/or modify it + * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation. See http://www.gnu.org/ for details. */ @@ -51,49 +51,41 @@ static void md5_str(const char *str, md5sum_t csum) static int cup(void) { -/* compressed/uncompressed size is 259/1213 */ - static unsigned char z[] = { - 0x78,0x9c,0x9d,0x94,0x3d,0x8e,0xc4,0x20, - 0xc,0x85,0xfb,0x9c,0xc2,0x72,0x43,0x46, - 0x8a,0x4d,0x3f,0x67,0x89,0x64,0x77,0x2b, - 0x6d,0xbb,0x6d,0xe,0x3f,0xc6,0x84,0x4d, - 0x8,0x84,0x55,0xd6,0xa2,0xe0,0xef,0x7b, - 0x36,0xe1,0x11,0x80,0x6e,0xcc,0x53,0x7f, - 0x3e,0xc5,0xeb,0xcf,0x1d,0x20,0x22,0xcc, - 0x3c,0x53,0x8e,0x17,0xd9,0x80,0x6d,0xee, - 0xe,0x61,0x42,0x3c,0x8b,0xcf,0xc7,0x12, - 0x22,0x71,0x8b,0x31,0x5,0xd5,0xb0,0x11, - 0x4b,0xa7,0x32,0x2f,0x80,0x69,0x6b,0xb0, - 0x98,0x40,0xe2,0xcd,0xba,0x6a,0xba,0xe4, - 0x65,0xed,0x61,0x23,0x44,0xb5,0x95,0x6, - 0x8b,0xde,0x6c,0x61,0x70,0xde,0xe,0xb6, - 0xed,0xc4,0x43,0xc,0x56,0x6f,0x8f,0x31, - 0xd0,0x35,0xb5,0xc7,0x58,0x6,0xff,0x81, - 0x49,0x84,0xb8,0xe,0xb1,0xd8,0xc1,0x66, - 0x31,0xe,0x46,0x5c,0x43,0xc9,0xef,0xe5, - 0xdc,0x63,0xb1,0xdc,0x67,0x6d,0x31,0xb3, - 0xc9,0x69,0x74,0x87,0xc7,0xa3,0x1b,0x6a, - 0xb3,0xbd,0x2f,0x3b,0xd5,0xc,0x57,0x3b, - 0xce,0x7c,0x5e,0xe5,0x48,0xd0,0x48,0x1, - 0x92,0x49,0x8b,0xf7,0xfc,0x58,0x67,0xb3, - 0xf7,0x14,0x20,0x5c,0x4c,0x9e,0xcc,0xeb, - 0x78,0x7e,0x64,0xa6,0xa1,0xf5,0xb2,0x70, - 0x38,0x9,0x7c,0x7f,0xfd,0xc0,0x8a,0x4e, - 0xc8,0x55,0xe8,0x12,0xe2,0x9f,0x1a,0xb1, - 0xb9,0x82,0x52,0x2,0x7a,0xe5,0xf9,0xd9, - 0x88,0x47,0x79,0x3b,0x46,0x61,0x27,0xf9, - 0x51,0xb1,0x17,0xb0,0x2c,0xe,0xd5,0x39, - 0x2d,0x96,0x25,0x27,0xd6,0xd1,0x3f,0xa5, - 0x8,0xe1,0x9e,0x4e,0xa7,0xe9,0x3,0xb1, - 0xa,0xb6,0x75,}; + /* compressed/uncompressed size is 259/1213 */ + static unsigned char z[] = { + 0x78,0x9c,0x9d,0x94,0x3d,0x8e,0xc4,0x20,0x0c,0x85,0xfb,0x9c, + 0xc2,0x72,0x43,0x46,0x8a,0x4d,0x3f,0x67,0x89,0x64,0x77,0x2b, + 0x6d,0xbb,0x6d,0x0e,0x3f,0xc6,0x84,0x4d,0x08,0x84,0x55,0xd6, + 0xa2,0xe0,0xef,0x7b,0x36,0xe1,0x11,0x80,0x6e,0xcc,0x53,0x7f, + 0x3e,0xc5,0xeb,0xcf,0x1d,0x20,0x22,0xcc,0x3c,0x53,0x8e,0x17, + 0xd9,0x80,0x6d,0xee,0x0e,0x61,0x42,0x3c,0x8b,0xcf,0xc7,0x12, + 0x22,0x71,0x8b,0x31,0x05,0xd5,0xb0,0x11,0x4b,0xa7,0x32,0x2f, + 0x80,0x69,0x6b,0xb0,0x98,0x40,0xe2,0xcd,0xba,0x6a,0xba,0xe4, + 0x65,0xed,0x61,0x23,0x44,0xb5,0x95,0x06,0x8b,0xde,0x6c,0x61, + 0x70,0xde,0x0e,0xb6,0xed,0xc4,0x43,0x0c,0x56,0x6f,0x8f,0x31, + 0xd0,0x35,0xb5,0xc7,0x58,0x06,0xff,0x81,0x49,0x84,0xb8,0x0e, + 0xb1,0xd8,0xc1,0x66,0x31,0x0e,0x46,0x5c,0x43,0xc9,0xef,0xe5, + 0xdc,0x63,0xb1,0xdc,0x67,0x6d,0x31,0xb3,0xc9,0x69,0x74,0x87, + 0xc7,0xa3,0x1b,0x6a,0xb3,0xbd,0x2f,0x3b,0xd5,0x0c,0x57,0x3b, + 0xce,0x7c,0x5e,0xe5,0x48,0xd0,0x48,0x01,0x92,0x49,0x8b,0xf7, + 0xfc,0x58,0x67,0xb3,0xf7,0x14,0x20,0x5c,0x4c,0x9e,0xcc,0xeb, + 0x78,0x7e,0x64,0xa6,0xa1,0xf5,0xb2,0x70,0x38,0x09,0x7c,0x7f, + 0xfd,0xc0,0x8a,0x4e,0xc8,0x55,0xe8,0x12,0xe2,0x9f,0x1a,0xb1, + 0xb9,0x82,0x52,0x02,0x7a,0xe5,0xf9,0xd9,0x88,0x47,0x79,0x3b, + 0x46,0x61,0x27,0xf9,0x51,0xb1,0x17,0xb0,0x2c,0x0e,0xd5,0x39, + 0x2d,0x96,0x25,0x27,0xd6,0xd1,0x3f,0xa5,0x08,0xe1,0x9e,0x4e, + 0xa7,0xe9,0x03,0xb1,0x0a,0xb6,0x75 + }; unsigned char buf[1213]; - unsigned long len = 1213; //sizeof(buf); + unsigned long len = sizeof(buf); + uncompress(buf, &len, z, sizeof(z)); write(STDOUT_FILENO, buf, len); + return 0; } - + static int add_main(void *ctx, int argc, char **argv) { struct add_ctx *actx = (struct add_ctx *) ctx; @@ -104,21 +96,21 @@ static int add_main(void *ctx, int argc, char **argv) struct apk_dependency virtdep; int i, r; - if ((argc > 0) && (apk_verbosity > 1) && + if ((argc > 0) && (apk_verbosity > 1) && (strcmp(argv[0], "coffee") == 0)) return cup(); r = apk_db_open(&db, apk_root, actx->open_flags | APK_OPENF_WRITE); if (r != 0) return r; - + if (actx->virtpkg) { virtpkg = apk_pkg_new(); if (virtpkg == NULL) { apk_error("Failed to allocate virtual meta package"); goto err; } - virtpkg->name = apk_db_get_name(&db, APK_BLOB_STR(actx->virtpkg)); + virtpkg->name = apk_db_get_name(&db, APK_BLOB_STR(actx->virtpkg)); md5_str(virtpkg->name->name, virtpkg->csum); virtpkg->version = strdup("0"); virtpkg->description = strdup("virtual meta package"); @@ -174,15 +166,21 @@ err: return r; } -static struct option add_options[] = { - { "initdb", no_argument, NULL, 0x10000 }, - { "upgrade", no_argument, NULL, 'u' }, - { "virtual", required_argument, NULL, 't' }, +static struct apk_option add_options[] = { + { 0x10000, "initdb", "Initialize database" }, + { 'u', "upgrade", "Prefer to upgrade package" }, + { 't', "virtual", + "Instead of adding all the packages to 'world', create a new virtual " + "package with the listed dependencies and add that to 'world'. The " + "actions of the command are easily reverted by deleting the virtual " + "package.", required_argument, "NAME" }, }; static struct apk_applet apk_add = { .name = "add", - .usage = "[--initdb] [-u|--upgrade] [-t|--virtual NAME] PACKAGE...", + .help = "Add (or update) PACKAGEs to main dependencies and install " + "them, while ensuring that all dependencies are met.", + .arguments = "PACKAGE...", .context_size = sizeof(struct add_ctx), .num_options = ARRAY_SIZE(add_options), .options = add_options, -- cgit v1.2.3-60-g2f50