Skip to content
Merged
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
13 changes: 11 additions & 2 deletions src/fmu_settings_cli/init/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from fmu_settings_cli.prints import (
error,
info,
success,
validation_error,
validation_warning,
Expand Down Expand Up @@ -53,7 +54,7 @@ def is_fmu_project(path: Path) -> tuple[bool, list[str]]:


@init_cmd.callback(invoke_without_command=True)
def init(
def init( # noqa: PLR0912
ctx: typer.Context,
force: Annotated[
bool,
Expand Down Expand Up @@ -123,7 +124,7 @@ def init(
success("Successfully imported masterdata from global config/variables.")

try:
init_fmu_directory(cwd, global_config=global_config)
fmu_dir = init_fmu_directory(cwd, global_config=global_config)
except FileExistsError as e:
error(
"Unable to create .fmu directory.",
Expand Down Expand Up @@ -152,4 +153,12 @@ def init(
)
raise typer.Abort from e

if fmu_dir.config.load().masterdata is not None:
info(
"Project stratigraphy was not imported by 'fmu init'.",
suggestion=(
"Open 'fmu settings' to import stratigraphy from RMS and map it "
"to SMDA."
),
)
success("All done! You can now use the 'fmu settings' application.")
2 changes: 1 addition & 1 deletion src/fmu_settings_cli/prints.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def warning(
suggestion: Optional suggestion or additional info after the reason
**kwargs: Additional arguments to past to console.print().
"""
_print_stderr(_WARNING, *content, reason=reason, suggestion=reason, **kwargs)
_print_stderr(_WARNING, *content, reason=reason, suggestion=suggestion, **kwargs)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

also fix warning to use suggestion



def error(
Expand Down
2 changes: 2 additions & 0 deletions tests/test_init/test_init_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ def test_init_adds_global_variables_with_masterdata(
assert result.exit_code == 0
assert "Success: Successfully imported masterdata" in result.stdout
assert "Success: All done!" in result.stdout
assert "Info: Project stratigraphy was not imported by 'fmu init'." in result.stdout
assert "Open 'fmu settings' to import stratigraphy from RMS" in result.stdout

fmu_dir = find_nearest_fmu_directory()
fmu_dir_cfg = fmu_dir.config.load()
Expand Down
3 changes: 2 additions & 1 deletion tests/test_prints.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ def test_success_and_info_print_to_stdout() -> None:
def test_warning_and_error_print_to_stderr() -> None:
"""Tests that 'warning' and 'error' print as expected."""
with patch("sys.stderr", new=StringIO()) as mock_stderr:
warning("Bad", reason="Because")
warning("Bad", reason="Because", suggestion="Do this next")
error("Failed", suggestion="Fix it")

err = mock_stderr.getvalue()
assert "Warning: Bad" in err
assert "Reason: Because" in err
assert "→ Do this next" in err
assert "Error: Failed" in err
assert "→ Fix it" in err

Expand Down