Skip to content

Commit

Permalink
Add error for missing command (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
samkellerhals authored May 31, 2023
1 parent 2ca2b5b commit 69248f1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion liskov/src/icon4py/liskov/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import click

from icon4py.common.logger import setup_logger
from icon4py.liskov.external.exceptions import MissingCommandError
from icon4py.liskov.pipeline.collection import (
load_gt4py_stencils,
parse_fortran_file,
Expand All @@ -31,7 +32,7 @@
def main(ctx):
"""Command line interface for interacting with the ICON-Liskov DSL Preprocessor."""
if ctx.invoked_subcommand is None:
click.echo(
raise MissingCommandError(
"Need to choose one of the following commands:\nintegrate\nserialise"
)

Expand Down
4 changes: 4 additions & 0 deletions liskov/src/icon4py/liskov/external/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ class UnknownStencilError(Exception):

class IncompatibleFieldError(Exception):
pass


class MissingCommandError(Exception):
pass
8 changes: 8 additions & 0 deletions liskov/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import pytest

from icon4py.liskov.cli import main
from icon4py.liskov.external.exceptions import MissingCommandError
from icon4py.testutils.liskov_fortran_samples import (
CONSECUTIVE_STENCIL,
FREE_FORM_STENCIL,
Expand Down Expand Up @@ -67,3 +68,10 @@ def test_cli(make_f90_tmpfile, cli, outfile, file_name, file_content, cmd, cmd_f
args = [cmd, *cmd_flags, fpath, outfile]
result = cli.invoke(main, args)
assert result.exit_code == 0


def test_cli_missing_command(cli):
args = []
result = cli.invoke(main, args)
assert result.exit_code == 1
assert isinstance(result.exception, MissingCommandError)

0 comments on commit 69248f1

Please sign in to comment.