Radish alpha
H
HardenedBSD Package Manager
Radicle
Git (anonymous pull)
Log in to clone via SSH
New subcommand config to query the configuration options
Baptiste Daroussin committed 12 years ago
commit c24a6753e6027c2a20b9ce083c883d377e65f551
parent 9003d30c1e2b87ff8dda7a6225ce4c5fa20d85fa
6 files changed +123 -0
modified libpkg/pkg.h.in
@@ -1187,6 +1187,7 @@ int pkg_configs(struct pkg_config **c);
int pkg_config_id(struct pkg_config *c);
int pkg_config_type(struct pkg_config *c);
const char *pkg_config_name(struct pkg_config *c);
+
struct pkg_config *pkg_config_lookup(const char *name);

/**
 * @todo Document
modified libpkg/pkg_config.c
@@ -1112,6 +1112,19 @@ pkg_init(const char *path)
	return (EPKG_OK);
}

+
struct pkg_config *
+
pkg_config_lookup(const char *name)
+
{
+
	struct pkg_config *conf;
+

+
	if (name == NULL)
+
		return (NULL);
+

+
	HASH_FIND(hhkey, config_by_key, name, strlen(name), conf);
+

+
	return (conf);
+
}
+

static void
pkg_config_kv_free(struct pkg_config_kv *k)
{
modified pkg/Makefile
@@ -6,6 +6,7 @@ SRCS= add.c \
		backup.c \
		check.c \
		clean.c \
+
		config.c \
		convert.c \
		create.c \
		delete.c \
added pkg/config.c
@@ -0,0 +1,103 @@
+
/*-
+
 * Copyright (c) 2013 Baptiste Daroussin <bapt@FreeBSD.org>
+
 * All rights reserved.
+
 * 
+
 * Redistribution and use in source and binary forms, with or without
+
 * modification, are permitted provided that the following conditions
+
 * are met:
+
 * 1. Redistributions of source code must retain the above copyright
+
 *    notice, this list of conditions and the following disclaimer
+
 *    in this position and unchanged.
+
 * 2. Redistributions in binary form must reproduce the above copyright
+
 *    notice, this list of conditions and the following disclaimer in the
+
 *    documentation and/or other materials provided with the distribution.
+
 * 
+
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+
 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
 */
+

+
#include <ctype.h>
+
#include <err.h>
+
#include <inttypes.h>
+
#include <stdio.h>
+
#include <sysexits.h>
+
#include <libutil.h>
+

+
#include <pkg.h>
+

+
#include "pkgcli.h"
+

+
void
+
usage_config(void)
+
{
+
	fprintf(stderr,
+
            "usage: pkg config <configname>\n\n");
+
	fprintf(stderr,
+
            "For more information see 'pkg help config'.\n");
+
}
+

+
int
+
exec_config(int argc, char **argv)
+
{
+
	struct pkg_config *conf;
+
	struct pkg_config_value *list;
+
	struct pkg_config_kv *kv;
+
	const char *buf;
+
	char *key;
+
	int64_t integer;
+
	int i;
+
	bool b;
+

+
	if (argc != 2) {
+
		usage_config();
+
		return (EX_USAGE);
+
	}
+

+
	key = argv[1];
+
	for (i = 0; key[i] != '\0'; i++)
+
		key[i] = toupper(key[i]);
+

+
	conf = pkg_config_lookup(key);
+
	if (conf == NULL) {
+
		warnx("No such configuration options: %s", key);
+
		return (EX_SOFTWARE);
+
	}
+

+
	switch (pkg_config_type(conf)) {
+
	case PKG_CONFIG_STRING:
+
		pkg_config_string(pkg_config_id(conf), &buf);
+
		printf("%s\n", buf == NULL ? "" : buf);
+
		break;
+
	case PKG_CONFIG_BOOL:
+
		pkg_config_bool(pkg_config_id(conf), &b);
+
		printf("%s\n", b ? "yes" : "no");
+
		break;
+
	case PKG_CONFIG_INTEGER:
+
		pkg_config_int64(pkg_config_id(conf), &integer);
+
		printf("%"PRId64"\n", integer);
+
		break;
+
	case PKG_CONFIG_KVLIST:
+
		kv = NULL;
+
		while (pkg_config_kvlist(pkg_config_id(conf), &kv) == EPKG_OK) {
+
			printf("%s: %s", pkg_config_kv_get(kv, PKG_CONFIG_KV_KEY),
+
			    pkg_config_kv_get(kv, PKG_CONFIG_KV_VALUE));
+
		}
+
		break;
+
	case PKG_CONFIG_LIST:
+
		list = NULL;
+
		while (pkg_config_list(pkg_config_id(conf), &list) == EPKG_OK) {
+
			printf("%s\n", pkg_config_value(list));
+
		}
+
		break;
+
	}
+

+
	return (EX_OK);
+
}
modified pkg/main.c
@@ -70,6 +70,7 @@ static struct commands {
	{ "backup", "Backs-up and restores the local package database", exec_backup, usage_backup},
	{ "check", "Checks for missing dependencies and database consistency", exec_check, usage_check},
	{ "clean", "Cleans old packages from the cache", exec_clean, usage_clean},
+
	{ "config", "Display the value of the configuration options", exec_config, usage_config},
	{ "convert", "Convert database from/to pkgng", exec_convert, usage_convert},
	{ "create", "Creates software package distributions", exec_create, usage_create},
	{ "delete", "Deletes packages from the database and the system", exec_delete, usage_delete},
modified pkg/pkgcli.h
@@ -172,6 +172,10 @@ void usage_convert(void);
int exec_ssh(int, char **);
void usage_ssh(void);

+
/* pkg config */
+
int exec_config(int, char **);
+
void usage_config(void);
+

/* utils */

/* These are the fields of the Full output, in order */