diff --git a/airflow/cli/__main__.py b/airflow/cli/__main__.py index 2ae6c91cb39f1..e2ee6a0178457 100644 --- a/airflow/cli/__main__.py +++ b/airflow/cli/__main__.py @@ -18,6 +18,9 @@ # under the License. from airflow.cli import airflow_cmd +from airflow.cli.commands import version + +__all__ = ["version"] if __name__ == '__main__': airflow_cmd(obj={}) diff --git a/airflow/cli/commands/version.py b/airflow/cli/commands/version.py new file mode 100644 index 0000000000000..b90f37ad8ace7 --- /dev/null +++ b/airflow/cli/commands/version.py @@ -0,0 +1,28 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""Version command""" +from airflow.cli import airflow_cmd + + +@airflow_cmd.command('version') +def version(): + """Displays Airflow version at the command line""" + from rich.console import Console + + import airflow + + Console().print(airflow.__version__) diff --git a/tests/cli/commands/test_version.py b/tests/cli/commands/test_version.py new file mode 100644 index 0000000000000..fa767345d5335 --- /dev/null +++ b/tests/cli/commands/test_version.py @@ -0,0 +1,32 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import unittest + +from click.testing import CliRunner + +import airflow +from airflow.cli.commands.version import version + + +class TestCliVersion(unittest.TestCase): + def test_cli_version(self): + runner = CliRunner() + response = runner.invoke(version) + + assert response.exit_code == 0 + assert airflow.__version__ in response.output