You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ep...@apache.org on 2022/10/18 15:08:36 UTC

[airflow] 01/13: Respect "common" options value in breeze sub-commands. (#26264)

This is an automated email from the ASF dual-hosted git repository.

ephraimanierobi pushed a commit to branch v2-4-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit 5c073b52f63c900ab2429892695827ab4b1a57bc
Author: Ash Berlin-Taylor <as...@apache.org>
AuthorDate: Fri Sep 9 14:51:01 2022 +0100

    Respect "common" options value in breeze sub-commands. (#26264)
    
    This lets us run `breeze -v static-checks` and have the sub-command pick
    up the value from the parent context. If you specify a value for the
    subcommand, that is used in place of the global one.
    
    (The fact that `-v` was allowed before the sub-command but had no effect
    caused me lots of confusion)
    
    (cherry picked from commit 6da571f705bbfd92f8641f2604ef6f4c61bfa889)
---
 .../src/airflow_breeze/utils/common_options.py     | 30 +++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/dev/breeze/src/airflow_breeze/utils/common_options.py b/dev/breeze/src/airflow_breeze/utils/common_options.py
index 79b21d906e..d6f4699a2f 100644
--- a/dev/breeze/src/airflow_breeze/utils/common_options.py
+++ b/dev/breeze/src/airflow_breeze/utils/common_options.py
@@ -49,8 +49,32 @@ from airflow_breeze.utils.custom_param_types import (
 )
 from airflow_breeze.utils.recording import generating_command_images
 
+
+def _set_default_from_parent(ctx: "click.core.Context", option: "click.core.Option", value):
+    from click.core import ParameterSource
+
+    if (
+        ctx.parent
+        and option.name in ctx.parent.params
+        and ctx.get_parameter_source(option.name)
+        in (
+            ParameterSource.DEFAULT,
+            ParameterSource.DEFAULT_MAP,
+        )
+    ):
+        # Current value is the default, use the parent's value (i.e. for `breeze
+        # # -v static-checks` respect the "global" option)
+        value = ctx.parent.params[option.name]
+    return value
+
+
 option_verbose = click.option(
-    "-v", "--verbose", is_flag=True, help="Print verbose information about performed steps.", envvar='VERBOSE'
+    "-v",
+    "--verbose",
+    is_flag=True,
+    help="Print verbose information about performed steps.",
+    envvar='VERBOSE',
+    callback=_set_default_from_parent,
 )
 option_dry_run = click.option(
     "-D",
@@ -58,6 +82,7 @@ option_dry_run = click.option(
     is_flag=True,
     help="If dry-run is set, commands are only printed, not executed.",
     envvar='DRY_RUN',
+    callback=_set_default_from_parent,
 )
 option_answer = click.option(
     "-a",
@@ -65,6 +90,7 @@ option_answer = click.option(
     type=AnswerChoice(['y', 'n', 'q', 'yes', 'no', 'quit']),
     help="Force answer to questions.",
     envvar='ANSWER',
+    callback=_set_default_from_parent,
 )
 option_github_repository = click.option(
     '-g',
@@ -73,6 +99,7 @@ option_github_repository = click.option(
     default=APACHE_AIRFLOW_GITHUB_REPOSITORY,
     show_default=True,
     envvar='GITHUB_REPOSITORY',
+    callback=_set_default_from_parent,
 )
 option_python = click.option(
     '-p',
@@ -501,4 +528,5 @@ option_max_time = click.option(
     help="Maximum time that the command should take - if it takes longer, the command will fail.",
     type=click.IntRange(min=1),
     envvar='MAX_TIME',
+    callback=_set_default_from_parent,
 )