Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add -l option to pkg(8) to list available commands. This is mostly for the benefit of people writing shell tab-completion scripts.
Matthew Seaman committed 13 years ago
commit 8e4cc67cffe8f0afd5c0e25651bd367e12196bbd
parent ad200b4
2 files changed +34 -3
modified pkg/main.c
@@ -105,13 +105,25 @@ struct plugcmd {

typedef int (register_cmd)(const char **name, const char **desc, int (**exec)(int argc, char **argv));

+

+
static void
+
show_command_names(void)
+
{
+
	unsigned	i;
+

+
	for(i = 0; i < cmd_len; i++)
+
		printf("%s\n", cmd[i].name);
+

+
	return;
+
}
+

static void
usage(void)
{
	struct plugcmd *c;
	bool plugins_enabled = false;
	
-
	fprintf(stderr, "usage: pkg [-v] [-d] [-j <jail name or id>|-c <chroot path>] <command> [<args>]\n\n");
+
	fprintf(stderr, "usage: pkg [-v] [-d] [-j <jail name or id>|-c <chroot path>] [-l] <command> [<args>]\n\n");
	fprintf(stderr, "Global options supported:\n");
	fprintf(stderr, "\t%-15s%s\n", "-d", "Increment debug level");
	fprintf(stderr, "\t%-15s%s\n", "-j", "Execute pkg(1) inside a jail(8)");
@@ -205,6 +217,7 @@ main(int argc, char **argv)
	int ret = EX_OK;
	const char *buf = NULL;
	bool b, plugins_enabled = false;
+
	bool show_commands = false;
	struct pkg_config_kv *kv = NULL;
	struct pkg_config_value *list = NULL;
	struct plugcmd *c;
@@ -219,7 +232,7 @@ main(int argc, char **argv)
	if (argc < 2)
		usage();

-
	while ((ch = getopt(argc, argv, "dj:c:vq")) != -1) {
+
	while ((ch = getopt(argc, argv, "dj:c:lvq")) != -1) {
		switch (ch) {
		case 'd':
			debug++;
@@ -230,6 +243,9 @@ main(int argc, char **argv)
		case 'j':
			jail_str = optarg;
			break;
+
		case 'l':
+
			show_commands = true;
+
			break;
		case 'v':
			version++;
			break;
@@ -244,6 +260,10 @@ main(int argc, char **argv)
		printf(PKGVERSION""GITHASH"\n");
		exit(EX_OK);
	}
+
	if (show_commands && version == 0) {
+
		show_command_names();
+
		exit(EX_OK);
+
	}
	if (argc == 0 && version == 0)
		usage();

modified pkg/pkg.8
@@ -15,7 +15,7 @@
.\"     @(#)pkg.8
.\" $FreeBSD$
.\"
-
.Dd June 6, 2012
+
.Dd October 19, 2012
.Dt PKG 8
.Os
.\" ---------------------------------------------------------------------------
@@ -28,6 +28,7 @@
.Nm
.Op Fl v
.Op Fl d
+
.Op Fl l
.Op Fl j Ao jail name or id Ac | Fl c Ao chroot path Ac
.Ao command Ac Ao Ar flags Ac
.\" ---------------------------------------------------------------------------
@@ -53,6 +54,16 @@ Displays the current version of
.Nm
.It Fl d
Show debug information
+
.It Fl l
+
List all the available command names, and exit without performing any
+
other action.
+
The
+
.Fl v
+
option takes precedence over
+
.Fl l
+
but
+
.Fl l
+
will override any other command line arguments. 
.It Fl j Ao jail name or id Ac
.Nm
will execute in the given