From 635ebc1f4ddd7437cb6b5ba3b4d42bc52bf4e616 Mon Sep 17 00:00:00 2001 From: Marc Bonnici Date: Tue, 19 Dec 2017 17:56:57 +0000 Subject: [PATCH] commands/show: Improved formatting of show command --- wa/commands/show.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/wa/commands/show.py b/wa/commands/show.py index a9a6acb5..26083def 100644 --- a/wa/commands/show.py +++ b/wa/commands/show.py @@ -40,10 +40,14 @@ class ShowCommand(Command): plugin = get_plugin(name) if plugin: rst_output = get_rst_from_plugin(plugin) + plugin_name = plugin.name + kind = '{}:'.format(plugin.kind) else: target = get_target_description(name) if target: rst_output = get_rst_from_target(target) + plugin_name = target.name + kind = 'target:' if not rst_output: raise NotFoundError('Could not find plugin or alias "{}"'.format(name)) @@ -51,10 +55,15 @@ class ShowCommand(Command): if which('pandoc'): p = Popen(['pandoc', '-f', 'rst', '-t', 'man'], stdin=PIPE, stdout=PIPE, stderr=PIPE) output, _ = p.communicate(rst_output) + # Make sure to double escape back slashes output = output.replace('\\', '\\\\\\') - # Correctly format the tile of the man page - output = output.replace('.SH', '.TH', 1) + + # Correctly format the title and page number of the man page + title, body = output.split('\n', 1) + title = '.TH {}{} 1'.format(kind, plugin_name) + output = '\n'.join([title, body]) + call('echo "{}" | man -l -'.format(escape_double_quotes(output)), shell=True) else: print rst_output