From 0d6064e7f3bf15a549910145d68cfebd18aced21 Mon Sep 17 00:00:00 2001 From: Marian Beermann Date: Wed, 7 Jun 2017 16:29:37 +0200 Subject: [PATCH] docs: fix build_man for relocated examples --- docs/usage/create.rst | 2 +- docs/usage/extract.rst | 2 +- docs/usage/init.rst | 2 +- setup.py | 25 +++++++++++++++++++++++-- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/docs/usage/create.rst b/docs/usage/create.rst index 712157356..2f05be396 100644 --- a/docs/usage/create.rst +++ b/docs/usage/create.rst @@ -67,4 +67,4 @@ Examples # Backing up relative paths by moving into the correct directory first $ cd /home/user/Documents # The root directory of the archive will be "projectA" - $ borg create /path/to/repo::daily-projectA-{now:%Y-%m-%d} projectA \ No newline at end of file + $ borg create /path/to/repo::daily-projectA-{now:%Y-%m-%d} projectA diff --git a/docs/usage/extract.rst b/docs/usage/extract.rst index 62cbbdc6a..be9268962 100644 --- a/docs/usage/extract.rst +++ b/docs/usage/extract.rst @@ -26,4 +26,4 @@ Examples .. Note:: Currently, extract always writes into the current working directory ("."), - so make sure you ``cd`` to the right place before calling ``borg extract``. \ No newline at end of file + so make sure you ``cd`` to the right place before calling ``borg extract``. diff --git a/docs/usage/init.rst b/docs/usage/init.rst index 46355b0d1..97860a15a 100644 --- a/docs/usage/init.rst +++ b/docs/usage/init.rst @@ -14,4 +14,4 @@ Examples $ borg init --encryption=repokey-blake2 user@hostname:backup # Remote repository (store the key your home dir) - $ borg init --encryption=keyfile user@hostname:backup \ No newline at end of file + $ borg init --encryption=keyfile user@hostname:backup diff --git a/setup.py b/setup.py index 683799773..434145032 100644 --- a/setup.py +++ b/setup.py @@ -358,6 +358,23 @@ class build_man(Command): """) + usage_group = { + 'break-lock': 'lock', + 'with-lock': 'lock', + + 'change-passphrase': 'key', + 'key_change-passphrase': 'key', + 'key_export': 'key', + 'key_import': 'key', + 'key_migrate-to-repokey': 'key', + + 'export-tar': 'tar', + + 'benchmark_crud': 'benchmark', + + 'umount': 'mount', + } + def initialize_options(self): pass @@ -495,11 +512,15 @@ class build_man(Command): write() def write_examples(self, write, command): - with open('docs/usage.rst') as fd: + command = command.replace(' ', '_') + with open('docs/usage/%s.rst' % self.usage_group.get(command, command)) as fd: usage = fd.read() - usage_include = '.. include:: usage/%s.rst.inc' % command + usage_include = '.. include:: %s.rst.inc' % command begin = usage.find(usage_include) end = usage.find('.. include', begin + 1) + # If a command has a dedicated anchor, it will occur before the command's include. + if 0 < usage.find('.. _', begin + 1) < end: + end = usage.find('.. _', begin + 1) examples = usage[begin:end] examples = examples.replace(usage_include, '') examples = examples.replace('Examples\n~~~~~~~~', '')