Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-46240: Turn on generation of IDs by default #108

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changes/DM-46240.api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
By default, generate the `@id` field for any schema object if it is missing.
To turn this off, use `felis --no-id-generation [command]`.
7 changes: 6 additions & 1 deletion python/felis/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@
help="Felis log file path",
)
@click.option(
"--id-generation", is_flag=True, help="Generate IDs for all objects that do not have them", default=False
"--id-generation/--no-id-generation",
is_flag=True,
help="Generate IDs for all objects that do not have them",
default=True,
)
@click.pass_context
def cli(ctx: click.Context, log_level: str, log_file: str | None, id_generation: bool) -> None:
Expand All @@ -71,6 +74,8 @@ def cli(ctx: click.Context, log_level: str, log_file: str | None, id_generation:
ctx.obj["id_generation"] = id_generation
if ctx.obj["id_generation"]:
logger.info("ID generation is enabled")
else:
logger.info("ID generation is disabled")
if log_file:
logging.basicConfig(filename=log_file, level=log_level)
else:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ def test_id_generation(self) -> None:
self.assertEqual(result.exit_code, 0)

def test_no_id_generation(self) -> None:
"""Test that loading a schema without IDs fails if ID generation is not
enabled.
"""Test the ``--no-id-generation`` flag which should raise an
exception.
"""
test_yaml = os.path.join(TESTDIR, "data", "test_id_generation.yaml")
runner = CliRunner()
result = runner.invoke(cli, ["validate", test_yaml], catch_exceptions=False)
result = runner.invoke(cli, ["--no-id-generation", "validate", test_yaml], catch_exceptions=False)
self.assertNotEqual(result.exit_code, 0)

def test_validation_flags(self) -> None:
Expand Down
Loading