diff --git a/README.md b/README.md index 6aff3b1..1b257e6 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,7 @@ A typical execution of the container will look like the following, the container $ docker run --rm -ti \ --publish 8080:80 \ --mount type=bind,source=${PWD},target=/src,readonly \ - spjmurray/couchbase-antora-preview:latest \ - --repo url=/src,start_path=docs/user + spjmurray/couchbase-antora-preview:latest ``` ## Arguments @@ -59,15 +58,19 @@ This argument is optional and defaults to 8080. This argument is passed to the container entry point. This specifies a repository to be added to the Antora playbook. +This argument is optional and will default to `url=/src`. The `url` parameter is required and specifies the path to a mounted git repository or a reference to GitHub. This must match the mount target specified in the [`--mount`](#mount) argument. The `branches` parameter is optional and specifies which branches to use for document generation. Branches are colon (`:`) separated. +If not specified then the current branch is automatically detected from git. The `start_path` parameter is used to select the path within the repository to find the `antora.yml` module configuration. For further details please consult the [Antora documentation](https://docs.antora.org/antora/1.1/playbook/configure-content-sources/). +If not specified then the Antora configuration is automatically detected by walking the git repository. +The first match is chosen. ## Contributing diff --git a/src/run b/src/run index 2e886ba..8dfdbf3 100755 --- a/src/run +++ b/src/run @@ -154,6 +154,11 @@ def init_slumber(): def parse_repos(args): """Parses raw repo arguments and expands them into a repos argument""" + # If no repos are provided provide a default + if not args.repo: + logging.info('Using default repo path /src') + args.repo = ['url=/src'] + # Process specified repositories. # We expect 'url=/mnt/docs,branches=master:1.0.0,start_path=docs' repos = [] @@ -165,16 +170,39 @@ def parse_repos(args): for req in required: if req not in repo_args: logging.error('Missing %s argument in repo specification') + + # Enter the git repo for the duration + os.chdir(repo_args['url']) + + # Parse the selected branches or derive the current branch if 'branches' in repo_args: repo_args['branches'] = repo_args['branches'].split(':') else: - # Derive the current branch if repo_args['url'].startswith('/'): - os.chdir(repo_args['url']) stdout, _ = Executor.execute(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) - repo_args['branches'] = [stdout.strip()] + branch = stdout.strip() + logging.info("Using branch %s", branch) + repo_args['branches'] = [branch] + + # Derive the start path + if 'start_path' not in repo_args: + done = False + for root, _, files in os.walk('.'): + if done: + break + for filename in files: + if filename == 'antora.yml': + logging.info('Using path %s', root) + repo_args['start_path'] = root + done = True + break + if not done: + logging.error('Unable to find antora.yml') + sys.exit(1) + repos.append(repo_args) - setattr(args, 'repos', repos) + + args.repos = repos def main(): @@ -183,7 +211,7 @@ def main(): parser = argparse.ArgumentParser() parser.add_argument('-d', '--debug', action='store_true', default=False) parser.add_argument('-p', '--port', default='8080') - parser.add_argument('-r', '--repo', action='append', required=True) + parser.add_argument('-r', '--repo', action='append') args = parser.parse_args() init_logging(args)