Browse Source

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
pull/597/merge
Kim 9 years ago
committed by Max Lv
parent
commit
dfa9e17c1b
12 changed files with 127 additions and 25 deletions
  1. 3
      man/shadowsocks-libev.8
  2. 7
      man/ss-local.1
  3. 5
      man/ss-manager.1
  4. 5
      man/ss-redir.1
  5. 5
      man/ss-server.1
  6. 5
      man/ss-tunnel.1
  7. 19
      src/local.c
  8. 19
      src/manager.c
  9. 24
      src/redir.c
  10. 20
      src/server.c
  11. 26
      src/tunnel.c
  12. 14
      src/utils.c

3
man/shadowsocks-libev.8

@ -164,6 +164,9 @@ Only available in manager mode.
.TP
.B \-v
Enable verbose mode.
.TP
.B \-h, --help
Print help message.
.SH EXAMPLE
\*(Re requires netfilter's NAT function. Here is an example:

7
man/ss-local.1

@ -31,11 +31,11 @@ ss-local \- shadowsocks client as socks5 proxy, libev port
.SH SYNOPSIS
\*(Lo
[\fB\-Auhv\fR]
[\fB\-Auv\fR] [\fB\-h\fR|\fB\--help\fR]
[\fB\-s\fR \fIserver_host\fR] [\fB\-p\fR \fIserver_port\fR] [\fB\-l\fR \fIlocal_port\fR]
[\fB\-k\fR \fIpassword\fR] [\fB\-m\fR \fIencrypt_method\fR] [\fB\-f\fR \fIpid_file\fR] [\fB\-t\fR \fItimeout\fR]
[\fB\-c\fR \fIconfig_file\fR] [\fB\-b\fR \fIinterface\fR] [\fB\-a\fR \fIuser_name\fR]
[\fB\-n\fR \fInofile\fR] [\fB\-\-fast\-open\fR] [\fB\-\-acl\fR \fIacl_config\fR]
[\fB\-n\fR \fInofile\fR] [\fB\-\-fast\-open\fR] [\fB\-\-acl\fR \fIacl_config\fR]
.SH DESCRIPTION
\*(Me is a lightweight and secure socks5 proxy. It is a port of the original
@ -110,6 +110,9 @@ Enable ACL (Access Control List) and specify config file.
.TP
.B \-v
Enable verbose mode.
.TP
.B \-h, --help
Print help message.
.SH EXAMPLE
\*(Lo(1) can be started from command line and run in foreground. Here is an

5
man/ss-manager.1

@ -32,7 +32,7 @@ statistics
.SH SYNOPSIS
\*(Ma
[\fB\-AhuUv\fR]
[\fB\-AuUv\fR] [\fB\-h\fR|\fB\--help\fR]
[\fB\-s\fR \fIserver_host\fR] [\fB\-p\fR \fIserver_port\fR] [\fB\-l\fR \fIlocal_port\fR]
[\fB\-k\fR \fIpassword\fR] [\fB\-m\fR \fIencrypt_method\fR] [\fB\-f\fR \fIpid_file\fR]
[\fB\-t\fR \fItimeout\fR] [\fB\-c\fR \fIconfig_file\fR] [\fB\-i\fR \fIinterface\fR]
@ -119,6 +119,9 @@ Only available in manager mode.
.TP
.B \-v
Enable verbose mode.
.TP
.B \-h, --help
Print help message.
.SH PROTOCOL
\*(Ma(1) provides several APIs through UDP protocol:

5
man/ss-redir.1

@ -31,7 +31,7 @@ ss-redir \- shadowsocks client as transparent proxy, libev port
.SH SYNOPSIS
\*(Re
[\fB\-AhuUv\fR]
[\fB\-AuUv\fR] [\fB\-h\fR|\fB\--help\fR]
[\fB\-s\fR \fIserver_host\fR] [\fB\-p\fR \fIserver_port\fR] [\fB\-l\fR \fIlocal_port\fR]
[\fB\-k\fR \fIpassword\fR] [\fB\-m\fR \fIencrypt_method\fR] [\fB\-f\fR \fIpid_file\fR]
[\fB\-t\fR \fItimeout\fR] [\fB\-c\fR \fIconfig_file\fR] [\fB\-b\fR \fIlocal_address\fR]
@ -105,6 +105,9 @@ Enable onetime authentication.
.TP
.B \-v
Enable verbose mode.
.TP
.B \-h, --help
Print help message.
.SH EXAMPLE
\*(Re requires netfilter's NAT function. Here is an example:

5
man/ss-server.1

@ -31,7 +31,7 @@ ss-server \- shadowsocks server, libev port
.SH SYNOPSIS
\*(Se
[\fB-AhuUv\fR]
[\fB-AuUv\fR] [\fB\-h\fR|\fB\--help\fR]
[\fB\-s\fR \fIserver_host\fR] [\fB\-p\fR \fIserver_port\fR] [\fB\-l\fR \fIlocal_port\fR]
[\fB\-k\fR \fIpassword\fR] [\fB\-m\fR \fIencrypt_method\fR] [\fB\-f\fR \fIpid_file\fR]
[\fB\-t\fR \fItimeout\fR] [\fB\-c\fR \fIconfig_file\fR] [\fB\-i\fR \fIinterface\fR]
@ -122,6 +122,9 @@ Only available in server and manager mode.
.TP
.B \-v
Enable verbose mode.
.TP
.B \-h, --help
Print help message.
.SH EXAMPLE
It is recommended to use a config file when starting \*(Se(1).

5
man/ss-tunnel.1

@ -31,7 +31,7 @@ ss-tunnel \- shadowsocks tools for local port forwarding, libev port
.SH SYNOPSIS
\*(Tu
[\fB-AhuUv\fR]
[\fB-AuUv\fR] [\fB\-h\fR|\fB\--help\fR]
[\fB\-s\fR \fIserver_host\fR] [\fB\-p\fR \fIserver_port\fR] [\fB\-l\fR \fIlocal_port\fR]
[\fB\-k\fR \fIpassword\fR] [\fB\-m\fR \fIencrypt_method\fR] [\fB\-f\fR \fIpid_file\fR]
[\fB\-t\fR \fItimeout\fR] [\fB\-c\fR \fIconfig_file\fR] [\fB\-i\fR \fIinterface\fR]
@ -111,6 +111,9 @@ Only used and available in tunnel mode.
.TP
.B \-v
Enable verbose mode.
.TP
.B \-h, --help
Print help message.
.SH SEE ALSO
.BR \*(Lo (1),

19
src/local.c

@ -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;
}
}

19
src/manager.c

@ -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) {

24
src/redir.c

@ -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();

20
src/server.c

@ -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();

26
src/tunnel.c

@ -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;
}
}

14
src/utils.c

@ -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");
}

Loading…
Cancel
Save