Skip to content

Commit 1fce578

Browse files
committed
Use cog to update --help in README, closes #82
1 parent b686230 commit 1fce578

File tree

3 files changed

+100
-59
lines changed

3 files changed

+100
-59
lines changed

README.md

Lines changed: 85 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -105,62 +105,90 @@ They will be populated with IDs that reference the new derived tables.
105105

106106
## csvs-to-sqlite --help
107107

108-
Usage: csvs-to-sqlite [OPTIONS] PATHS... DBNAME
109-
110-
PATHS: paths to individual .csv files or to directories containing .csvs
111-
112-
DBNAME: name of the SQLite database file to create
113-
114-
Options:
115-
-s, --separator TEXT Field separator in input .csv
116-
-q, --quoting INTEGER Control field quoting behavior per csv.QUOTE_*
117-
constants. Use one of QUOTE_MINIMAL (0),
118-
QUOTE_ALL (1), QUOTE_NONNUMERIC (2) or
119-
QUOTE_NONE (3).
120-
--skip-errors Skip lines with too many fields instead of
121-
stopping the import
122-
--replace-tables Replace tables if they already exist
123-
-t, --table TEXT Table to use (instead of using CSV filename)
124-
-c, --extract-column TEXT One or more columns to 'extract' into a
125-
separate lookup table. If you pass a simple
126-
column name that column will be replaced with
127-
integer foreign key references to a new table
128-
of that name. You can customize the name of the
129-
table like so:
130-
state:States:state_name
131-
This will pull unique values from the 'state'
132-
column and use them to populate a new 'States'
133-
table, with an id column primary key and a
134-
state_name column containing the strings from
135-
the original column.
136-
-d, --date TEXT One or more columns to parse into ISO formatted
137-
dates
138-
-dt, --datetime TEXT One or more columns to parse into ISO formatted
139-
datetimes
140-
-df, --datetime-format TEXT One or more custom date format strings to try
141-
when parsing dates/datetimes
142-
-pk, --primary-key TEXT One or more columns to use as the primary key
143-
-f, --fts TEXT One or more columns to use to populate a full-
144-
text index
145-
-i, --index TEXT Add index on this column (or a compound index
146-
with -i col1,col2)
147-
--shape TEXT Custom shape for the DB table - format is
148-
csvcol:dbcol(TYPE),...
149-
--filename-column TEXT Add a column with this name and populate with
150-
CSV file name
151-
--fixed-column <TEXT TEXT>... Populate column with a fixed string
108+
<!-- [[[cog
109+
import cog
110+
from csvs_to_sqlite import cli
111+
from click.testing import CliRunner
112+
runner = CliRunner()
113+
result = runner.invoke(cli.cli, ["--help"])
114+
help = result.output.replace("Usage: cli", "Usage: csvs-to-sqlite")
115+
cog.out(
116+
"```\n{}\n```".format(help)
117+
)
118+
]]] -->
119+
```
120+
Usage: csvs-to-sqlite [OPTIONS] PATHS... DBNAME
121+
122+
PATHS: paths to individual .csv files or to directories containing .csvs
123+
124+
DBNAME: name of the SQLite database file to create
125+
126+
Options:
127+
-s, --separator TEXT Field separator in input .csv
128+
-q, --quoting INTEGER Control field quoting behavior per csv.QUOTE_*
129+
constants. Use one of QUOTE_MINIMAL (0),
130+
QUOTE_ALL (1), QUOTE_NONNUMERIC (2) or
131+
QUOTE_NONE (3).
132+
133+
--skip-errors Skip lines with too many fields instead of
134+
stopping the import
135+
136+
--replace-tables Replace tables if they already exist
137+
-t, --table TEXT Table to use (instead of using CSV filename)
138+
-c, --extract-column TEXT One or more columns to 'extract' into a
139+
separate lookup table. If you pass a simple
140+
column name that column will be replaced with
141+
integer foreign key references to a new table
142+
of that name. You can customize the name of
143+
the table like so: state:States:state_name
144+
145+
This will pull unique values from the 'state'
146+
column and use them to populate a new 'States'
147+
table, with an id column primary key and a
148+
state_name column containing the strings from
149+
the original column.
150+
151+
-d, --date TEXT One or more columns to parse into ISO
152+
formatted dates
153+
154+
-dt, --datetime TEXT One or more columns to parse into ISO
155+
formatted datetimes
156+
157+
-df, --datetime-format TEXT One or more custom date format strings to try
158+
when parsing dates/datetimes
159+
160+
-pk, --primary-key TEXT One or more columns to use as the primary key
161+
-f, --fts TEXT One or more columns to use to populate a full-
162+
text index
163+
164+
-i, --index TEXT Add index on this column (or a compound index
165+
with -i col1,col2)
166+
167+
--shape TEXT Custom shape for the DB table - format is
168+
csvcol:dbcol(TYPE),...
169+
170+
--filename-column TEXT Add a column with this name and populate with
171+
CSV file name
172+
173+
--fixed-column <TEXT TEXT>... Populate column with a fixed string
152174
--fixed-column-int <TEXT INTEGER>...
153-
Populate column with a fixed integer
175+
Populate column with a fixed integer
154176
--fixed-column-float <TEXT FLOAT>...
155-
Populate column with a fixed float
156-
--no-index-fks Skip adding index to foreign key columns
157-
created using --extract-column (default is to
158-
add them)
159-
--no-fulltext-fks Skip adding full-text index on values extracted
160-
using --extract-column (default is to add them)
161-
--just-strings Import all columns as text strings by default
162-
(and, if specified, still obey --shape,
163-
--date/datetime, and --datetime-format)
164-
165-
--version Show the version and exit.
166-
--help Show this message and exit.
177+
Populate column with a fixed float
178+
--no-index-fks Skip adding index to foreign key columns
179+
created using --extract-column (default is to
180+
add them)
181+
182+
--no-fulltext-fks Skip adding full-text index on values
183+
extracted using --extract-column (default is
184+
to add them)
185+
186+
--just-strings Import all columns as text strings by default
187+
(and, if specified, still obey --shape,
188+
--date/datetime, and --datetime-format)
189+
190+
--version Show the version and exit.
191+
--help Show this message and exit.
192+
193+
```
194+
<!-- [[[end]]] -->

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ def get_long_description():
2929
"py-lru-cache~=0.1.4",
3030
"six",
3131
],
32-
extras_require={"test": ["pytest"]},
33-
tests_require=["csvs-to-sqlite[test]"],
32+
extras_require={"test": ["pytest", "cogapp"]},
3433
entry_points="""
3534
[console_scripts]
3635
csvs-to-sqlite=csvs_to_sqlite.cli:cli

tests/test_csvs_to_sqlite.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
from click.testing import CliRunner
22
from csvs_to_sqlite import cli
33
from six import string_types, text_type
4+
from cogapp import Cog
5+
import sys
6+
from io import StringIO
7+
import pathlib
48
import sqlite3
59

610
CSV = """county,precinct,office,district,party,candidate,votes
@@ -688,3 +692,13 @@ def test_just_strings_with_date_specified():
688692

689693
for name, gross, dt in actual:
690694
assert isinstance(gross, text_type)
695+
696+
697+
def test_if_cog_needs_to_be_run():
698+
_stdout = sys.stdout
699+
sys.stdout = StringIO()
700+
readme = pathlib.Path(__file__).parent.parent / "README.md"
701+
result = Cog().main(["cog", str(readme)])
702+
output = sys.stdout.getvalue()
703+
sys.stdout = _stdout
704+
assert output == readme.read_text()

0 commit comments

Comments
 (0)