Skip to content

Commit

Permalink
feat: prioritize cli arguments over environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Zane Clark committed Nov 8, 2024
1 parent f659acb commit db86db4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
5 changes: 2 additions & 3 deletions schemachange/config/get_merged_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ def get_merged_config(
env_kwargs: dict[str, str] = get_env_kwargs()
logger.debug("env_kwargs", **env_kwargs)

connection_name = env_kwargs.pop("connection_name", None)

cli_kwargs = parse_cli_args(sys.argv[1:])
logger.debug("cli_kwargs", **cli_kwargs)

Expand All @@ -55,8 +53,9 @@ def get_merged_config(
file_path=cli_kwargs.pop("connections_file_path", None)
)

connection_name = cli_kwargs.pop("connection_name", None)
if connection_name is None:
connection_name = cli_kwargs.pop("connection_name", None)
connection_name = env_kwargs.pop("connection_name", None)

config_folder = validate_directory(path=cli_kwargs.pop("config_folder", "."))
config_file_name = cli_kwargs.pop("config_file_name")
Expand Down
12 changes: 6 additions & 6 deletions tests/config/test_get_merged_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,12 @@ def get_connection_from_toml(file_path: Path, connection_name: str) -> dict:
"snowflake_warehouse": "cli_snowflake_warehouse",
"snowflake_database": "cli_snowflake_database",
"snowflake_schema": "cli_snowflake_schema",
"snowflake_authenticator": "env_snowflake_authenticator",
"snowflake_authenticator": "cli_snowflake_authenticator",
"snowflake_password": "env_snowflake_password",
"snowflake_private_key_path": "env_snowflake_private_key_path",
"snowflake_private_key_path": "cli_snowflake_private_key_path",
"snowflake_token_path": "cli_snowflake_token_path",
"connections_file_path": Path("cli_connections_file_path"),
"connection_name": "env_connection_name",
"connection_name": "cli_connection_name",
"change_history_table": "cli_change_history_table",
"create_change_history_table": False,
"autocommit": False,
Expand Down Expand Up @@ -756,8 +756,8 @@ def test_invalid_config_folder(mock_parse_cli_args, _):
"snowflake_warehouse": "snowflake-warehouse-from-cli",
"snowflake_database": "snowflake-database-from-cli",
"snowflake_schema": "snowflake-schema-from-cli",
"snowflake_authenticator": "env_snowflake_authenticator",
"snowflake_private_key_path": "env_snowflake_private_key_path",
"snowflake_authenticator": "snowflake-authenticator-from-cli",
"snowflake_private_key_path": "snowflake-private-key-path-from-cli",
"snowflake_token_path": "snowflake-token-path-from-cli",
"change_history_table": "change-history-table-from-cli",
"config_vars": {
Expand All @@ -772,7 +772,7 @@ def test_invalid_config_folder(mock_parse_cli_args, _):
"query_tag": "query-tag-from-cli",
"snowflake_oauth_token": "env_snowflake_token",
"oauth_config": {"oauth_config_variable": "cli_oauth_config_value"},
"connection_name": "anotherconnection",
"connection_name": "myaltconnection",
"connections_file_path": assets_path / "alt-connections.toml",
"snowflake_password": "env_snowflake_password",
},
Expand Down
4 changes: 2 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ def get_connection_from_toml(file_path: Path, connection_name: str) -> dict:
"snowflake_schema": get_snowflake_identifier_string(
"snowflake-schema-from-cli", "placeholder"
),
"snowflake_authenticator": "snowflake_jwt",
"snowflake_private_key_path": assets_path / "alt_private_key.txt",
"snowflake_authenticator": "externalbrowser",
"snowflake_private_key_path": assets_path / "private_key.txt",
"change_history_table": ChangeHistoryTable(
database_name="db",
schema_name="schema",
Expand Down

0 comments on commit db86db4

Please sign in to comment.