Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/ftp ftp: add -? for help. improve synopsis



details:   https://anonhg.NetBSD.org/src/rev/feb92e67ed44
branches:  trunk
changeset: 1011960:feb92e67ed44
user:      lukem <lukem%NetBSD.org@localhost>
date:      Sat Jul 18 03:00:37 2020 +0000

description:
ftp: add -? for help. improve synopsis

Add -? to display usage synopsis and help to stdout.
This allows for "ftp -? | less", which is more user friendly.
Errors still show usage to stderr.
Consistency improvements in some usage text.

diffstat:

 usr.bin/ftp/ftp.1     |   27 +++++++++--
 usr.bin/ftp/main.c    |  110 +++++++++++++++++++++++++++++++++++++------------
 usr.bin/ftp/version.h |    4 +-
 3 files changed, 106 insertions(+), 35 deletions(-)

diffs (280 lines):

diff -r 84434a23608c -r feb92e67ed44 usr.bin/ftp/ftp.1
--- a/usr.bin/ftp/ftp.1 Fri Jul 17 21:59:30 2020 +0000
+++ b/usr.bin/ftp/ftp.1 Sat Jul 18 03:00:37 2020 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: ftp.1,v 1.141 2020/07/15 19:23:44 uwe Exp $
+.\"    $NetBSD: ftp.1,v 1.142 2020/07/18 03:00:37 lukem Exp $
 .\"
 .\" Copyright (c) 1996-2020 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -57,7 +57,7 @@
 .\"
 .\"    @(#)ftp.1       8.3 (Berkeley) 10/9/94
 .\"
-.Dd July 15, 2020
+.Dd July 18, 2020
 .Dt FTP 1
 .Os
 .Sh NAME
@@ -65,7 +65,7 @@
 .Nd Internet file transfer program
 .Sh SYNOPSIS
 .Nm
-.Op Fl 46AadefginpRtVv
+.Op Fl 46AadefginpRtVv?
 .Op Fl N Ar netrc
 .Op Fl o Ar output
 .Op Fl P Ar port
@@ -121,7 +121,7 @@
 .Ar host Oo Li \&: Ar port Oc
 .Li / Ar path
 .Op Li /
-.Op Li ;type= Ar X
+.Op Li ;type= Ar type
 .Oc
 .Sm on
 .Ek
@@ -138,6 +138,19 @@
 .Oc
 .Sm on
 .Ek
+.Bk -words
+.\" [https://[user[:password]@]host[:port]/path]
+.Sm off
+.Oo
+.Li https://
+.Oo Ar user
+.Op Li \&: Ar password
+.Li \&@ Oc
+.Ar host Oo Li \&: Ar port Oc
+.Li / Ar path
+.Oc
+.Sm on
+.Ek
 .Ar \&...
 .Nm
 .Bk -words
@@ -316,6 +329,8 @@
 Refer to
 .Ic xferbuf
 for more information.
+.It Fl ?
+Display help to stdout, and exit.
 .El
 .Pp
 The client host with which
@@ -1581,10 +1596,10 @@
 in the current directory.
 Otherwise, the full remote name is used as the local name,
 relative to the local root directory.
-.\" ftp://[user[:password]@]host[:port]/path[/][;type=X]
+.\" ftp://[user[:password]@]host[:port]/path[/][;type=type]
 .It Li ftp:// Ns Oo Ar user Ns Oo Ns Li \&: Ns Ar password Oc Ns Li \&@ Oc \
 Ns Ar host Ns Oo Li \&: Ns Ar port Oc Ns Li / Ns Ar path Ns Oo Li / Oc \
-Ns Oo Li ;type= Ns Ar X Oc
+Ns Oo Li ;type= Ns Ar type Oc
 An
 .Tn FTP
 URL, retrieved using the
diff -r 84434a23608c -r feb92e67ed44 usr.bin/ftp/main.c
--- a/usr.bin/ftp/main.c        Fri Jul 17 21:59:30 2020 +0000
+++ b/usr.bin/ftp/main.c        Sat Jul 18 03:00:37 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.126 2019/02/04 04:09:13 mrg Exp $   */
+/*     $NetBSD: main.c,v 1.127 2020/07/18 03:00:37 lukem Exp $ */
 
 /*-
  * Copyright (c) 1996-2015 The NetBSD Foundation, Inc.
@@ -98,7 +98,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.6 (Berkeley) 10/9/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.126 2019/02/04 04:09:13 mrg Exp $");
+__RCSID("$NetBSD: main.c,v 1.127 2020/07/18 03:00:37 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -130,7 +130,8 @@
 #define        NO_PROXY        "no_proxy"      /* env var with list of non-proxied
                                         * hosts, comma or space separated */
 
-__dead static void     usage(void);
+static int     usage(void);
+static int     usage_help(void);
 static void    setupoption(const char *, const char *, const char *);
 
 int
@@ -266,7 +267,7 @@
                }
        }
 
-       while ((ch = getopt(argc, argv, "46AadefginN:o:pP:q:r:Rs:tT:u:vVx:")) != -1) {
+       while ((ch = getopt(argc, argv, "?46AadefginN:o:pP:q:r:Rs:tT:u:vVx:")) != -1) {
                switch (ch) {
                case '4':
                        family = AF_INET;
@@ -378,15 +379,15 @@
                                if (*cp == '\0') {
                                        warnx("Bad throttle value `%s'",
                                            optarg);
-                                       usage();
-                                       /* NOTREACHED */
+                                       return usage();
                                }
                                targv[targc++] = cp;
                                if (targc >= 5)
                                        break;
                        }
-                       if (parserate(targc, targv, 1) == -1)
-                               usage();
+                       if (parserate(targc, targv, 1) == -1) {
+                               return usage();
+                       }
                        free(oac);
                        break;
                }
@@ -415,8 +416,14 @@
                        rcvbuf_size = sndbuf_size;
                        break;
 
+               case '?':
+                       if (optopt == '?') {
+                               return usage_help();
+                       }
+                       return usage();
+
                default:
-                       usage();
+                       errx(1, "unimplemented option -%c", ch);
                }
        }
                        /* set line buffering on ttyout */
@@ -572,8 +579,9 @@
                        retry_connect = 0; /* connected, stop hiding msgs */
                }
        }
-       if (isupload)
-               usage();
+       if (isupload) {
+               return usage();
+       }
 
 #ifndef NO_EDITCOMPLETE
        controlediting();
@@ -836,7 +844,6 @@
                                slrflag++;
                                INC_CHKCURSOR(stringbase);
                                return ((*sb == '!') ? bangstr : dollarstr);
-                               /* NOTREACHED */
                        case 1:
                                slrflag++;
                                altarg = stringbase;
@@ -965,7 +972,7 @@
        cmd = argv[0];
        isusage = (strcmp(cmd, "usage") == 0);
        if (argc == 0 || (isusage && argc == 1)) {
-               UPRINTF("usage: %s [command [...]]\n", cmd);
+               UPRINTF("usage: %s [command ...]\n", cmd);
                return;
        }
        if (argc == 1) {
@@ -1044,20 +1051,69 @@
        set_option(name, value ? value : defaultvalue, 0);
 }
 
-void
+static void
+synopsis(FILE * stream)
+{
+       const char * progname = getprogname();
+
+       fprintf(stream,
+"usage: %s [-46AadefginpRtVv] [-N NETRC] [-o OUTPUT] [-P PORT] [-q QUITTIME]\n"
+"           [-r RETRY] [-s SRCADDR] [-T DIR,MAX[,INC]] [-x XFERSIZE]\n"
+"           [[USER@]HOST [PORT]]\n"
+"           [[USER@]HOST:[PATH][/]]\n"
+"           [file:///PATH]\n"
+"           [ftp://[USER[:PASSWORD]@]HOST[:PORT]/PATH[/][;type=TYPE]]\n";
+"           [http://[USER[:PASSWORD]@]HOST[:PORT]/PATH]\n";
+#ifdef WITH_SSL
+"           [https://[USER[:PASSWORD]@]HOST[:PORT]/PATH]\n";
+#endif
+"           ...\n"
+"       %s -u URL FILE ...\n"
+"       %s -?\n",
+               progname, progname, progname);
+}
+
+static int
+usage_help(void)
+{
+       synopsis(stdout);
+#ifndef NO_USAGE
+       printf(
+"  -4            Only use IPv4 addresses\n"
+"  -6            Only use IPv6 addresses\n"
+"  -A            Force active mode\n"
+"  -a            Use anonymous login\n"
+"  -d            Enable debugging\n"
+"  -e            Disable command-line editing\n"
+"  -f            Force cache reload for FTP or HTTP proxy transfers\n"
+"  -g            Disable file name globbing\n"
+"  -i            Disable interactive prompt during multiple file transfers\n"
+"  -N NETRC      Use NETRC instead of ~/.netrc\n"
+"  -n            Disable auto-login\n"
+"  -o OUTPUT     Save auto-fetched files to OUTPUT\n"
+"  -P PORT       Use port PORT\n"
+"  -p            Force passive mode\n"
+"  -q QUITTIME   Quit if connection stalls for QUITTIME seconds\n"
+"  -R            Restart non-proxy auto-fetch\n"
+"  -r RETRY      Retry failed connection attempts after RETRY seconds\n"
+"  -s SRCADDR    Use source address SRCADDR\n"
+"  -t            Enable packet tracing\n"
+"  -T DIR,MAX[,INC]\n"
+"                Set maximum transfer rate for direction DIR to MAX bytes/s,\n"
+"                with optional increment INC bytes/s\n"
+"  -u URL        URL to upload file arguments to\n"
+"  -V            Disable verbose and progress\n"
+"  -v            Enable verbose and progress\n"
+"  -x XFERSIZE   Set socket send and receive size to XFERSIZE\n"
+"  -?            Display this help and exit\n"
+               );
+#endif
+       return EXIT_SUCCESS;
+}
+
+static int
 usage(void)
 {
-       const char *progname = getprogname();
-
-       (void)fprintf(stderr,
-"usage: %s [-46AadefginpRtVv] [-N netrc] [-o outfile] [-P port] [-q quittime]\n"
-"           [-r retry] [-s srcaddr] [-T dir,max[,inc]] [-x xferbufsize]\n"
-"           [[user@]host [port]] [host:path[/]] [file:///file]\n"
-"           [ftp://[user[:pass]@]host[:port]/path[/]]\n";
-"           [http://[user[:pass]@]host[:port]/path] [...]\n"
-#ifdef WITH_SSL
-"           [https://[user[:pass]@]host[:port]/path] [...]\n"
-#endif
-"       %s -u URL file [...]\n", progname, progname);
-       exit(1);
+       synopsis(stderr);
+       return EXIT_FAILURE;
 }
diff -r 84434a23608c -r feb92e67ed44 usr.bin/ftp/version.h
--- a/usr.bin/ftp/version.h     Fri Jul 17 21:59:30 2020 +0000
+++ b/usr.bin/ftp/version.h     Sat Jul 18 03:00:37 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: version.h,v 1.90 2020/07/11 02:19:31 lukem Exp $       */
+/*     $NetBSD: version.h,v 1.91 2020/07/18 03:00:37 lukem Exp $       */
 
 /*-
  * Copyright (c) 1999-2020 The NetBSD Foundation, Inc.
@@ -34,5 +34,5 @@
 #endif
 
 #ifndef FTP_VERSION
-#define        FTP_VERSION     "20200711"
+#define        FTP_VERSION     "20200718"
 #endif



Home | Main Index | Thread Index | Old Index