Skip to content

Commit

Permalink
Support a custom root via '--root'
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Feb 24, 2017
1 parent 2a474a3 commit 21a67d2
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 7 deletions.
1 change: 1 addition & 0 deletions .appveyor.yml
Expand Up @@ -23,3 +23,4 @@ build: off
test_script:
- make check
- make test
- make demo
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -20,6 +20,7 @@ install:
script:
- make check
- make test
- make demo

after_success:
- pip install coveralls scrutinizer-ocular
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Expand Up @@ -76,6 +76,14 @@ watch: install .clean-test ## Continuously run all CI tasks when files chanage
run: install
$(PYTHON) $(PACKAGE)/__main__.py

.PHONY: demo
demo: install
$(BIN)/osmerge new --root=demo
# TODO: support these commands:
# $(BIN)/osmerge build --root=demo
# $(BIN)/osmerge update --root=demo
# $(BIN)/osmerge build --root=demo

# SYSTEM DEPENDENCIES ##########################################################

.PHONY: doctor
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions sample/Makefile → demo/Makefile
Expand Up @@ -7,19 +7,19 @@ all: build
build: docs/osmerge.geojson

docs/osmerge.geojson: tmp/merged.json
osmerge convert $< $@
osmerge convert $< $@

tmp/merged.json: tmp/filtered.json osmerge.csv
osmerge merge $< $@
osmerge merge $< $@

tmp/filtered.json: tmp/base.json osmerge.yml
osmerge filter $< $@
osmerge filter $< $@

tmp/base.json: osmerge.yml
osmerge download $@
osmerge download $@

# CLEANUP ######################################################################

.PHONY: clean
clean:
rm -rf tmp
rm -rf tmp
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 12 additions & 2 deletions osmerge/cli.py
@@ -1,6 +1,8 @@
#!/usr/bin/env python

import os
import logging
from pathlib import Path

import click

Expand All @@ -11,19 +13,27 @@
log = logging.getLogger(__name__)


@click.group()
@click.group(context_settings=dict(help_option_names=['-h', '--help']))
@click.version_option(message=VERSION)
def main():
logging.basicConfig(level=logging.INFO)
logging.getLogger('yorm').setLevel(logging.WARNING)


@main.command()
def new():
@click.option('-r', '--root', type=Path, default=Path.cwd)
def new(root):
_enter(root)
Project.generate()
Config.generate_example()
Data.generate_example()


def _enter(path):
"""Create and enter the root directory."""
path.mkdir(parents=True, exist_ok=True)
os.chdir(str(path))


if __name__ == '__main__':
main()
6 changes: 6 additions & 0 deletions tests/test_cli.py
Expand Up @@ -50,3 +50,9 @@ def it_generates_a_sample_project(cli):
"osmerge.csv", # data set
"osmerge.yml", # config file
]

def it_can_be_run_from_a_custom_root(cli):
cmd = cli('new', '--root=foobar')

expect(cmd.returncode) == 0
expect(cmd.files_created).contains("foobar/docs/index.html")

0 comments on commit 21a67d2

Please sign in to comment.