Skip to content

Commit 85589cf

Browse files
author
EliuX
committed
Close #10 Apply review suggestions
1 parent 5f521dd commit 85589cf

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@ a link to the swagger.json with the definition of the api.
5252
5353
## CLI
5454
55-
There are available commands aware of the API that can be verify useful for you. You
55+
There are available commands, aware of the API, that can be very helpful to you. You
5656
can check them out by running
5757
58-
```angular2
58+
```
5959
python cli.py
6060
```
6161
6262
If you want to run an specific command, e.g. `gen_swagger_json`, specify it as a param
6363
as well as its correspondent options.
6464
65-
```angular2
65+
```
6666
python cli.py gen_swagger_json -f ~/Downloads/swagger.json
6767
```

cli.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,48 @@
77
import os
88

99
from flask import json
10-
from time_tracker_api import create_app
1110
from flask_script import Manager
11+
12+
from time_tracker_api import create_app
1213
from time_tracker_api.api import api
1314

1415
app = create_app()
1516
cli_manager = Manager(app)
1617

1718

1819
@cli_manager.command
19-
@cli_manager.option('-f', '--filename', help='Path of the swagger file. By default swagger.json')
20+
@cli_manager.option('-f', '--filename',
21+
dest='filename',
22+
help='Path of the swagger file. By default swagger.json')
2023
def gen_swagger_json(filename='swagger.json'):
2124
""" Exports swagger specifications in json format """
2225
schema_json_data = json.dumps(api.__schema__)
2326
save_data(schema_json_data, filename)
2427

2528

2629
@cli_manager.command
27-
@cli_manager.option('-f', '--filename', dest='filename', help='Path of the postman collection file.'
28-
'By default it is timetracker-api-postman-collection.json')
29-
def gen_postman_collection(filename='timetracker-api-postman-collection.json'):
30+
@cli_manager.option('-f', '--filename',
31+
dest='filename',
32+
help='Path of the postman collection file.'
33+
'By default it is timetracker-api-postman-collection.json')
34+
@cli_manager.option('-b', '--base-url-placeholder',
35+
dest='base_url_placeholder',
36+
help='Text used as placeholder. E.g. {{timetracker_api_host}}.'
37+
'By default the base url will be http://localhost')
38+
def gen_postman_collection(filename='timetracker-api-postman-collection.json',
39+
base_url_placeholder=None):
3040
""" Generates a Postman collection for the API """
3141
data = api.as_postman(urlvars=False, swagger=True)
3242
postman_collection_json_data = json.dumps(data)
33-
parsed_json = postman_collection_json_data.replace("http://localhost", '{{timetracker_api_host}}')
43+
if base_url_placeholder is not None:
44+
parsed_json = postman_collection_json_data.replace("http://localhost", base_url_placeholder)
45+
else:
46+
parsed_json = postman_collection_json_data
47+
3448
save_data(parsed_json, filename)
3549

3650

37-
def save_data(data, filename):
51+
def save_data(data: str, filename: str) -> None:
3852
""" Save text content to a file """
3953
if filename:
4054
try:

0 commit comments

Comments
 (0)