Skip to content

Commit

Permalink
implement config reset command
Browse files Browse the repository at this point in the history
  • Loading branch information
popenta committed Jan 18, 2024
1 parent 4c08e9a commit bbf9c13
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
21 changes: 19 additions & 2 deletions CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions CLI.md.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 23 additions & 0 deletions multiversx_sdk_cli/cli_config.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)

0 comments on commit bbf9c13

Please sign in to comment.