Eric Blake
2019-Sep-12 21:06 UTC
[Libguestfs] [libnbd PATCH v2] nbdsh: Prefer --uri over --connect
Typing nbdsh --con (the minimum to get an unambiguous prefix for --connect, different from --command) is annoying compared to having a short option. Since it takes a URI as an argument, using -u/--uri is a nicer mnemonic. We still accept --connect for back-compat, and document it in the man page, but omit it from --help as the new spelling is nicer all around. --- Here's what things evolved to after hiding --connect from --help output. I've gone ahead and pushed this. sh/nbdsh.pod | 8 ++++++-- python/nbdsh.py | 8 +++++--- sh/test-context.sh | 24 ++++++++++++------------ sh/test-pattern.sh | 2 +- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/sh/nbdsh.pod b/sh/nbdsh.pod index d44c8d8..41a88a5 100644 --- a/sh/nbdsh.pod +++ b/sh/nbdsh.pod @@ -32,11 +32,11 @@ For documentation about the libnbd API please open the shell and type: =head2 Print the size of an NBD export -The I<--connect> option connects to an NBD URI. The I<-c> option lets +The I<-u> option connects to an NBD URI. The I<-c> option lets you execute single Python statements from the command line. Combining these two options lets you print the size in bytes of an NBD export: - $ nbdsh --connect nbd://localhost -c 'print (h.get_size ())' + $ nbdsh -u nbd://localhost -c 'print (h.get_size ())' 1073741824 =head2 Hexdump the boot sector of an NBD export @@ -76,6 +76,10 @@ can be specified multiple times in order to run multiple commands. Read standard input and execute it as a command. +=item B<-u> URI + +=item B<-uri> URI + =item B<--connect> URI Connect to the given L<NBD URI|https://github.com/NetworkBlockDevice/nbd/blob/master/doc/uri.md>. diff --git a/python/nbdsh.py b/python/nbdsh.py index 098cc8a..3b4ad0e 100644 --- a/python/nbdsh.py +++ b/python/nbdsh.py @@ -29,8 +29,10 @@ def shell(): epilog=epilog) parser.add_argument ('--base-allocation', action='store_true', help='request the "base:allocation" meta context') - parser.add_argument ('--connect', metavar='URI', + parser.add_argument ('-u', '--uri', help="connect to NBD URI") + # For back-compat, provide --connect as an undocumented synonym to --uri + parser.add_argument ('--connect', dest='uri', help=argparse.SUPPRESS) parser.add_argument ('-c', '--command', action='append', help="run a command") parser.add_argument ('-V', '--version', action='version', @@ -56,8 +58,8 @@ help (nbd) # Display documentation if args.base_allocation: h.add_meta_context (nbd.CONTEXT_BASE_ALLOCATION) - if args.connect is not None: - h.connect_uri (args.connect) + if args.uri is not None: + h.connect_uri (args.uri) # If there are no -c or --command parameters, go interactive, # otherwise we run the commands and exit. if not args.command: diff --git a/sh/test-context.sh b/sh/test-context.sh index 9a7d3ab..ab3ae80 100755 --- a/sh/test-context.sh +++ b/sh/test-context.sh @@ -21,7 +21,7 @@ fail=0 # Without --base-allocation, no meta context is requested output=$(nbdkit -U - null --run 'nbdsh \ - --connect "nbd+unix://?socket=$unixsocket" \ + -u "nbd+unix://?socket=$unixsocket" \ -c "print (h.can_meta_context (nbd.CONTEXT_BASE_ALLOCATION))"') if test "x$output" != xFalse; then echo "$0: unexpected output: $output" @@ -30,26 +30,26 @@ fi # With --base-allocation (and a server that supports it), meta context works. output=$(nbdkit -U - null --run 'nbdsh \ - --base-allocation --connect "nbd+unix://?socket=$unixsocket" \ - -c "print (h.can_meta_context (nbd.CONTEXT_BASE_ALLOCATION))"') -if test "x$output" != xTrue; then - echo "$0: unexpected output: $output" - fail=1 -fi - -# Again, but with --b after --connect, and with abbreviated option names -output=$(nbdkit -U - null --run 'nbdsh \ - --conn "nbd+unix://?socket=$unixsocket" --b \ + --base-allocation --uri "nbd+unix://?socket=$unixsocket" \ --command "print (h.can_meta_context (nbd.CONTEXT_BASE_ALLOCATION))"') if test "x$output" != xTrue; then echo "$0: unexpected output: $output" fail=1 fi +# Again, but with --b after -u, and with abbreviated option names +output=$(nbdkit -U - null --run 'nbdsh \ + -u "nbd+unix://?socket=$unixsocket" --b \ + -c "print (h.can_meta_context (nbd.CONTEXT_BASE_ALLOCATION))"') +if test "x$output" != xTrue; then + echo "$0: unexpected output: $output" + fail=1 +fi + if [[ $(nbdkit --help) =~ --no-sr ]]; then # meta context depends on server cooperation output=$(nbdkit -U - --no-sr null --run 'nbdsh \ - --connect "nbd+unix://?socket=$unixsocket" --base-allocation \ + -u "nbd+unix://?socket=$unixsocket" --base-allocation \ -c "print (h.can_meta_context (nbd.CONTEXT_BASE_ALLOCATION))"') if test "x$output" != xFalse; then echo "$0: unexpected output: $output" diff --git a/sh/test-pattern.sh b/sh/test-pattern.sh index 2d4e261..855bec7 100755 --- a/sh/test-pattern.sh +++ b/sh/test-pattern.sh @@ -36,7 +36,7 @@ if ! test -f "$pidfile"; then exit 1 fi -nbdsh --connect "nbd+unix://?socket=$sock" \ +nbdsh -u "nbd+unix://?socket=$sock" \ -c ' def size(): return h.get_size() -- 2.21.0
Richard W.M. Jones
2019-Sep-12 21:26 UTC
Re: [Libguestfs] [libnbd PATCH v2] nbdsh: Prefer --uri over --connect
On Thu, Sep 12, 2019 at 04:06:48PM -0500, Eric Blake wrote:> Typing nbdsh --con (the minimum to get an unambiguous prefix for > --connect, different from --command) is annoying compared to having a > short option. Since it takes a URI as an argument, using -u/--uri is > a nicer mnemonic. We still accept --connect for back-compat, and > document it in the man page, but omit it from --help as the new > spelling is nicer all around. > --- > > Here's what things evolved to after hiding --connect from --help output. > > I've gone ahead and pushed this.Yes, it looks fine, thanks. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
Seemingly Similar Threads
- [libnbd PATCH] nbdsh: Support -u as synonym for --connect
- [libnbd PATCH] nbdsh: Add -b option to simplify h.block_status
- [libnbd PATCH] nbdsh: Add --opt-mode command line option
- [libnbd PATCH v2 0/3] Improve nbdsh -u handling
- [libnbd PATCH] nbdsh: Start adding unit tests