diff --git a/CLI.md b/CLI.md index c7aa1e31..6f18244f 100644 --- a/CLI.md +++ b/CLI.md @@ -16,7 +16,10 @@ mxpy is part of the multiversx-sdk and consists of Command Line Tools and Python for interacting with the Blockchain (in general) and with Smart Contracts (in particular). mxpy targets a broad audience of users and developers. -https://docs.multiversx.com/sdk-and-tools/mxpy. + +See: + - https://docs.multiversx.com/sdk-and-tools/sdk-py + - https://docs.multiversx.com/sdk-and-tools/sdk-py/mxpy-cli COMMAND GROUPS: @@ -1293,7 +1296,7 @@ usage: mxpy config COMMAND [-h] ... Configure multiversx-sdk (default values etc.) COMMANDS: - {dump,get,set,delete,new,switch,list} + {dump,get,set,delete,new,switch,list,reset} OPTIONS: -h, --help show this help message and exit @@ -1308,6 +1311,7 @@ delete Deletes a configuration value. new Creates a new configuration. switch Switch to a different config list List available configs +reset Deletes the config file. Default config will be used. ``` ### Configuration.Dump @@ -1399,6 +1403,19 @@ usage: mxpy config list [-h] ... List available configs +options: + -h, --help show this help message and exit + +``` +### Configuration.Reset + + +``` +$ mxpy config reset --help +usage: mxpy config reset [-h] ... + +Deletes the config file. Default config will be used. + options: -h, --help show this help message and exit diff --git a/CLI.md.sh b/CLI.md.sh index db02f98f..c1b3ac8d 100755 --- a/CLI.md.sh +++ b/CLI.md.sh @@ -93,6 +93,7 @@ generate() { command "Configuration.New" "config new" command "Configuration.Switch" "config switch" command "Configuration.List" "config list" + command "Configuration.Reset" "config reset" group "Data" "data" command "Data.Dump" "data parse" diff --git a/multiversx_sdk_cli/cli_config.py b/multiversx_sdk_cli/cli_config.py index 5169ff20..b32496df 100644 --- a/multiversx_sdk_cli/cli_config.py +++ b/multiversx_sdk_cli/cli_config.py @@ -1,5 +1,7 @@ import logging +import os import sys +from pathlib import Path from typing import Any from multiversx_sdk_cli import cli_shared, config, utils @@ -40,6 +42,9 @@ def setup_parser(subparsers: Any) -> Any: sub = cli_shared.add_command_subparser(subparsers, "config", "list", "List available configs") sub.set_defaults(func=list_configs) + sub = cli_shared.add_command_subparser(subparsers, "config", "reset", "Deletes the config file. Default config will be used.") + sub.set_defaults(func=delete_config) + parser.epilog = cli_shared.build_group_epilog(subparsers) return subparsers @@ -93,3 +98,21 @@ def list_configs(args: Any): if config_name == data.get("active", "default"): config_name += "*" print(config_name) + + +def delete_config(args: Any): + config_file = config.resolve_config_path() + if not config_file.is_file(): + logger.info(f"Config file not found. Aborting...") + return + + confirm_continuation(config_file) + os.remove(config_file) + logger.info("Successfully deleted the config file") + + +def confirm_continuation(file: Path): + answer = input(f"The file `{str(file)}` will be deleted. Do you want to continue? (y/n)") + if answer.lower() not in ["y", "yes"]: + print("Confirmation not given. Stopping...") + exit(1)