fix arguments so init works, start on pygit2 stuff

master
nathaniel smith 2017-08-30 00:07:33 -07:00
parent a767fc477e
commit c35508340b
1 changed files with 55 additions and 24 deletions

View File

@ -7,6 +7,7 @@ from os.path import join as path_join
import click import click
import pygit2 import pygit2
from click import ClickException
from click.types import Path from click.types import Path
# TODO support reading from env # TODO support reading from env
@ -16,7 +17,7 @@ PREVIEW_PATH = expanduser('~/public_html/wiki')
LOCAL_REPOSITORY_PATH = expanduser('~/wiki') LOCAL_REPOSITORY_PATH = expanduser('~/wiki')
REPOSITORY_PATH = '/wiki' REPOSITORY_PATH = '/wiki'
PATH_TYPE_KWARGS = dict( DEFAULT_PATH_KWARGS = dict(
exists=True, exists=True,
writable=True, writable=True,
readable=True, readable=True,
@ -63,45 +64,71 @@ pass_config = click.make_pass_decorator(Config, ensure=True)
@click.option('--publish-path', @click.option('--publish-path',
default=PUBLISH_PATH, default=PUBLISH_PATH,
help='System level path to wiki for publishing.', help='System level path to wiki for publishing.',
type=Path(**PATH_TYPE_KWARGS)) type=Path(**DEFAULT_PATH_KWARGS))
@click.option('--preview-path',
default=PREVIEW_PATH,
help='Local path to wiki for previewing.',
type=Path(**PATH_TYPE_KWARGS))
@click.option('--local-repo-path',
default=LOCAL_REPOSITORY_PATH,
help='Path to shared wiki git repository.',
type=WikiRepo(**PATH_TYPE_KWARGS))
@click.option('--repo-path', @click.option('--repo-path',
default=REPOSITORY_PATH, default=REPOSITORY_PATH,
help='Path to your clone of the shared git repository.', help='Path to your clone of the shared git repository.',
type=WikiRepo(**PATH_TYPE_KWARGS)) type=WikiRepo(**DEFAULT_PATH_KWARGS))
@pass_config @pass_config
def main(config, site_name, publish_path, preview_path, def main(config, site_name, publish_path, repo_path):
local_repo_path, repo_path):
# 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?
config.site_name = site_name config.site_name = site_name
config.publish_path = publish_path config.publish_path = publish_path
config.preview_path = preview_path
config.local_repo_path = local_repo_path
config.repo_path = repo_path config.repo_path = repo_path
@main.command() @main.command()
@click.option('--local-repo-path',
default=LOCAL_REPOSITORY_PATH,
help='Path to shared wiki git repository.',
type=Path(file_okay=False))
@click.option('--preview-path',
default=PREVIEW_PATH,
help='Local path to wiki for previewing.',
type=Path(file_okay=False))
@pass_config @pass_config
def init(config): def init(config, local_repo_path, preview_path):
"""
This command, `wiki init`, does the following:
- clones REPOSITORY_PATH to LOCAL_REPOSITORY_PATH
- creates PREVIEW_PATH
- calls the preview command
"""
if path_exists(path_join(local_repo_path)):
raise ClickException(
'{} already exists. Have you already run wiki init?'.format(
local_repo_path))
if path_exists(path_join(preview_path)):
raise ClickException(
'{} already exists. Have you already run wiki init?'.format(
preview_path))
pygit2.clone_repository(
config.repo_path,
local_repo_path
)
@main.command()
@click.option('--local-repo-path',
default=LOCAL_REPOSITORY_PATH,
help='Path to shared wiki git repository.',
type=WikiRepo(**DEFAULT_PATH_KWARGS))
@click.option('--preview-path',
default=PREVIEW_PATH,
help='Local path to wiki for previewing.',
type=Path(**DEFAULT_PATH_KWARGS))
@pass_config
def preview(config, local_repo_path):
raise NotImplementedError() raise NotImplementedError()
@main.command() @main.command()
@click.option('--local-repo-path',
default=LOCAL_REPOSITORY_PATH,
help='Path to shared wiki git repository.',
type=WikiRepo(**DEFAULT_PATH_KWARGS))
@pass_config @pass_config
def preview(config): def publish(config, local_repo_path):
click.echo('SUP')
raise NotImplementedError()
@main.command()
@pass_config
def publish(config):
raise NotImplementedError() raise NotImplementedError()
@main.command() @main.command()
@ -110,6 +137,10 @@ def get(config):
raise NotImplementedError() raise NotImplementedError()
@main.command() @main.command()
@click.option('--local-repo-path',
default=LOCAL_REPOSITORY_PATH,
help='Path to shared wiki git repository.',
type=WikiRepo(**DEFAULT_PATH_KWARGS))
@pass_config @pass_config
def reset(config): def reset(config, local_repo_path):
raise NotImplementedError() raise NotImplementedError()