diff --git a/.changes/unreleased/added-20260219-122814.yaml b/.changes/unreleased/added-20260219-122814.yaml new file mode 100644 index 00000000..5cdf9961 --- /dev/null +++ b/.changes/unreleased/added-20260219-122814.yaml @@ -0,0 +1,6 @@ +kind: added +body: ' Introduces a deploy command skeleton, allowing users to deploy items to a Fabric workspace using Fabric CI/CD lib' +time: 2026-02-19T12:28:14.367269851Z +custom: + Author: aviatco + AuthorLink: https://github.com/aviatco diff --git a/src/fabric_cli/commands/fs/deploy/fab_fs_deploy_config_file.py b/src/fabric_cli/commands/fs/deploy/fab_fs_deploy_config_file.py new file mode 100644 index 00000000..1770ec4e --- /dev/null +++ b/src/fabric_cli/commands/fs/deploy/fab_fs_deploy_config_file.py @@ -0,0 +1,9 @@ +from argparse import Namespace + +from fabric_cli.utils import fab_ui + +def deploy_with_config_file(args: Namespace) -> None: + """Deploy using config file and environment parameters - delegates to CICD library.""" + # WILL BE REMOVED - SHOULD CALL DEPLOY_WITH_CONFIG + fab_ui.print_info( + "Deploying using config file and environment parameters..." + str(args)) diff --git a/src/fabric_cli/commands/fs/fab_fs.py b/src/fabric_cli/commands/fs/fab_fs.py index fb707302..943da54b 100644 --- a/src/fabric_cli/commands/fs/fab_fs.py +++ b/src/fabric_cli/commands/fs/fab_fs.py @@ -15,6 +15,7 @@ from fabric_cli.commands.fs import fab_fs_export as fs_export from fabric_cli.commands.fs import fab_fs_get as fs_get from fabric_cli.commands.fs import fab_fs_import as fs_import +from fabric_cli.commands.fs import fab_fs_deploy as fs_deploy from fabric_cli.commands.fs import fab_fs_ln as fs_ln from fabric_cli.commands.fs import fab_fs_ls as fs_ls from fabric_cli.commands.fs import fab_fs_mkdir as fs_mkdir @@ -144,6 +145,14 @@ def import_command(args: Namespace) -> None: fs_import.exec_command(args, context) +@handle_exceptions() +@set_command_context() +def deploy_command(args: Namespace) -> None: + context = handle_context.get_command_context(args.path if hasattr( + args, 'path') and args.path else [], raise_error=False) + fs_deploy.exec_command(args, context) + + @handle_exceptions() @set_command_context() def set_command(args: Namespace) -> None: diff --git a/src/fabric_cli/commands/fs/fab_fs_deploy.py b/src/fabric_cli/commands/fs/fab_fs_deploy.py new file mode 100644 index 00000000..aab38d68 --- /dev/null +++ b/src/fabric_cli/commands/fs/fab_fs_deploy.py @@ -0,0 +1,14 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +from argparse import Namespace + +from fabric_cli.commands.fs.deploy.fab_fs_deploy_config_file import deploy_with_config_file +from fabric_cli.core.hiearchy.fab_element import FabricElement +from fabric_cli.utils import fab_ui + + +def exec_command(args: Namespace, context: FabricElement) -> None: + """Deploy using config file and environment parameters - CICD flow.""" + if args.force or fab_ui.prompt_confirm(): + deploy_with_config_file(args) diff --git a/src/fabric_cli/core/fab_constant.py b/src/fabric_cli/core/fab_constant.py index f81f9eb9..fba411ca 100644 --- a/src/fabric_cli/core/fab_constant.py +++ b/src/fabric_cli/core/fab_constant.py @@ -183,6 +183,7 @@ COMMAND_FS_EXPORT_DESCRIPTION = "Export an item." COMMAND_FS_GET_DESCRIPTION = "Get workspace or item properties." COMMAND_FS_IMPORT_DESCRIPTION = "Import an item to create or update it." +COMMAND_FS_DEPLOY_DESCRIPTION = "Deploy items using configuration file and environment parameters." COMMAND_FS_SET_DESCRIPTION = "Set workspace or item properties." COMMAND_FS_CLEAR_DESCRIPTION = "Clear the terminal screen." COMMAND_FS_LN_DESCRIPTION = "Create a shortcut." diff --git a/src/fabric_cli/core/fab_parser_setup.py b/src/fabric_cli/core/fab_parser_setup.py index ae91d37a..c66c1747 100644 --- a/src/fabric_cli/core/fab_parser_setup.py +++ b/src/fabric_cli/core/fab_parser_setup.py @@ -201,6 +201,7 @@ def create_parser_and_subparsers(): fs_parser.register_open_parser(subparsers) # open fs_parser.register_export_parser(subparsers) # export fs_parser.register_import_parser(subparsers) # import + fs_parser.register_deploy_parser(subparsers) # deploy fs_parser.register_set_parser(subparsers) # set fs_parser.register_get_parser(subparsers) # get fs_parser.register_clear_parser(subparsers) # clear diff --git a/src/fabric_cli/parsers/fab_fs_parser.py b/src/fabric_cli/parsers/fab_fs_parser.py index 8d0273b0..4c185c76 100644 --- a/src/fabric_cli/parsers/fab_fs_parser.py +++ b/src/fabric_cli/parsers/fab_fs_parser.py @@ -424,6 +424,56 @@ def register_import_parser(subparsers: _SubParsersAction) -> None: import_parser.usage = f"{utils_error_parser.get_usage_prog(import_parser)}" import_parser.set_defaults(func=fs.import_command) +# Command for 'deploy' + + +def register_deploy_parser(subparsers: _SubParsersAction) -> None: + deploy_examples = [ + "# deploy using config file and environment", + "$ deploy --config-file config.yml --env dev\n", + "# deploy with config file, environment, and optional parameters", + "$ deploy --config-file config.yml --env prod -P '[{\"param1\":\"value1\"}]' -f", + ] + + deploy_parser = subparsers.add_parser( + "deploy", + help=fab_constant.COMMAND_FS_DEPLOY_DESCRIPTION, + fab_examples=deploy_examples, + fab_learnmore=["_"], + ) + + deploy_parser.add_argument( + "-dcf", + "--deploy_config_file", + metavar="PATH", + type=str, + required=True, + help="Path to local deployment config file.", + ) + + deploy_parser.add_argument( + "-tenv", + "--target_env", + metavar="ENV_NAME", + type=str, + required=True, + help="Environment name as defined in deployment config file.", + ) + + deploy_parser.add_argument( + "-P", + "--params", + metavar="JSON", + type=str, + help="parameters for deployment in JSON format (e.g., '[{\"p1\":\"v1\",\"p2\":\"v2\"}]'). Optional", + ) + + deploy_parser.add_argument( + "-f", "--force", required=False, action="store_true", help="Force. Optional" + ) + + deploy_parser.set_defaults(func=fs.deploy_command) + deploy_parser.usage = f"{utils_error_parser.get_usage_prog(deploy_parser)}" # Command for 'set' def register_set_parser(subparsers: _SubParsersAction) -> None: