rename reset -> sync, clean up docstrings

master
nathaniel smith 2017-10-03 16:07:41 -07:00
parent 2360b25d73
commit a6b8a15b1e
1 changed files with 15 additions and 11 deletions

View File

@ -55,6 +55,8 @@ pass_config = click.make_pass_decorator(Config, ensure=True)
type=WikiRepo(**DEFAULT_PATH_KWARGS)) type=WikiRepo(**DEFAULT_PATH_KWARGS))
@pass_config @pass_config
def main(config, site_name, publish_path, repo_path): def main(config, site_name, publish_path, repo_path):
"""This tool helps manage a wiki that exists as a git repository on a
social server."""
# TODO click does not appear to call expanduser on things. it'd be nice to # TODO click does not appear to call expanduser on things. it'd be nice to
# opt into that with the Path type. Should click be patched? Or should we # opt into that with the Path type. Should click be patched? Or should we
# use a custom Path type? # use a custom Path type?
@ -70,10 +72,7 @@ def main(config, site_name, publish_path, repo_path):
@pass_config @pass_config
def init(config, local_repo_path, preview_path): def init(config, local_repo_path, preview_path):
""" """
This command, `wiki init`, does the following: Initializes a local copy of the shared wiki.
- clones REPOSITORY_PATH to LOCAL_REPOSITORY_PATH
- creates PREVIEW_PATH
- calls the preview command
""" """
if os.path.exists(os.path.join(local_repo_path)): if os.path.exists(os.path.join(local_repo_path)):
raise ClickException( raise ClickException(
@ -113,6 +112,7 @@ def init(config, local_repo_path, preview_path):
type=Path(**DEFAULT_PATH_KWARGS)) type=Path(**DEFAULT_PATH_KWARGS))
@pass_config @pass_config
def preview(config, preview_path, local_repo_path): def preview(config, preview_path, local_repo_path):
"""Compiles all the files in the local wiki repository."""
click.confirm( click.confirm(
WIPE_PROMPT.format(preview_path), WIPE_PROMPT.format(preview_path),
abort=True) abort=True)
@ -124,6 +124,8 @@ def preview(config, preview_path, local_repo_path):
help='Path to local clone of wiki repository.', type=WikiRepo(**DEFAULT_PATH_KWARGS)) help='Path to local clone of wiki repository.', type=WikiRepo(**DEFAULT_PATH_KWARGS))
@pass_config @pass_config
def publish(config, local_repo_path): def publish(config, local_repo_path):
"""Commits any local changes, syncs with the shared wiki repository (in
both directions), and recompiles the shared wiki."""
if os.path.exists(LOCK_PATH): if os.path.exists(LOCK_PATH):
raise ClickException('The wiki lock file already exists. Seems like someone else is compiling.') raise ClickException('The wiki lock file already exists. Seems like someone else is compiling.')
@ -166,6 +168,9 @@ def publish(config, local_repo_path):
@click.argument('path') @click.argument('path')
@pass_config @pass_config
def get(config, preview, preview_path, path): def get(config, preview, preview_path, path):
"""Given a path to a file in the wiki, open it in a browser. Uses
sensible-browser. No need to specify the extension; e.g., 'wiki get
editors/emacs' will show /wiki/editors/emacs.html in the browser."""
read_path = config.publish_path read_path = config.publish_path
if preview: if preview:
read_path = preview_path read_path = preview_path
@ -182,16 +187,15 @@ def get(config, preview, preview_path, path):
subprocess.run(['sensible-browser', path]) subprocess.run(['sensible-browser', path])
# TODO sync command that:
# - offers to wipe any local changes or commit them
# - pulls from origin
# - pushes to origin
@main.command() @main.command()
@click.option('--local-repo-path', default=LOCAL_REPOSITORY_PATH, @click.option('--local-repo-path', default=LOCAL_REPOSITORY_PATH,
help='Path to shared wiki git repository.', type=WikiRepo(**DEFAULT_PATH_KWARGS)) help='Path to shared wiki git repository.', type=WikiRepo(**DEFAULT_PATH_KWARGS))
@pass_config @pass_config
def reset(config, local_repo_path): def sync(config, local_repo_path):
"""Syncs a local copy of the wiki with the shared copy. Resets any
outstanding changes. If those changes should be kept, publish them
first."""
if git.dirty(local_repo_path):
click.confirm("This will overwrite any changes you've made locally. Proceed?", abort=True) click.confirm("This will overwrite any changes you've made locally. Proceed?", abort=True)
git.reset_from_origin(local_repo_path) git.reset_from_origin(local_repo_path)