Document all options in --help output. If -n is not in use, then
enhance the banner to print the current state of h, and further tailor
the advice given on useful next steps to take to mention opt_go when
using --opt-mode.
---
python/nbdsh.py | 37 ++++++++++++++++++++++++++++---------
1 file changed, 28 insertions(+), 9 deletions(-)
diff --git a/python/nbdsh.py b/python/nbdsh.py
index 0919c9ec..872b94fc 100644
--- a/python/nbdsh.py
+++ b/python/nbdsh.py
@@ -86,11 +86,13 @@ def __call__(self, parser, namespace, values, option_string=None):
parser.add_argument('--connect', dest='uri', action=SnippetAction,
help=argparse.SUPPRESS)
- parser.add_argument('-v', '--verbose', action='store_true')
+ parser.add_argument('-v', '--verbose', action='store_true',
+ help="enable verbose debugging")
short_options.append("-v")
long_options.append("--verbose")
- parser.add_argument('-V', '--version', action='store_true')
+ parser.add_argument('-V', '--version', action='store_true',
+ help="display version information")
short_options.append("-V")
long_options.append("--version")
@@ -127,7 +129,10 @@ def __call__(self, parser, namespace, values, option_string=None):
os.environ["LIBNBD_DEBUG"] = "1"
# Create the handle.
- if not args.n:
+ if args.n:
+ pass
+ else:
+ global h
h = nbd.NBD()
h.set_handle_name("nbdsh")
@@ -165,21 +170,35 @@ def line(x): lines.append(x)
def blank(): line("")
def example(ex, desc): line("%-34s # %s" % (ex, desc))
+ connect_hint = False
+ go_hint = False
blank()
line("Welcome to nbdsh, the shell for interacting with")
line("Network Block Device (NBD) servers.")
blank()
- if not args.n:
- line("The ‘nbd’ module has already been imported and there")
- line("is an open NBD handle called ‘h’.")
- blank()
- else:
+ if args.n:
line("The ‘nbd’ module has already been imported.")
blank()
example("h = nbd.NBD()", "Create a new handle.")
- if False: # args.uri is None:
+ connect_hint = True
+ else:
+ global h
+ state = h.connection_state()
+ state = state[:state.find(':')]
+ line("The ‘nbd’ module has already been imported and there")
+ line("is an open NBD handle called ‘h’ in state '%s'." %
state)
+ blank()
+ if h.aio_is_created():
+ connect_hint = True
+ if h.get_opt_mode():
+ go_hint = True
+ elif h.aio_is_negotiating():
+ go_hint = True
+ if connect_hint:
example('h.connect_tcp("remote", "10809")',
"Connect to a remote server.")
+ if go_hint:
+ example("h.opt_go()", "Finish option negotiation")
example("h.get_size()", "Get size of the remote disk.")
example("buf = h.pread(512, 0)", "Read the first sector.")
example("exit() or Ctrl-D", "Quit the shell")
--
2.38.1