[cowdancer] 01/01: parameter: Accept aliases for the operation to perform
James Clarke
jrtc27 at moszumanska.debian.org
Tue Jan 17 21:33:10 UTC 2017
This is an automated email from the git hooks/post-receive script.
jrtc27 pushed a commit to branch master
in repository cowdancer.
commit 9e38d69ca473301df043a2b62d1643072ad4e6f1
Author: James Clarke <jrtc27 at debian.org>
Date: Tue Jan 17 21:31:16 2017 +0000
parameter: Accept aliases for the operation to perform
This also means the operation must be specified as the first argument.
This shouldn't be a problem, since pbuilder already requires this.
---
parameter.c | 77 ++++++++++++++++++++++++++++---
parameter.h | 23 +++++----
tests/101_test_qemubuilder_dumpconfig.sh | 4 +-
tests/102_test_cowbuilder_debbuildopts.sh | 6 +--
4 files changed, 88 insertions(+), 22 deletions(-)
diff --git a/parameter.c b/parameter.c
index 6f7b886..6f2039f 100644
--- a/parameter.c
+++ b/parameter.c
@@ -29,6 +29,11 @@
#include "parameter.h"
#include <assert.h>
+struct pbuilder_operation_arg {
+ const char* arg;
+ enum pbuilder_operation operation;
+};
+
/*
The pbuilder command-line to pass
@@ -383,11 +388,48 @@ int parse_parameter(int ac, char** av,
const char* keyword)
{
int c; /* option */
+ int i;
int index_point;
int config_ok = -1, load_ok;
char * cmdstr=NULL;
static pbuilderconfig pc;
+ static const struct pbuilder_operation_arg operations[] =
+ {
+ {"--create", pbuilder_create},
+ {"create", pbuilder_create},
+
+ {"--update", pbuilder_update},
+ {"update", pbuilder_update},
+ {"up", pbuilder_update},
+ {"u", pbuilder_update},
+
+ {"--build", pbuilder_build},
+ {"build", pbuilder_build},
+ {"b", pbuilder_build},
+
+ {"--login", pbuilder_login},
+ {"login", pbuilder_login},
+ {"l", pbuilder_login},
+
+ {"--execute", pbuilder_execute},
+ {"execute", pbuilder_execute},
+ {"e", pbuilder_execute},
+
+ {"--dumpconfig", pbuilder_dumpconfig},
+ {"dumpconfig", pbuilder_dumpconfig},
+
+ {"--help", pbuilder_help},
+ {"help", pbuilder_help},
+ {"h", pbuilder_help},
+ {"--version", pbuilder_help},
+ {"version", pbuilder_help},
+ {"-v", pbuilder_help},
+ {"v", pbuilder_help},
+
+ {NULL, pbuilder_do_nothing}
+ };
+
static struct option long_options[]=
{
{"basepath", required_argument, 0, 'b'},
@@ -400,13 +442,7 @@ int parse_parameter(int ac, char** av,
{"nomountdevpts", no_argument, &(pc.mountdevpts), 0},
{"save-after-login", no_argument, &(pc.save_after_login), 1},
{"save-after-exec", no_argument, &(pc.save_after_login), 1},
- {"build", no_argument, (int*)&(pc.operation), pbuilder_build},
- {"create", no_argument, (int*)&(pc.operation), pbuilder_create},
- {"update", no_argument, (int*)&(pc.operation), pbuilder_update},
- {"login", no_argument, (int*)&(pc.operation), pbuilder_login},
- {"execute", no_argument, (int*)&(pc.operation), pbuilder_execute},
{"help", no_argument, (int*)&(pc.operation), pbuilder_help},
- {"dumpconfig", no_argument, (int*)&(pc.operation), pbuilder_dumpconfig},
{"version", no_argument, 0, 'v'},
{"debug", no_argument, 0, 0},
{"loglevel", required_argument, 0, 0},
@@ -490,6 +526,33 @@ int parse_parameter(int ac, char** av,
if( load_ok > 1 ) exit( 4 );
if( config_ok != 0 ) config_ok = load_ok;
+ if (ac >= 2)
+ {
+ for (i = 0; operations[i].arg; ++i)
+ {
+ if (!strcmp(av[1], operations[i].arg))
+ {
+ pc.operation = operations[i].operation;
+ break;
+ }
+ }
+
+ if (pc.operation == pbuilder_do_nothing)
+ {
+ log_printf(log_error, "Unknown operation: %s", av[1]);
+ return 1;
+ }
+ }
+ else
+ {
+ log_printf(log_error, "No operation specified");
+ return 1;
+ }
+
+ --ac;
+ av[1] = av[0];
+ ++av;
+
#define PASS_TO_PBUILDER_WITH_PARAM PBUILDER_ADD_PARAM(cmdstr); \
PBUILDER_ADD_PARAM(strdup(optarg));
@@ -844,7 +907,7 @@ int parse_parameter(int ac, char** av,
return cpbuilder_dumpconfig(&pc);
default:
- log_printf(log_error, "No operation specified");
+ log_printf(log_error, "Internal error: Unknown operation (%d)", pc.operation);
return 1;
}
diff --git a/parameter.h b/parameter.h
index fac1af0..7260e35 100644
--- a/parameter.h
+++ b/parameter.h
@@ -24,6 +24,18 @@
#define MAX_CUSTOM_FILES 32
+enum pbuilder_operation
+{
+ pbuilder_do_nothing=0,
+ pbuilder_help,
+ pbuilder_build,
+ pbuilder_create,
+ pbuilder_update,
+ pbuilder_execute,
+ pbuilder_login,
+ pbuilder_dumpconfig
+};
+
typedef struct pbuilderconfig
{
/* if you edit here, please add to parameter.c: dumpconfig */
@@ -69,16 +81,7 @@ typedef struct pbuilderconfig
char* arch;
char* arch_diskdevice;
- enum {
- pbuilder_do_nothing=0,
- pbuilder_help,
- pbuilder_build,
- pbuilder_create,
- pbuilder_update,
- pbuilder_execute,
- pbuilder_login,
- pbuilder_dumpconfig
- } operation;
+ enum pbuilder_operation operation;
} pbuilderconfig;
int load_config_file(const char* config, pbuilderconfig* pc);
diff --git a/tests/101_test_qemubuilder_dumpconfig.sh b/tests/101_test_qemubuilder_dumpconfig.sh
index b280143..85f094b 100755
--- a/tests/101_test_qemubuilder_dumpconfig.sh
+++ b/tests/101_test_qemubuilder_dumpconfig.sh
@@ -5,6 +5,6 @@
# die of error, so we need to have qemubuilder installed.
set -ex
-[ "$(./qemubuilder --inputfile one --inputfile two --dumpconfig | grep inputfile)" = \
+[ "$(./qemubuilder --dumpconfig --inputfile one --inputfile two | grep inputfile)" = \
" inputfile[0]: one
- inputfile[1]: two" ]
\ No newline at end of file
+ inputfile[1]: two" ]
diff --git a/tests/102_test_cowbuilder_debbuildopts.sh b/tests/102_test_cowbuilder_debbuildopts.sh
index 467ada7..624665a 100755
--- a/tests/102_test_cowbuilder_debbuildopts.sh
+++ b/tests/102_test_cowbuilder_debbuildopts.sh
@@ -6,8 +6,8 @@ set -ex
CONFIGFILE=tests/102_test_cowbuilder_debbuildopts.config
-[ "$(./cowbuilder --configfile ${CONFIGFILE} --dumpconfig | grep debbuildopts:)" = \
+[ "$(./cowbuilder --dumpconfig --configfile ${CONFIGFILE} | grep debbuildopts:)" = \
" debbuildopts: -j2 -I" ]
-[ "$(./cowbuilder --configfile ${CONFIGFILE} --dumpconfig | grep kernel_image:)" = \
- " kernel_image: /boot/vmlinuz-x.y.z" ]
\ No newline at end of file
+[ "$(./cowbuilder --dumpconfig --configfile ${CONFIGFILE} | grep kernel_image:)" = \
+ " kernel_image: /boot/vmlinuz-x.y.z" ]
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pbuilder/cowdancer.git
More information about the Pbuilder-maint
mailing list