Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 9 additions & 1 deletion docs/commands/fs/rm.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,24 @@ Delete a workspace, item, or file.
**Usage:**

```
fab rm <path> [-f]
fab rm <path> [-f] [--purge]
```

**Parameters:**

- `<path>`: Path to delete.
- `-f, --force`: Force deletion without confirmation. Optional.
- `--purge`: Permanently delete the item. Cannot be recovered. When not specified, item is soft-deleted if the item type supports it. Optional.

**Example:**

```
# Soft delete
fab rm ws1.Workspace/nb1.Notebook

# Force delete without confirmation
fab rm ws1.Workspace/nb1.Notebook --force

# Purge delete (permanent removal)
fab rm ws1.Workspace/nb1.Notebook --purge --force
```
24 changes: 19 additions & 5 deletions src/fabric_cli/client/fab_api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,25 @@ def delete_resource(
operation: Optional[str] = "delete",
) -> bool:
if not bypass_confirmation:
if utils_ui.prompt_confirm():
if hasattr(args, 'purge') and args.purge:
confirm_message = "Your item will be deleted forever. Are you sure you want to proceed?"
else:
confirm_message = "Are you sure?"

if utils_ui.prompt_confirm(confirm_message):
if hasattr(args, 'purge') and args.purge and verbose:
utils_ui.print_warning("! Executing purge delete")
Comment thread
v-alexmoraru marked this conversation as resolved.
Outdated
return _do_delete_resource(args, operation=operation)
Comment thread
v-alexmoraru marked this conversation as resolved.
Outdated
else:
if verbose:
utils_ui.print_warning(f"Resource {operation} cancelled")
return False
else:
if verbose:
utils_ui.print_warning(f"Executing force {operation}...")
if hasattr(args, 'purge') and args.purge:
utils_ui.print_warning("! Executing force purge delete")
Comment thread
v-alexmoraru marked this conversation as resolved.
Outdated
else:
utils_ui.print_warning(f"Executing force {operation}...")
return _do_delete_resource(args, verbose=verbose, operation=operation)
Comment thread
v-alexmoraru marked this conversation as resolved.


Expand Down Expand Up @@ -125,7 +135,8 @@ def get_api_version(resource_uri: str) -> Any:
return rt["apiVersions"][0]

raise FabricCLIError(
ErrorMessages.Client.resource_type_not_found_in_provider(args.resource_type, args.provider_namespace),
ErrorMessages.Client.resource_type_not_found_in_provider(
args.resource_type, args.provider_namespace),
Comment thread
v-alexmoraru marked this conversation as resolved.
Comment thread
v-alexmoraru marked this conversation as resolved.
status_code=constant.ERROR_NOT_SUPPORTED,
)

Expand All @@ -136,7 +147,8 @@ def _do_delete_resource(
) -> bool:
if verbose:
if operation is not None:
utils_ui.print_grey(f"{_to_gerund_capitalized(operation)} '{args.name}'...")
utils_ui.print_grey(
f"{_to_gerund_capitalized(operation)} '{args.name}'...")
response = fabric_api.do_request(args)

return _validate_success_and_print_on_verbose(
Expand Down Expand Up @@ -187,6 +199,7 @@ def _do_unassign_resource(
args, "unassigned", response.status_code, verbose
)


def _to_gerund_capitalized(operation: str) -> str:
if operation.endswith("e") and not operation.endswith("ee"):
result = f"{operation[:-1]}ing"
Expand All @@ -200,7 +213,8 @@ def _validate_success_and_print_on_verbose(
) -> bool:
if status_code in [200, 201]:
if verbose:
utils_ui.print_output_format(args, message=f"'{args.name}' {action}")
utils_ui.print_output_format(
args, message=f"'{args.name}' {action}")
return True
if status_code == 202:
if verbose:
Expand Down
5 changes: 5 additions & 0 deletions src/fabric_cli/commands/fs/rm/fab_fs_rm_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ def exec(item: Item, args: Namespace, force_delete: bool) -> None:
args.name = item.name
args.item_type = item.type.value

if hasattr(args, 'purge') and args.purge:
args.request_params = {"hardDelete": "true"}
else:
args.request_params = {}
Comment thread
v-alexmoraru marked this conversation as resolved.
Outdated

if item_api.delete_item(args, force_delete):
# Remove from mem_store
utils_mem_store.delete_item_from_cache(item)
26 changes: 19 additions & 7 deletions src/fabric_cli/commands/fs/rm/fab_fs_rm_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@

def bulk(tenant: Tenant, args: Namespace, force_delete: bool) -> None:
workspaces: list[Workspace] = utils_mem_store.get_workspaces(tenant)
sorted_workspaces: list[Workspace] = sorted(workspaces, key=lambda ws: ws.name)
sorted_workspaces: list[Workspace] = sorted(
workspaces, key=lambda ws: ws.name)

names = [workspace.name for workspace in sorted_workspaces]
selected_workspaces = utils_ui.prompt_select_items("Select workspaces:", names)
selected_workspaces = utils_ui.prompt_select_items(
"Select workspaces:", names)
if selected_workspaces:
for workspace_str in selected_workspaces:
utils_ui.print_grey(workspace_str)
Expand Down Expand Up @@ -51,7 +53,8 @@ def bulk(tenant: Tenant, args: Namespace, force_delete: bool) -> None:
utils_mem_store.delete_workspace_from_cache(workspace)

utils_ui.print("")
utils_ui.print_output_format(args, message=f"{deleted_workspaces} workspaces deleted successfully")
utils_ui.print_output_format(
args, message=f"{deleted_workspaces} workspaces deleted successfully")


def single(workspace: Workspace, args: Namespace, force_delete: bool) -> None:
Expand All @@ -77,7 +80,8 @@ def single(workspace: Workspace, args: Namespace, force_delete: bool) -> None:
pass

if force_delete:
utils_ui.print_grey(f"This will delete {len(ws_items)} underlying items")
utils_ui.print_grey(
f"This will delete {len(ws_items)} underlying items")

if workspace_api.delete_workspace(args, force_delete):
# Remove from mem_store
Expand All @@ -94,7 +98,8 @@ def single(workspace: Workspace, args: Namespace, force_delete: bool) -> None:
sorted_items = item_utils.sort_ws_elems_by_config(supported_items)

names = [item.name for item in sorted_items]
selected_items = utils_ui.prompt_select_items("Select items:", names)
selected_items = utils_ui.prompt_select_items(
"Select items:", names)
if selected_items:
for item_str in selected_items:
utils_ui.print_grey(item_str)
Expand All @@ -113,18 +118,25 @@ def single(workspace: Workspace, args: Namespace, force_delete: bool) -> None:
args.name = item.name
args.item_type = str(item.item_type)

if hasattr(args, 'purge') and args.purge:
args.request_params = {"hardDelete": "true"}
else:
args.request_params = {}
Comment thread
v-alexmoraru marked this conversation as resolved.
Outdated

# Reset args for subsequent calls
args.uri = None
args.method = None

if item_api.delete_item(
args, bypass_confirmation=True, verbose=False
):
utils_ui.print_output_format(args, message=f"'{args.name}' deleted")
utils_ui.print_output_format(
args, message=f"'{args.name}' deleted")
deleted_items = deleted_items + 1

# Remove from mem_store
utils_mem_store.delete_item_from_cache(item)

utils_ui.print("")
utils_ui.print_output_format(args, message=f"{deleted_items} items deleted successfully")
utils_ui.print_output_format(
args, message=f"{deleted_items} items deleted successfully")
72 changes: 52 additions & 20 deletions src/fabric_cli/parsers/fab_fs_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def register_mkdir_parser(subparsers: _SubParsersAction) -> None:
fab_aliases=mkdir_aliases,
fab_learnmore=mkdir_learnmore,
)
mkdir_parser.add_argument("path", nargs="+", type=str, help="Directory path")
mkdir_parser.add_argument(
"path", nargs="+", type=str, help="Directory path")
mkdir_parser.add_argument(
"-P",
"--params",
Expand All @@ -93,7 +94,8 @@ def register_mkdir_parser(subparsers: _SubParsersAction) -> None:
)

mkdir_parser.usage = f"{utils_error_parser.get_usage_prog(mkdir_parser)}"
mkdir_parser.set_defaults(func=lazy_command(_fs_module_path, 'mkdir_command'))
mkdir_parser.set_defaults(func=lazy_command(
_fs_module_path, 'mkdir_command'))


# Command for 'cd'
Expand Down Expand Up @@ -124,6 +126,8 @@ def register_rm_parser(subparsers: _SubParsersAction) -> None:
"$ rm ws1.Workspace\n",
"# remove a table",
"$ rm lh1.Lakehouse/Tables/fabtbl",
"# permanently remove an item (purge)",
"$ rm nb1.Notebook --purge --force",
Comment thread
v-alexmoraru marked this conversation as resolved.
Outdated
]

rm_parser = subparsers.add_parser(
Expand All @@ -138,6 +142,12 @@ def register_rm_parser(subparsers: _SubParsersAction) -> None:
rm_parser.add_argument(
"-f", "--force", required=False, action="store_true", help="Force. Optional"
)
rm_parser.add_argument(
"--purge",
Comment thread
v-alexmoraru marked this conversation as resolved.
Outdated
required=False,
action="store_true",
help="Permanently delete the item. Cannot be recovered. Optional"
)
Comment thread
v-alexmoraru marked this conversation as resolved.
Comment thread
v-alexmoraru marked this conversation as resolved.

rm_parser.usage = f"{utils_error_parser.get_usage_prog(rm_parser)}"
rm_parser.set_defaults(func=lazy_command(_fs_module_path, 'rm_command'))
Expand All @@ -162,7 +172,8 @@ def register_mv_parser(subparsers: _SubParsersAction) -> None:
fab_aliases=mv_aliases,
fab_learnmore=["_"],
)
mv_parser.add_argument("from_path", nargs="+", type=str, help="Source path")
mv_parser.add_argument("from_path", nargs="+",
type=str, help="Source path")
Comment thread
v-alexmoraru marked this conversation as resolved.
Outdated
mv_parser.add_argument("to_path", nargs="+", type=str, help="Target path")
mv_parser.add_argument(
"-f",
Expand Down Expand Up @@ -203,7 +214,8 @@ def register_cp_parser(subparsers: _SubParsersAction) -> None:
fab_learnmore=["_"],
)

cp_parser.add_argument("from_path", nargs="+", type=str, help="Source path")
cp_parser.add_argument("from_path", nargs="+",
type=str, help="Source path")
Comment thread
v-alexmoraru marked this conversation as resolved.
Outdated
cp_parser.add_argument("to_path", nargs="+", type=str, help="Target path")
cp_parser.add_argument(
"-f",
Expand Down Expand Up @@ -246,10 +258,12 @@ def register_exists_parser(subparsers: _SubParsersAction) -> None:
fab_examples=exists_examples,
fab_learnmore=["_"],
)
exists_parser.add_argument("path", nargs="+", type=str, help="Directory path")
exists_parser.add_argument(
"path", nargs="+", type=str, help="Directory path")

exists_parser.usage = f"{utils_error_parser.get_usage_prog(exists_parser)}"
exists_parser.set_defaults(func=lazy_command(_fs_module_path, 'exists_command'))
exists_parser.set_defaults(func=lazy_command(
_fs_module_path, 'exists_command'))


# Command for 'pwd'
Expand Down Expand Up @@ -281,10 +295,12 @@ def register_open_parser(subparsers: _SubParsersAction) -> None:
fab_examples=open_examples,
fab_learnmore=["_"],
)
open_parser.add_argument("path", nargs="+", type=str, help="Directory path")
open_parser.add_argument(
"path", nargs="+", type=str, help="Directory path")

open_parser.usage = f"{utils_error_parser.get_usage_prog(open_parser)}"
open_parser.set_defaults(func=lazy_command(_fs_module_path, 'open_command'))
open_parser.set_defaults(func=lazy_command(
_fs_module_path, 'open_command'))


# Command for 'export'
Expand All @@ -302,7 +318,8 @@ def register_export_parser(subparsers: _SubParsersAction) -> None:
fab_examples=export_examples,
fab_learnmore=["_"],
)
export_parser.add_argument("path", nargs="+", type=str, help="Directory path")
export_parser.add_argument(
"path", nargs="+", type=str, help="Directory path")
export_parser.add_argument(
"-o",
"--output",
Expand Down Expand Up @@ -332,7 +349,8 @@ def register_export_parser(subparsers: _SubParsersAction) -> None:
)

export_parser.usage = f"{utils_error_parser.get_usage_prog(export_parser)}"
export_parser.set_defaults(func=lazy_command(_fs_module_path, 'export_command'))
export_parser.set_defaults(func=lazy_command(
_fs_module_path, 'export_command'))


# Command for 'get'
Expand Down Expand Up @@ -424,9 +442,12 @@ def register_import_parser(subparsers: _SubParsersAction) -> None:
)

import_parser.usage = f"{utils_error_parser.get_usage_prog(import_parser)}"
import_parser.set_defaults(func=lazy_command(_fs_module_path, 'import_command'))
import_parser.set_defaults(func=lazy_command(
_fs_module_path, 'import_command'))

# Command for 'deploy'


def register_deploy_parser(subparsers: _SubParsersAction) -> None:
deploy_examples = [
"# deploy fabric items to a workspace using a configuration file and target environment",
Expand Down Expand Up @@ -469,10 +490,13 @@ def register_deploy_parser(subparsers: _SubParsersAction) -> None:
"-f", "--force", required=False, action="store_true", help="Force. Optional"
)

deploy_parser.set_defaults(func=lazy_command(_fs_module_path, 'deploy_command'))
deploy_parser.set_defaults(func=lazy_command(
_fs_module_path, 'deploy_command'))
deploy_parser.usage = f"{utils_error_parser.get_usage_prog(deploy_parser)}"

# Command for 'set'


def register_set_parser(subparsers: _SubParsersAction) -> None:
set_examples = [
"# rename a workspace",
Expand Down Expand Up @@ -581,13 +605,15 @@ def register_start_parser(subparsers: _SubParsersAction) -> None:
fab_examples=start_examples,
fab_learnmore=["_"],
)
start_parser.add_argument("path", nargs="+", type=str, help="Directory path")
start_parser.add_argument(
"path", nargs="+", type=str, help="Directory path")
start_parser.add_argument(
"-f", "--force", required=False, action="store_true", help="Force. Optional"
)

start_parser.usage = f"{utils_error_parser.get_usage_prog(start_parser)}"
start_parser.set_defaults(func=lazy_command(_fs_module_path, 'start_command'))
start_parser.set_defaults(func=lazy_command(
_fs_module_path, 'start_command'))


# Command for 'stop'
Expand All @@ -605,13 +631,15 @@ def register_stop_parser(subparsers: _SubParsersAction) -> None:
fab_examples=stop_examples,
fab_learnmore=["_"],
)
stop_parser.add_argument("path", nargs="+", type=str, help="Directory path")
stop_parser.add_argument(
"path", nargs="+", type=str, help="Directory path")
stop_parser.add_argument(
"-f", "--force", required=False, action="store_true", help="Force. Optional"
)

stop_parser.usage = f"{utils_error_parser.get_usage_prog(stop_parser)}"
stop_parser.set_defaults(func=lazy_command(_fs_module_path, 'stop_command'))
stop_parser.set_defaults(func=lazy_command(
_fs_module_path, 'stop_command'))


# Command for 'assign'
Expand All @@ -629,7 +657,8 @@ def register_assign_parser(subparsers: _SubParsersAction) -> None:
fab_examples=assign_examples,
fab_learnmore=["_"],
)
assign_parser.add_argument("path", nargs="+", type=str, help="Directory path")
assign_parser.add_argument(
"path", nargs="+", type=str, help="Directory path")
assign_parser.add_argument(
"-W",
"--workspace",
Expand All @@ -642,7 +671,8 @@ def register_assign_parser(subparsers: _SubParsersAction) -> None:
)

assign_parser.usage = f"{utils_error_parser.get_usage_prog(assign_parser)}"
assign_parser.set_defaults(func=lazy_command(_fs_module_path, 'assign_command'))
assign_parser.set_defaults(func=lazy_command(
_fs_module_path, 'assign_command'))


# Command for 'unassign'
Expand All @@ -660,7 +690,8 @@ def register_unassign_parser(subparsers: _SubParsersAction) -> None:
fab_examples=unassign_examples,
fab_learnmore=["_"],
)
unassign_parser.add_argument("path", nargs="+", type=str, help="Directory path")
unassign_parser.add_argument(
"path", nargs="+", type=str, help="Directory path")
unassign_parser.add_argument(
"-W",
"--workspace",
Expand All @@ -673,7 +704,8 @@ def register_unassign_parser(subparsers: _SubParsersAction) -> None:
)

unassign_parser.usage = f"{utils_error_parser.get_usage_prog(unassign_parser)}"
unassign_parser.set_defaults(func=lazy_command(_fs_module_path, 'unassign_command'))
unassign_parser.set_defaults(func=lazy_command(
_fs_module_path, 'unassign_command'))


# Command for 'clear'
Expand Down
Loading
Loading