forked from github/abduco
Allow squashing of command line flags together
This commit is contained in:
parent
15ae398ea5
commit
e08d7acc3a
36
abduco.c
36
abduco.c
|
|
@ -574,38 +574,28 @@ static int list_session(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
int opt;
|
||||||
bool force = false;
|
bool force = false;
|
||||||
char **cmd = NULL, action = '\0';
|
char **cmd = NULL, action = '\0';
|
||||||
server.name = basename(argv[0]);
|
server.name = basename(argv[0]);
|
||||||
gethostname(server.host+1, sizeof(server.host) - 1);
|
gethostname(server.host+1, sizeof(server.host) - 1);
|
||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
exit(list_session());
|
exit(list_session());
|
||||||
for (int arg = 1; arg < argc; arg++) {
|
|
||||||
if (argv[arg][0] != '-') {
|
while ((opt = getopt(argc, argv, "aAcne:frv")) != -1) {
|
||||||
if (!server.session_name) {
|
switch (opt) {
|
||||||
server.session_name = argv[arg];
|
|
||||||
continue;
|
|
||||||
} else if (!cmd) {
|
|
||||||
cmd = &argv[arg];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (server.session_name)
|
|
||||||
usage();
|
|
||||||
switch (argv[arg][1]) {
|
|
||||||
case 'a':
|
case 'a':
|
||||||
case 'A':
|
case 'A':
|
||||||
case 'c':
|
case 'c':
|
||||||
case 'n':
|
case 'n':
|
||||||
action = argv[arg][1];
|
action = opt;
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
if (arg + 1 >= argc)
|
if (!optarg)
|
||||||
usage();
|
usage();
|
||||||
char *esc = argv[++arg];
|
if (optarg[0] == '^' && optarg[1])
|
||||||
if (esc[0] == '^' && esc[1])
|
optarg[0] = CTRL(optarg[1]);
|
||||||
*esc = CTRL(esc[1]);
|
KEY_DETACH = optarg[0];
|
||||||
KEY_DETACH = *esc;
|
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
force = true;
|
force = true;
|
||||||
|
|
@ -621,6 +611,14 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* collect the session name if trailing args */
|
||||||
|
if (optind < argc)
|
||||||
|
server.session_name = argv[optind];
|
||||||
|
|
||||||
|
/* if yet more trailing arguments, they must be the command */
|
||||||
|
if (optind + 1 < argc)
|
||||||
|
cmd = &argv[optind + 1];
|
||||||
|
|
||||||
if (!cmd) {
|
if (!cmd) {
|
||||||
cmd = (char*[]){ getenv("ABDUCO_CMD"), NULL };
|
cmd = (char*[]){ getenv("ABDUCO_CMD"), NULL };
|
||||||
if (!cmd[0])
|
if (!cmd[0])
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue