Skip to content

Commit 99d390d

Browse files
committed
simplifying command line by removing output option (you can just redirect output to a file if wanted, more flexible) and fixing tests
1 parent dcde174 commit 99d390d

File tree

2 files changed

+9
-26
lines changed

2 files changed

+9
-26
lines changed

overpass/cli.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from __future__ import print_function
33
import click
44
import geojson
5-
5+
import sys
66
import overpass
77

88

@@ -13,21 +13,13 @@
1313
@click.option('--responseformat', default='geojson', help="""Format to save the data.
1414
Options are 'geojson' and 'osm'. Default format is geojson.""")
1515
@click.argument('query', type=str)
16-
@click.argument('output_file', type=click.Path())
17-
def cli(timeout, endpoint, responseformat, query, output_file):
18-
"""Run query and save the result in output_file"""
19-
16+
def cli(timeout, endpoint, responseformat, query):
17+
"""Run query"""
2018
api = overpass.API(timeout=timeout, endpoint=endpoint)
21-
2219
if responseformat not in api.SUPPORTED_FORMATS:
2320
print("format {} not supported. Supported formats: {}".format(
2421
responseformat,
25-
api.SUPPORTED_FORMATS.join(", ")))
22+
", ".join(api.SUPPORTED_FORMATS)))
23+
sys.exit(1)
2624
result = api.Get(query, responseformat=responseformat)
27-
with open(output_file, 'w') as f:
28-
if responseformat=="geojson":
29-
geojson.dump(result, f, indent=2, sort_keys=True)
30-
else:
31-
f.write(result.encode('utf-8'))
32-
f.close()
33-
print('File saved at %s.' % output_file)
25+
click.echo(result)

tests/test_cli.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,18 @@
44
from overpass.cli import cli
55
from nose.tools import nottest
66

7-
#@nottest
87
def test_cli():
8+
99
runner = CliRunner()
1010
with runner.isolated_filesystem():
1111
result = runner.invoke(cli, [
12-
'--timeout', 40,
13-
'--endpoint', 'http://overpass-api.de/api/interpreter',
14-
'node(area:3600362504)[amenity=cafe]', 'out.geojson'
15-
])
12+
'node(40.704,-74.010,40.708,-74.013)[amenity=cafe]'])
1613
assert result.exit_code == 0
17-
assert exists('out.geojson')
1814

19-
#@nottest
2015
def test_cli_xml():
2116
runner = CliRunner()
2217
with runner.isolated_filesystem():
2318
result = runner.invoke(cli, [
24-
'--timeout', 40,
25-
'--endpoint', 'http://overpass-api.de/api/interpreter',
2619
'--responseformat', 'osm',
27-
'node(area:3600362504)[amenity=cafe]', 'out.osm'
28-
])
20+
'node(40.704,-74.010,40.708,-74.013)[amenity=cafe]'])
2921
assert result.exit_code == 0
30-
assert exists('out.osm')

0 commit comments

Comments
 (0)