summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2015-11-23 22:47:43 +0800
committerMatt Johnston <matt@ucc.asn.au>2015-11-23 22:47:43 +0800
commit6f5abeff2e13bd8051d7d7372eb75d7c55c85464 (patch)
treef8e0f62ddcf6d1d52be3b32bb62cab174409745d
parent7cbf6b131b8053a1735bb6229be629b1e9af591d (diff)
Fix flags after the hostname
-rw-r--r--cli-runopts.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/cli-runopts.c b/cli-runopts.c
index f6220bf..e8cb313 100644
--- a/cli-runopts.c
+++ b/cli-runopts.c
@@ -177,7 +177,20 @@ void cli_getopts(int argc, char ** argv) {
fill_own_user();
- for (i = 1; i < (unsigned int)argc && argv[i][0] == '-'; i++) {
+ for (i = 1; i < (unsigned int)argc; i++) {
+ /* Handle non-flag arguments such as hostname or commands for the remote host */
+ if (argv[i][0] != '-')
+ {
+ if (host_arg == NULL) {
+ host_arg = argv[i];
+ continue;
+ }
+ /* Commands to pass to the remote host. No more flag handling,
+ commands are consumed below */
+ break;
+ }
+
+ /* Begins with '-' */
opt = OPT_OTHER;
for (j = 1; (c = argv[i][j]) != '\0' && !next && opt == OPT_OTHER; j++) {
switch (c) {
@@ -348,11 +361,10 @@ void cli_getopts(int argc, char ** argv) {
/* Done with options/flags; now handle the hostname (which may not
* start with a hyphen) and optional command */
- if (i >= (unsigned int)argc) { /* missing hostname */
+ if (host_arg == NULL) { /* missing hostname */
printhelp();
exit(EXIT_FAILURE);
}
- host_arg = argv[i++];
TRACE(("host is: %s", host_arg))
if (i < (unsigned int)argc) {