Skip to content

Commit

Permalink
add import subcommand to import account backups
Browse files Browse the repository at this point in the history
  • Loading branch information
adbenitez committed May 20, 2024
1 parent be1620f commit e3c7457
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions deltabot_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sys
import time
from argparse import ArgumentParser, Namespace
from pathlib import Path
from threading import Thread
from typing import Callable, Set, Union

Expand Down Expand Up @@ -131,6 +132,9 @@ def init_parser(self) -> None:
config_parser.add_argument("option", help="option name", nargs="?")
config_parser.add_argument("value", help="option value to set", nargs="?")

import_parser = self.add_subcommand(_import_cmd, name="import")
import_parser.add_argument("path", help="path to the account backup", type=Path)

self.add_subcommand(_serve_cmd, name="serve")
self.add_subcommand(_qr_cmd, name="qr")
self.add_subcommand(_list_cmd, name="list")
Expand Down Expand Up @@ -365,3 +369,20 @@ def _remove_cmd(cli: BotCli, bot: Bot, args: Namespace) -> None:
addr = cli.get_address(bot.rpc, accid)
bot.rpc.remove_account(accid)
print(f"Account #{accid} ({addr}) removed successfully.")


def _import_cmd(_cli: BotCli, bot: Bot, args: Namespace) -> None:
"""import account backup"""
if not args.path.exists():
bot.logger.error(f"path doesn't exist: {str(args.path)!r}")
sys.exit(1)
accid = bot.rpc.add_account()
try:
bot.rpc.import_backup(accid, str(args.path), None)
except JsonRpcError as ex:
bot.rpc.remove_account(accid)
bot.logger.exception(ex)
sys.exit(1)
else:
addr = bot.rpc.get_config(accid, "configured_addr")
print(f"Account #{accid} ({addr}) imported successfully.")

0 comments on commit e3c7457

Please sign in to comment.