[Libguestfs] [libnbd PATCH] nbdsh: Support -u as synonym for --connect
Richard W.M. Jones
rjones at redhat.com
Thu Sep 12 19:36:51 UTC 2019
On Thu, Sep 12, 2019 at 02:33:24PM -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 seems
> like a reasonable mnemonic.
> ---
> sh/nbdsh.pod | 6 ++++--
> python/nbdsh.py | 2 +-
> sh/test-context.sh | 8 ++++----
> sh/test-pattern.sh | 2 +-
> 4 files changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/sh/nbdsh.pod b/sh/nbdsh.pod
> index 6c540c7..b1a3552 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
> @@ -78,6 +78,8 @@ 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<--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 00bc6bc..b15702c 100644
> --- a/python/nbdsh.py
> +++ b/python/nbdsh.py
> @@ -29,7 +29,7 @@ def shell():
> epilog=epilog)
> parser.add_argument ('-b', '--base-allocation', action='store_true',
> help='request the "base:allocation" meta context')
> - parser.add_argument ('--connect', metavar='URI',
> + parser.add_argument ('-u', '--connect', metavar='URI',
> help="connect to NBD URI")
> parser.add_argument ('-c', '--command', action='append',
> help="run a command")
> diff --git a/sh/test-context.sh b/sh/test-context.sh
> index 3b32ba9..f2c3ba5 100755
> --- a/sh/test-context.sh
> +++ b/sh/test-context.sh
> @@ -21,7 +21,7 @@ fail=0
>
> # Without -b, 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,7 +30,7 @@ fi
>
> # With -b (and a server that supports it), meta context works.
> output=$(nbdkit -U - null --run 'nbdsh \
> - -b --connect "nbd+unix://?socket=$unixsocket" \
> + -b -u "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"
> @@ -40,7 +40,7 @@ fi
> # Again, but with -b after -u, and with long option names
> output=$(nbdkit -U - null --run 'nbdsh \
> --connect "nbd+unix://?socket=$unixsocket" --base-allocation \
> - --command "print (h.can_meta_context (nbd.CONTEXT_BASE_ALLOCATION))"')
> + -command "print (h.can_meta_context (nbd.CONTEXT_BASE_ALLOCATION))"')
> if test "x$output" != xTrue; then
> echo "$0: unexpected output: $output"
> fail=1
> @@ -49,7 +49,7 @@ 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()
> --
ACK
I wouldn't mind also hiding the --connect option and adding a --uri option.
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
More information about the Libguestfs
mailing list