xbps-dgraph: update options to match other utils.

This commit is contained in:
Juan RP 2014-11-29 08:06:26 +01:00
parent fe9a795995
commit f890a17b84

View File

@ -32,6 +32,7 @@
#include <unistd.h> #include <unistd.h>
#include <inttypes.h> #include <inttypes.h>
#include <assert.h> #include <assert.h>
#include <getopt.h>
#include <xbps.h> #include <xbps.h>
#include "queue.h" #include "queue.h"
@ -112,14 +113,21 @@ static void __attribute__((noreturn))
usage(void) usage(void)
{ {
fprintf(stdout, fprintf(stdout,
"Usage: xbps-dgraph [options] <pkgname>\n\n" "Usage: xbps-dgraph [OPTIONS] [MODE] <pkgname>\n\n"
" Options\n" "OPTIONS\n"
" -c\t\tPath to configuration file\n" " -C --config <dir> Path to confdir (xbps.d)\n"
" -d\t\tDebug mode shown to stderr\n" " -c --graph-config <file> Path to the graph configuration file\n"
" -g\t\tGenerate a default config file\n" " -d --debug Debug mode shown to stderr\n"
" -R\t\tEnable repository mode\n" " -h --help Print help usage\n"
" -f\t\tGenerate a full dependency graph\n" " -M --memory-sync Remote repository data is fetched and stored\n"
" -r\t\t<rootdir>\n\n"); " in memory, ignoring on-disk repodata archives.\n"
" -r --rootdir <dir> Full path to rootdir\n"
" -R --repository Enable repository mode. This mode explicitly\n"
" looks for packages in repositories.\n"
"MODE\n"
" -g --gen-config Generate a configuration file\n"
" -f --fulldeptree Generate a dependency graph\n"
" -m --metadata Generate a metadata graph (default mode)\n\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -493,15 +501,36 @@ create_dot_graph(struct xbps_handle *xhp,
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
const char *shortopts = "C:c:dfghMRr:V";
const struct option longopts[] = {
{ "config", required_argument, NULL, 'C' },
{ "graph-config", required_argument, NULL, 'c' },
{ "debug", no_argument, NULL, 'd' },
{ "fulldeptree", no_argument, NULL, 'f' },
{ "gen-config", no_argument, NULL, 'g' },
{ "help", no_argument, NULL, 'h' },
{ "memory-sync", no_argument, NULL, 'M' },
{ "repository", no_argument, NULL, 'R' },
{ "rootdir", required_argument, NULL, 'r' },
{ "version", no_argument, NULL, 'V' },
{ NULL, 0, NULL, 0 },
};
xbps_dictionary_t plistd = NULL; xbps_dictionary_t plistd = NULL;
struct xbps_handle xh; struct xbps_handle xh;
FILE *f = NULL; FILE *f = NULL;
const char *conf_file = NULL, *rootdir = NULL; const char *pkg, *confdir, *conf_file, *rootdir;
int c, rv, flags = 0; int c, rv, flags = 0;
bool repomode = false, fulldepgraph = false; bool opmode, repomode, fulldepgraph, metadata;
while ((c = getopt(argc, argv, "c:dgfRr:")) != -1) { pkg = confdir = conf_file = rootdir = NULL;
opmode = repomode = fulldepgraph = metadata = false;
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
switch (c) { switch (c) {
case 'C':
/* xbps.d confdir */
confdir = optarg;
break;
case 'c': case 'c':
/* Configuration file. */ /* Configuration file. */
conf_file = optarg; conf_file = optarg;
@ -509,13 +538,19 @@ main(int argc, char **argv)
case 'd': case 'd':
flags |= XBPS_FLAG_DEBUG; flags |= XBPS_FLAG_DEBUG;
break; break;
case 'g':
/* Generate auto conf file. */
generate_conf_file();
exit(EXIT_SUCCESS);
case 'f': case 'f':
/* generate a full dependency graph */ /* generate a full dependency graph */
fulldepgraph = true; opmode = fulldepgraph = true;
break;
case 'g':
/* Generate conf file. */
generate_conf_file();
exit(EXIT_SUCCESS);
case 'M':
flags |= XBPS_FLAG_REPOS_MEMSYNC;
break;
case 'm':
opmode = metadata = true;
break; break;
case 'R': case 'R':
/* enable repository mode */ /* enable repository mode */
@ -525,6 +560,9 @@ main(int argc, char **argv)
/* Set different rootdir. */ /* Set different rootdir. */
rootdir = optarg; rootdir = optarg;
break; break;
case 'v':
printf("%s\n", XBPS_RELVER);
exit(EXIT_SUCCESS);
case '?': case '?':
default: default:
usage(); usage();
@ -534,13 +572,20 @@ main(int argc, char **argv)
argc -= optind; argc -= optind;
argv += optind; argv += optind;
if (argc != 1) if (!argc && !opmode) {
usage(); usage();
} else if (!opmode) {
/* metadata mode by default */
metadata = opmode = true;
}
pkg = *argv;
/* Initialize libxbps */ /* Initialize libxbps */
memset(&xh, 0, sizeof(xh)); memset(&xh, 0, sizeof(xh));
if (rootdir != NULL) if (rootdir != NULL)
xbps_strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir)); xbps_strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir));
if (confdir)
xbps_strlcpy(xh.confdir, confdir, sizeof(xh.confdir));
xh.flags = flags; xh.flags = flags;
if ((rv = xbps_init(&xh)) != 0) if ((rv = xbps_init(&xh)) != 0)
@ -563,12 +608,12 @@ main(int argc, char **argv)
* Internalize the plist file of the target installed package. * Internalize the plist file of the target installed package.
*/ */
if (repomode) { if (repomode) {
plistd = xbps_rpool_get_pkg(&xh, argv[0]); plistd = xbps_rpool_get_pkg(&xh, pkg);
} else { } else {
plistd = xbps_pkgdb_get_pkg(&xh, argv[0]); plistd = xbps_pkgdb_get_pkg(&xh, pkg);
} }
if (plistd == NULL) if (plistd == NULL)
die("cannot find `%s' package", argv[0]); die("cannot find `%s' package", pkg);
/* /*
* Create the output FILE. * Create the output FILE.
@ -579,10 +624,6 @@ main(int argc, char **argv)
/* /*
* Create the dot(1) graph! * Create the dot(1) graph!
*/ */
if (fulldepgraph) { create_dot_graph(&xh, f, plistd, repomode, fulldepgraph);
create_dot_graph(&xh, f, plistd, repomode, true);
} else {
create_dot_graph(&xh, f, plistd, repomode, false);
}
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }