[PATCH] osmo-ggsn[master]: sgsnemu: Make use of "dependon" feature in gengetopt

Harald Welte gerrit-no-reply at lists.osmocom.org
Sat Oct 14 14:39:18 UTC 2017


Review at  https://gerrit.osmocom.org/4267

sgsnemu: Make use of "dependon" feature in gengetopt

The gengetopt syntax can specify that a particular command line argument
depends on some other argument/option present.  We can use this to
provide useful feedback to the user at the command line parsing state,
like --pingrate making no sense without --pinghost being specified.

Change-Id: Ief27275e90e6bce23aed1e83874dbac98dd0926b
---
M sgsnemu/cmdline.c
M sgsnemu/cmdline.ggo
2 files changed, 57 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-ggsn refs/changes/67/4267/1

diff --git a/sgsnemu/cmdline.c b/sgsnemu/cmdline.c
index 441322b..1c02baa 100644
--- a/sgsnemu/cmdline.c
+++ b/sgsnemu/cmdline.c
@@ -676,12 +676,60 @@
 	/* checks for required options */
 
 	/* checks for dependences among options */
+	if (args_info->net_given && !args_info->createif_given) {
+		fprintf(stderr,
+			"%s: '--net' ('-n') option depends on option 'createif'%s\n",
+			prog_name, (additional_error ? additional_error : ""));
+		error_occurred = 1;
+	}
+	if (args_info->defaultroute_given && !args_info->createif_given) {
+		fprintf(stderr,
+			"%s: '--defaultroute' option depends on option 'createif'%s\n",
+			prog_name, (additional_error ? additional_error : ""));
+		error_occurred = 1;
+	}
+	if (args_info->ipup_given && !args_info->createif_given) {
+		fprintf(stderr,
+			"%s: '--ipup' option depends on option 'createif'%s\n",
+			prog_name, (additional_error ? additional_error : ""));
+		error_occurred = 1;
+	}
+	if (args_info->ipdown_given && !args_info->createif_given) {
+		fprintf(stderr,
+			"%s: '--ipdown' option depends on option 'createif'%s\n",
+			prog_name, (additional_error ? additional_error : ""));
+		error_occurred = 1;
+	}
 	if (args_info->tun_device_given && !args_info->createif_given) {
 		fprintf(stderr,
 			"%s: '--tun-device' option depends on option 'createif'%s\n",
 			prog_name, (additional_error ? additional_error : ""));
 		error_occurred = 1;
 	}
+	if (args_info->pingrate_given && !args_info->pinghost_given) {
+		fprintf(stderr,
+			"%s: '--pingrate' option depends on option 'pinghost'%s\n",
+			prog_name, (additional_error ? additional_error : ""));
+		error_occurred = 1;
+	}
+	if (args_info->pingsize_given && !args_info->pinghost_given) {
+		fprintf(stderr,
+			"%s: '--pingsize' option depends on option 'pinghost'%s\n",
+			prog_name, (additional_error ? additional_error : ""));
+		error_occurred = 1;
+	}
+	if (args_info->pingcount_given && !args_info->pinghost_given) {
+		fprintf(stderr,
+			"%s: '--pingcount' option depends on option 'pinghost'%s\n",
+			prog_name, (additional_error ? additional_error : ""));
+		error_occurred = 1;
+	}
+	if (args_info->pingquiet_given && !args_info->pinghost_given) {
+		fprintf(stderr,
+			"%s: '--pingquiet' option depends on option 'pinghost'%s\n",
+			prog_name, (additional_error ? additional_error : ""));
+		error_occurred = 1;
+	}
 
 	return error_occurred;
 }
diff --git a/sgsnemu/cmdline.ggo b/sgsnemu/cmdline.ggo
index 7592eb5..8136d3a 100644
--- a/sgsnemu/cmdline.ggo
+++ b/sgsnemu/cmdline.ggo
@@ -50,16 +50,17 @@
 option  "pwd"          p "Login password"                 string default="hemmelig" no
 
 option  "createif"     - "Create local network interface" flag   off
-option  "net"          n "Network address for local interface" string no
-option  "defaultroute" - "Create default route"           flag   off
-option  "ipup"         - "Script to run after link-up"    string no
-option  "ipdown"       - "Script to run after link-down"  string no
+option  "net"          n "Network address for local interface" string dependon="createif" no
+option  "defaultroute" - "Create default route"           flag   dependon="createif" off
+option  "ipup"         - "Script to run after link-up"    string dependon="createif" no
+option  "ipdown"       - "Script to run after link-down"  string dependon="createif" no
 option  "tun-device"   - "Name of the local network interface" string dependon="createif" no
 
 option  "pinghost"     - "Ping remote host"               string no
-option  "pingrate"     - "Number of ping req per second"  int default="1" no
-option  "pingsize"     - "Number of ping data bytes"      int default="56" no
-option  "pingcount"    - "Number of ping req to send"     int default="0" no
-option  "pingquiet"    - "Do not print ping packet info"  flag off
+option  "pingrate"     - "Number of ping req per second"  int default="1" dependon="pinghost" no
+option  "pingsize"     - "Number of ping data bytes"      int default="56" dependon="pinghost" no
+option  "pingcount"    - "Number of ping req to send"     int default="0" dependon="pinghost" no
+option  "pingquiet"    - "Do not print ping packet info"  flag dependon="pinghost" off
+
 option  "no-tx-gpdu-seq" - "Don't transmit G-PDU sequence nums"   flag    off
 option  "pdp-type"     t "PDP Type"                       string default="v4" no typestr="(v4|v6)"

-- 
To view, visit https://gerrit.osmocom.org/4267
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ief27275e90e6bce23aed1e83874dbac98dd0926b
Gerrit-PatchSet: 1
Gerrit-Project: osmo-ggsn
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>


More information about the gerrit-log mailing list