Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Merge pull request #1153 from larsengels/pkg-alias
Baptiste Daroussin committed 11 years ago
commit 254a0345117aae6bca132306dbbc8eedd0f6cc02
parent 26757cf
2 files changed +164 -0
added docs/pkg-alias.8
@@ -0,0 +1,78 @@
+
.\"
+
.\" FreeBSD pkg - a next generation package for the installation and maintenance
+
.\" of non-core utilities.
+
.\"
+
.\" 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.
+
.\" 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.
+
.\"
+
.\"
+
.\"     @(#)pkg.8
+
.\" $FreeBSD$
+
.\"
+
.Dd January 24, 2015
+
.Dt PKG-ALIAS 8
+
.Os
+
.Sh NAME
+
.Nm "pkg alias"
+
.Nd display configured aliases
+
.Sh SYNOPSIS
+
.Nm
+
.Ar [alias]
+
.Sh DESCRIPTION
+
.Nm
+
displays configured aliases
+
If given the name of an existing alias only shows the aliased arguments to
+
.Xr pkg 8 .
+
Without arguments all aliases and their respective
+
.Xr pkg 8 .
+
arguments are printed.
+
.Sh FILES
+
.Xr pkg.conf 5
+
.Sh EXAMPLES
+
Display all aliases
+
.Dl % pkg alias
+
Display 
+
.Xr pkg 8 .
+
for alias 'size'
+
.Dl % pkg alias size
+
.Sh SEE ALSO
+
.Xr pkg_printf 3 ,
+
.Xr pkg_repos 3 ,
+
.Xr pkg-repository 5 ,
+
.Xr pkg.conf 5 ,
+
.Xr pkg 8 ,
+
.Xr pkg-add 8 ,
+
.Xr pkg-annotate 8 ,
+
.Xr pkg-audit 8 ,
+
.Xr pkg-autoremove 8 ,
+
.Xr pkg-backup 8 ,
+
.Xr pkg-check 8 ,
+
.Xr pkg-clean 8 ,
+
.Xr pkg-convert 8 ,
+
.Xr pkg-create 8 ,
+
.Xr pkg-delete 8 ,
+
.Xr pkg-fetch 8 ,
+
.Xr pkg-info 8 ,
+
.Xr pkg-install 8 ,
+
.Xr pkg-lock 8 ,
+
.Xr pkg-query 8 ,
+
.Xr pkg-register 8 ,
+
.Xr pkg-repo 8 ,
+
.Xr pkg-rquery 8 ,
+
.Xr pkg-search 8 ,
+
.Xr pkg-set 8 ,
+
.Xr pkg-shell 8 ,
+
.Xr pkg-shlib 8 ,
+
.Xr pkg-ssh 8 ,
+
.Xr pkg-stats 8 ,
+
.Xr pkg-update 8 ,
+
.Xr pkg-updating 8 ,
+
.Xr pkg-upgrade 8 ,
+
.Xr pkg-version 8 ,
+
.Xr pkg-which 8
added src/alias.c
@@ -0,0 +1,86 @@
+
/*-
+
 * Copyright (c) 2015 Lars Engels <lme@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 <sys/param.h>
+
#include <sys/sbuf.h>
+

+
#include <err.h>
+
#include <errno.h>
+
#include <libgen.h>
+
#include <stdio.h>
+
#include <string.h>
+
#include <sysexits.h>
+
#include <unistd.h>
+
#include <getopt.h>
+

+
#include <pkg.h>
+

+
#include "pkgcli.h"
+

+
void
+
usage_alias(void)
+
{
+
	fprintf(stderr, "Usage: pkg alias [alias]\n");
+
}
+

+
int
+
exec_alias(int argc, char **argv)
+
{
+
	const pkg_object *all_aliases;
+
	const pkg_object *alias;
+
	pkg_iter it = NULL;
+
	int found_alias = 0;
+

+
	if (argc > 2) {
+
		usage_alias();
+
		return(EX_USAGE);
+
	}
+

+
	all_aliases = pkg_config_get("ALIAS");
+

+
	if (argc == 2) {
+
		while ((alias = pkg_object_iterate(all_aliases, &it))) {
+
			if (strcmp(argv[1], pkg_object_key(alias)) == 0) {
+
				printf("\t%-15s -> '%s'\n", argv[1], pkg_object_string(alias));
+
				found_alias = 1;
+
				return (0);
+
			}
+
		}
+
	} else {
+
		printf("%-20s %-45s\n", "ALIAS", "ARGUMENTS");
+
		while ((alias = pkg_object_iterate(all_aliases, &it))) {
+
			printf("%-20s '%s'\n", pkg_object_key(alias), pkg_object_string(alias));
+
		}
+
	}
+

+
	if ((argc == 2) && (found_alias == 0)) {
+
		printf("No alias configured named '%s'\n", argv[1]);
+
		return(EX_USAGE);
+
	}
+

+
	return (0);
+
}
+