Skip to content

Commit

Permalink
Changed the name and delimiter of --option
Browse files Browse the repository at this point in the history
Fixes #259.
  • Loading branch information
agronholm committed Aug 5, 2023
1 parent 507362a commit e823bc8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Version history
**3.0.0rc3**

- Added support for SQLAlchemy 2 (PR by rbuffat with help from mhauru)
- Renamed ``--option`` to ``--options`` and made its values delimited by commas

**3.0.0rc2**

Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ The following built-in generators are available:
Generator-specific options
==========================

The following options can be turned on by passing them using ``--option`` (can be used
multiple times):
The following options can be turned on by passing them using ``--options`` (multiple
values must be delimited by commas, e.g. ``--options noconstraints,nobidi``):

* ``tables``

Expand Down
9 changes: 5 additions & 4 deletions src/sqlacodegen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ def main() -> None:
)
parser.add_argument("url", nargs="?", help="SQLAlchemy url to the database")
parser.add_argument(
"--option", nargs="*", help="options passed to the generator class"
"--options", help="options (comma-delimited) passed to the generator class"
)
parser.add_argument(
"--version", action="store_true", help="print the version number and exit"
)
parser.add_argument(
"--schemas", help="load tables from the given schemas (comma separated)"
"--schemas", help="load tables from the given schemas (comma-delimited)"
)
parser.add_argument(
"--generator",
Expand All @@ -36,7 +36,7 @@ def main() -> None:
help="generator class to use",
)
parser.add_argument(
"--tables", help="tables to process (comma-separated, default: all)"
"--tables", help="tables to process (comma-delimited, default: all)"
)
parser.add_argument("--noviews", action="store_true", help="ignore views")
parser.add_argument("--outfile", help="file to write output to (default: stdout)")
Expand All @@ -55,12 +55,13 @@ def main() -> None:
metadata = MetaData()
tables = args.tables.split(",") if args.tables else None
schemas = args.schemas.split(",") if args.schemas else [None]
options = set(args.option.split(",")) if args.options else set()
for schema in schemas:
metadata.reflect(engine, schema, not args.noviews, tables)

# Instantiate the generator
generator_class = generators[args.generator].load()
generator = generator_class(metadata, engine, set(args.option or ()))
generator = generator_class(metadata, engine, options)

# Open the target file (if given)
with ExitStack() as stack:
Expand Down

1 comment on commit e823bc8

@vinzenzweber
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agronholm I just spotted a bug: Line 24 defines "--options" with plural, but then in line 58 it is referred to with args.option with singular, no s. Hence the --options won't work in version 3.0.0rc3

Please sign in to comment.