Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions airflow-core/src/airflow/cli/cli_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ def string_lower_type(val):
ARG_VAR_EXPORT = Arg(
("file",),
help="Export all variables to JSON file",
type=argparse.FileType("w", encoding="UTF-8"),
type=str,
)
ARG_VAR_ACTION_ON_EXISTING_KEY = Arg(
("-a", "--action-on-existing-key"),
Expand Down Expand Up @@ -912,7 +912,7 @@ def string_lower_type(val):
ARG_CONN_EXPORT = Arg(
("file",),
help="Output file path for exporting the connections",
type=argparse.FileType("w", encoding="UTF-8"),
type=str,
)
ARG_CONN_EXPORT_FORMAT = Arg(
("--format",),
Expand Down
4 changes: 2 additions & 2 deletions airflow-core/src/airflow/cli/commands/connection_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,13 @@ def connections_export(args):
if args.format or args.file_format:
provided_file_format = f".{(args.format or args.file_format).lower()}"

with args.file as f:
with (args.file if hasattr(args.file, "write") else open(args.file, "w", encoding="UTF-8")) as f:
if is_stdout(f):
filetype = provided_file_format or default_format
elif provided_file_format:
filetype = provided_file_format
else:
filetype = Path(args.file.name).suffix.lower()
filetype = Path(args.file).suffix.lower()
if filetype not in file_formats:
raise SystemExit(
f"Unsupported file format. The file must have the extension {', '.join(file_formats)}."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,6 @@ def variables_export(args):
else:
var_dict[var.key] = val

with args.file as varfile:
with (args.file if hasattr(args.file, "write") else open(args.file, "w", encoding="UTF-8")) as varfile:
json.dump(var_dict, varfile, sort_keys=True, indent=4)
print_export_output("Variables", var_dict, varfile)