mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-30 22:13:49 +00:00
Add help option
* updated cli option 'help' - all 5 apps supports cli option '-h' without error exit code - supports long option '--help' * fixed bad line brake
This commit is contained in:
+15
-4
@@ -985,8 +985,9 @@ int main(int argc, char **argv)
|
||||
|
||||
int option_index = 0;
|
||||
static struct option long_options[] = {
|
||||
{ "fast-open", no_argument, 0, 0 },
|
||||
{ "acl", required_argument, 0, 0 },
|
||||
{ "fast-open", no_argument , 0, 0 },
|
||||
{ "acl" , required_argument, 0, 0 },
|
||||
{ "help" , no_argument , 0, 0 },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
@@ -995,10 +996,10 @@ int main(int argc, char **argv)
|
||||
USE_TTY();
|
||||
|
||||
#ifdef ANDROID
|
||||
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:i:c:b:a:n:P:uvVA",
|
||||
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:i:c:b:a:n:P:huvVA",
|
||||
long_options, &option_index)) != -1) {
|
||||
#else
|
||||
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:i:c:b:a:n:uvA",
|
||||
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:i:c:b:a:n:huvA",
|
||||
long_options, &option_index)) != -1) {
|
||||
#endif
|
||||
switch (c) {
|
||||
@@ -1008,6 +1009,9 @@ int main(int argc, char **argv)
|
||||
} else if (option_index == 1) {
|
||||
LOGI("initialize acl...");
|
||||
acl = !init_acl(optarg, BLACK_LIST);
|
||||
} else if (option_index == 2) {
|
||||
usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
@@ -1058,6 +1062,9 @@ int main(int argc, char **argv)
|
||||
case 'v':
|
||||
verbose = 1;
|
||||
break;
|
||||
case 'h':
|
||||
usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
case 'A':
|
||||
auth = 1;
|
||||
break;
|
||||
@@ -1069,6 +1076,10 @@ int main(int argc, char **argv)
|
||||
prefix = optarg;
|
||||
break;
|
||||
#endif
|
||||
case '?':
|
||||
// The option character is not recognized.
|
||||
opterr = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+15
-4
@@ -572,10 +572,11 @@ int main(int argc, char **argv)
|
||||
|
||||
int option_index = 0;
|
||||
static struct option long_options[] = {
|
||||
{ "fast-open", no_argument, 0, 0 },
|
||||
{ "acl", required_argument, 0, 0 },
|
||||
{ "fast-open" , no_argument , 0, 0 },
|
||||
{ "acl" , required_argument, 0, 0 },
|
||||
{ "manager-address", required_argument, 0, 0 },
|
||||
{ "executable", required_argument, 0, 0 },
|
||||
{ "executable" , required_argument, 0, 0 },
|
||||
{ "help" , no_argument , 0, 0 },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
@@ -583,7 +584,7 @@ int main(int argc, char **argv)
|
||||
|
||||
USE_TTY();
|
||||
|
||||
while ((c = getopt_long(argc, argv, "f:s:l:k:t:m:c:i:d:a:uUvA",
|
||||
while ((c = getopt_long(argc, argv, "f:s:l:k:t:m:c:i:d:a:huUvA",
|
||||
long_options, &option_index)) != -1)
|
||||
switch (c) {
|
||||
case 0:
|
||||
@@ -595,6 +596,9 @@ int main(int argc, char **argv)
|
||||
manager_address = optarg;
|
||||
} else if (option_index == 3) {
|
||||
executable = optarg;
|
||||
} else if (option_index == 4) {
|
||||
usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
@@ -638,9 +642,16 @@ int main(int argc, char **argv)
|
||||
case 'v':
|
||||
verbose = 1;
|
||||
break;
|
||||
case 'h':
|
||||
usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
case 'A':
|
||||
auth = 1;
|
||||
break;
|
||||
case '?':
|
||||
// The option character is not recognized.
|
||||
opterr = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (opterr) {
|
||||
|
||||
+23
-1
@@ -36,6 +36,7 @@
|
||||
#include <strings.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include <limits.h>
|
||||
#include <linux/if.h>
|
||||
#include <linux/netfilter_ipv4.h>
|
||||
@@ -671,10 +672,23 @@ int main(int argc, char **argv)
|
||||
ss_addr_t remote_addr[MAX_REMOTE_NUM];
|
||||
char *remote_port = NULL;
|
||||
|
||||
int option_index = 0;
|
||||
static struct option long_options[] = {
|
||||
{ "help", no_argument, 0, 0 },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
opterr = 0;
|
||||
|
||||
while ((c = getopt(argc, argv, "f:s:p:l:k:t:m:c:b:a:n:uUvA")) != -1)
|
||||
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:c:b:a:n:huUvA",
|
||||
long_options, &option_index)) != -1) {
|
||||
switch (c) {
|
||||
case 0:
|
||||
if (option_index == 0) {
|
||||
usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
if (remote_num < MAX_REMOTE_NUM) {
|
||||
remote_addr[remote_num].host = optarg;
|
||||
@@ -723,10 +737,18 @@ int main(int argc, char **argv)
|
||||
case 'v':
|
||||
verbose = 1;
|
||||
break;
|
||||
case 'h':
|
||||
usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
case 'A':
|
||||
auth = 1;
|
||||
break;
|
||||
case '?':
|
||||
// The option character is not recognized.
|
||||
opterr = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (opterr) {
|
||||
usage();
|
||||
|
||||
+16
-4
@@ -1316,9 +1316,10 @@ int main(int argc, char **argv)
|
||||
|
||||
int option_index = 0;
|
||||
static struct option long_options[] = {
|
||||
{ "fast-open", no_argument, 0, 0 },
|
||||
{ "acl", required_argument, 0, 0 },
|
||||
{ "fast-open" , no_argument , 0, 0 },
|
||||
{ "acl" , required_argument, 0, 0 },
|
||||
{ "manager-address", required_argument, 0, 0 },
|
||||
{ "help" , no_argument , 0, 0 },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
@@ -1326,8 +1327,8 @@ int main(int argc, char **argv)
|
||||
|
||||
USE_TTY();
|
||||
|
||||
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:c:i:d:a:n:uUvAw",
|
||||
long_options, &option_index)) != -1)
|
||||
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:c:i:d:a:n:huUvAw",
|
||||
long_options, &option_index)) != -1) {
|
||||
switch (c) {
|
||||
case 0:
|
||||
if (option_index == 0) {
|
||||
@@ -1338,6 +1339,9 @@ int main(int argc, char **argv)
|
||||
acl_path = optarg;
|
||||
} else if (option_index == 2) {
|
||||
manager_address = optarg;
|
||||
} else if (option_index == 3) {
|
||||
usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
@@ -1389,13 +1393,21 @@ int main(int argc, char **argv)
|
||||
case 'v':
|
||||
verbose = 1;
|
||||
break;
|
||||
case 'h':
|
||||
usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
case 'A':
|
||||
auth = 1;
|
||||
break;
|
||||
case 'w':
|
||||
white_list = 1;
|
||||
break;
|
||||
case '?':
|
||||
// The option character is not recognized.
|
||||
opterr = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (opterr) {
|
||||
usage();
|
||||
|
||||
+24
-2
@@ -28,6 +28,7 @@
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#ifndef __MINGW32__
|
||||
#include <errno.h>
|
||||
@@ -696,16 +697,30 @@ int main(int argc, char **argv)
|
||||
ss_addr_t tunnel_addr = { .host = NULL, .port = NULL };
|
||||
char *tunnel_addr_str = NULL;
|
||||
|
||||
int option_index = 0;
|
||||
static struct option long_options[] = {
|
||||
{ "help", no_argument, 0, 0 },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
opterr = 0;
|
||||
|
||||
USE_TTY();
|
||||
|
||||
#ifdef ANDROID
|
||||
while ((c = getopt(argc, argv, "f:s:p:l:k:t:m:i:c:b:L:a:n:P:uUvVA")) != -1) {
|
||||
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:i:c:b:L:a:n:P:huUvVA",
|
||||
long_options, &option_index)) != -1) {
|
||||
#else
|
||||
while ((c = getopt(argc, argv, "f:s:p:l:k:t:m:i:c:b:L:a:n:uUvA")) != -1) {
|
||||
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:i:c:b:L:a:n:huUvA",
|
||||
long_options, &option_index)) != -1) {
|
||||
#endif
|
||||
switch (c) {
|
||||
case 0:
|
||||
if (option_index == 0) {
|
||||
usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
if (remote_num < MAX_REMOTE_NUM) {
|
||||
remote_addr[remote_num].host = optarg;
|
||||
@@ -760,6 +775,9 @@ int main(int argc, char **argv)
|
||||
case 'v':
|
||||
verbose = 1;
|
||||
break;
|
||||
case 'h':
|
||||
usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
case 'A':
|
||||
auth = 1;
|
||||
break;
|
||||
@@ -771,6 +789,10 @@ int main(int argc, char **argv)
|
||||
prefix = optarg;
|
||||
break;
|
||||
#endif
|
||||
case '?':
|
||||
// The option character is not recognized.
|
||||
opterr = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-4
@@ -205,7 +205,7 @@ void usage()
|
||||
#endif
|
||||
printf("\n");
|
||||
printf(
|
||||
" -s <server_host> Host name or ip address of your remote server.\n");
|
||||
" -s <server_host> Host name or IP address of your remote server.\n");
|
||||
printf(
|
||||
" -p <server_port> Port number of your remote server.\n");
|
||||
printf(
|
||||
@@ -219,9 +219,13 @@ void usage()
|
||||
printf(
|
||||
" bf-cfb, camellia-128-cfb, camellia-192-cfb,\n");
|
||||
printf(
|
||||
" camellia-256-cfb, cast5-cfb, des-cfb, idea-cfb,\n");
|
||||
" camellia-256-cfb, cast5-cfb, des-cfb,\n");
|
||||
printf(
|
||||
" rc2-cfb, seed-cfb, salsa20 and chacha20.\n");
|
||||
" idea-cfb, rc2-cfb, seed-cfb, salsa20 and\n");
|
||||
printf(
|
||||
" chacha20.\n");
|
||||
printf(
|
||||
" The default cipher is tables.\n");
|
||||
printf("\n");
|
||||
printf(
|
||||
" [-a <user>] Run as another user.\n");
|
||||
@@ -289,7 +293,9 @@ void usage()
|
||||
#endif
|
||||
printf("\n");
|
||||
printf(
|
||||
" [-v] Verbose mode\n");
|
||||
" [-v] Verbose mode.\n");
|
||||
printf(
|
||||
" [-h, --help] Print this message.\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user