mirror of
https://oauth2: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@github.com/m1ngsama/TNT.git
synced 2026-05-10 19:00:57 +08:00
Merge pull request #40 from m1ngsama/feat/cli-improvements
feat: add --port, --version long options and improved help
This commit is contained in:
commit
848ad2e2a6
2 changed files with 27 additions and 12 deletions
23
src/main.c
23
src/main.c
|
|
@ -31,7 +31,8 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
/* Parse command line arguments */
|
/* Parse command line arguments */
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
if (strcmp(argv[i], "-p") == 0 && i + 1 < argc) {
|
if ((strcmp(argv[i], "-p") == 0 || strcmp(argv[i], "--port") == 0) &&
|
||||||
|
i + 1 < argc) {
|
||||||
char *end;
|
char *end;
|
||||||
long val = strtol(argv[i + 1], &end, 10);
|
long val = strtol(argv[i + 1], &end, 10);
|
||||||
if (*end != '\0' || val <= 0 || val > 65535) {
|
if (*end != '\0' || val <= 0 || val > 65535) {
|
||||||
|
|
@ -47,13 +48,23 @@ int main(int argc, char **argv) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
|
} else if (strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) {
|
||||||
|
printf("tnt %s\n", TNT_VERSION);
|
||||||
|
return 0;
|
||||||
} else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
|
} else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
|
||||||
printf("TNT - Terminal Network Talk\n");
|
printf("tnt %s - anonymous SSH chat server\n\n", TNT_VERSION);
|
||||||
printf("Usage: %s [options]\n", argv[0]);
|
printf("Usage: %s [options]\n\n", argv[0]);
|
||||||
printf("Options:\n");
|
printf("Options:\n");
|
||||||
printf(" -p PORT Listen on PORT (default: %d)\n", DEFAULT_PORT);
|
printf(" -p, --port PORT Listen on PORT (default: %d)\n", DEFAULT_PORT);
|
||||||
printf(" -d DIR Store host key and logs in DIR\n");
|
printf(" -d, --state-dir DIR Store host key and logs in DIR\n");
|
||||||
printf(" -h Show this help\n");
|
printf(" -V, --version Show version\n");
|
||||||
|
printf(" -h, --help Show this help\n");
|
||||||
|
printf("\nEnvironment:\n");
|
||||||
|
printf(" PORT Default listening port\n");
|
||||||
|
printf(" TNT_STATE_DIR State directory\n");
|
||||||
|
printf(" TNT_ACCESS_TOKEN Require this password for SSH auth\n");
|
||||||
|
printf(" TNT_MAX_CONNECTIONS Global connection limit (default: 64)\n");
|
||||||
|
printf(" TNT_RATE_LIMIT Set to 0 to disable rate limiting\n");
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unknown option: %s\n", argv[i]);
|
fprintf(stderr, "Unknown option: %s\n", argv[i]);
|
||||||
|
|
|
||||||
16
tnt.1
16
tnt.1
|
|
@ -4,11 +4,12 @@
|
||||||
tnt \- anonymous SSH chat server with Vim\-style TUI
|
tnt \- anonymous SSH chat server with Vim\-style TUI
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.B tnt
|
.B tnt
|
||||||
.RB [ \-p
|
.RB [ \-p | \-\-port
|
||||||
.IR port ]
|
.IR port ]
|
||||||
.RB [ \-d
|
.RB [ \-d | \-\-state\-dir
|
||||||
.IR dir ]
|
.IR dir ]
|
||||||
.RB [ \-h ]
|
.RB [ \-V | \-\-version ]
|
||||||
|
.RB [ \-h | \-\-help ]
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
.B tnt
|
.B tnt
|
||||||
is a multi\-user anonymous chat server accessed over SSH.
|
is a multi\-user anonymous chat server accessed over SSH.
|
||||||
|
|
@ -21,7 +22,7 @@ The server supports CJK and emoji input, rate limiting, access tokens, and
|
||||||
a non\-interactive exec interface for scripting.
|
a non\-interactive exec interface for scripting.
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
.TP
|
.TP
|
||||||
.BI \-p " port"
|
.BR \-p ", " \-\-port " " \fIport\fR
|
||||||
Listen on
|
Listen on
|
||||||
.I port
|
.I port
|
||||||
instead of the default 2222.
|
instead of the default 2222.
|
||||||
|
|
@ -29,7 +30,7 @@ Overrides the
|
||||||
.B PORT
|
.B PORT
|
||||||
environment variable.
|
environment variable.
|
||||||
.TP
|
.TP
|
||||||
.BI \-d " dir"
|
.BR \-d ", " \-\-state\-dir " " \fIdir\fR
|
||||||
Store the host key and message log in
|
Store the host key and message log in
|
||||||
.IR dir .
|
.IR dir .
|
||||||
Overrides the
|
Overrides the
|
||||||
|
|
@ -37,7 +38,10 @@ Overrides the
|
||||||
environment variable.
|
environment variable.
|
||||||
Defaults to the current working directory.
|
Defaults to the current working directory.
|
||||||
.TP
|
.TP
|
||||||
.B \-h
|
.BR \-V ", " \-\-version
|
||||||
|
Print version and exit.
|
||||||
|
.TP
|
||||||
|
.BR \-h ", " \-\-help
|
||||||
Print a short usage summary and exit.
|
Print a short usage summary and exit.
|
||||||
.SH CONNECTING
|
.SH CONNECTING
|
||||||
.PP
|
.PP
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue