Skip to content

Commit

Permalink
feat: deprecate cli connection arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Zane Clark committed Nov 14, 2024
1 parent 1beb3a5 commit eb8882b
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions schemachange/config/parse_cli_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,33 @@
import argparse
import json
import logging
import sys
from enum import Enum

import structlog

logger = structlog.getLogger(__name__)


class DeprecateConnectionArgAction(argparse.Action):
def __init__(self, *args, **kwargs):
self.call_count = 0
if "help" in kwargs:
kwargs["help"] = (
f'[DEPRECATED - Set in connections.toml instead.] {kwargs["help"]}'
)
super().__init__(*args, **kwargs)

def __call__(self, parser, namespace, values, option_string=None):
if self.call_count == 0:
sys.stderr.write(
f"{', '.join(self.option_strings)} is deprecated. It will be ignored in future versions.\n"
)
sys.stderr.write(self.help + "\n")
self.call_count += 1
setattr(namespace, self.dest, values)


class EnumAction(argparse.Action):
"""
Argparse action for handling Enums
Expand Down Expand Up @@ -101,68 +121,78 @@ def parse_cli_args(args) -> dict:
subcommands = parser.add_subparsers(dest="subcommand")
parser_deploy = subcommands.add_parser("deploy", parents=[parent_parser])

parser_deploy.register("action", "deprecate", DeprecateConnectionArgAction)
parser_deploy.add_argument(
"-a",
"--snowflake-account",
type=str,
help="The name of the snowflake account (e.g. xy12345.east-us-2.azure)",
required=False,
action="deprecate",
)
parser_deploy.add_argument(
"-u",
"--snowflake-user",
type=str,
help="The name of the snowflake user",
required=False,
action="deprecate",
)
parser_deploy.add_argument(
"-r",
"--snowflake-role",
type=str,
help="The name of the default role to use",
required=False,
action="deprecate",
)
parser_deploy.add_argument(
"-w",
"--snowflake-warehouse",
type=str,
help="The name of the default warehouse to use. Can be overridden in the change scripts.",
required=False,
action="deprecate",
)
parser_deploy.add_argument(
"-d",
"--snowflake-database",
type=str,
help="The name of the default database to use. Can be overridden in the change scripts.",
required=False,
action="deprecate",
)
parser_deploy.add_argument(
"-s",
"--snowflake-schema",
type=str,
help="The name of the default schema to use. Can be overridden in the change scripts.",
required=False,
action="deprecate",
)
parser_deploy.add_argument(
"-A",
"--snowflake-authenticator",
type=str,
help="The Snowflake Authenticator to use. One of snowflake, oauth, externalbrowser, or https://<okta_account_name>.okta.com",
required=False,
action="deprecate",
)
parser_deploy.add_argument(
"-k",
"--snowflake-private-key-path",
type=str,
help="Path to file containing private key.",
required=False,
action="deprecate",
)
parser_deploy.add_argument(
"-t",
"--snowflake-token-path",
type=str,
help="Path to the file containing the OAuth token to be used when authenticating with Snowflake.",
required=False,
action="deprecate",
)
parser_deploy.add_argument(
"--connections-file-path",
Expand Down

0 comments on commit eb8882b

Please sign in to comment.