2021-10-09 18:50:43 +02:00
|
|
|
# standard imports
|
|
|
|
import os
|
|
|
|
import logging
|
|
|
|
import sys
|
|
|
|
import importlib
|
|
|
|
|
|
|
|
# external imports
|
2021-10-11 17:39:01 +02:00
|
|
|
import chainlib.cli
|
2022-03-01 08:01:56 +01:00
|
|
|
|
|
|
|
# local imports
|
2021-10-09 18:50:43 +02:00
|
|
|
import cic.cmd.init as cmd_init
|
2021-10-09 20:37:54 +02:00
|
|
|
import cic.cmd.show as cmd_show
|
2021-10-18 10:47:48 +02:00
|
|
|
import cic.cmd.ext as cmd_ext
|
2021-10-09 21:04:11 +02:00
|
|
|
import cic.cmd.export as cmd_export
|
2022-03-01 08:01:56 +01:00
|
|
|
import cic.cmd.wizard as cmd_wizard
|
2022-03-16 09:04:38 +01:00
|
|
|
from cic.config import ensure_base_configs
|
2021-10-09 18:50:43 +02:00
|
|
|
|
|
|
|
logging.basicConfig(level=logging.WARNING)
|
|
|
|
logg = logging.getLogger()
|
|
|
|
|
|
|
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
data_dir = os.path.join(script_dir, '..', 'data')
|
2021-10-11 17:39:01 +02:00
|
|
|
base_config_dir = os.path.join(data_dir, 'config')
|
2021-10-09 18:50:43 +02:00
|
|
|
schema_dir = os.path.join(script_dir, '..', 'schema')
|
2022-03-16 09:04:38 +01:00
|
|
|
user_config_dir = os.path.join(os.path.expanduser("~"), ".config", "cic", "cli", "config")
|
2021-10-09 18:50:43 +02:00
|
|
|
|
2021-10-11 21:18:51 +02:00
|
|
|
arg_flags = chainlib.cli.argflag_std_read | chainlib.cli.Flag.SEQ
|
2022-03-01 08:01:56 +01:00
|
|
|
argparser = chainlib.cli.ArgumentParser(
|
|
|
|
env=os.environ,
|
|
|
|
arg_flags=arg_flags,
|
|
|
|
description='CIC cli tool for generating and publishing tokens'
|
|
|
|
)
|
2021-10-09 18:50:43 +02:00
|
|
|
|
|
|
|
sub = argparser.add_subparsers()
|
|
|
|
sub.dest = 'command'
|
2022-03-01 08:01:56 +01:00
|
|
|
|
2021-10-09 18:50:43 +02:00
|
|
|
sub_init = sub.add_parser('init', help='initialize new cic data directory')
|
|
|
|
cmd_init.process_args(sub_init)
|
2022-03-01 08:01:56 +01:00
|
|
|
|
2021-10-09 20:37:54 +02:00
|
|
|
sub_show = sub.add_parser('show', help='display summary of current state of cic data directory')
|
|
|
|
cmd_show.process_args(sub_show)
|
2022-03-01 08:01:56 +01:00
|
|
|
|
2021-10-09 21:04:11 +02:00
|
|
|
sub_export = sub.add_parser('export', help='export cic data directory state to a specified target')
|
|
|
|
cmd_export.process_args(sub_export)
|
2022-03-01 08:01:56 +01:00
|
|
|
|
2021-10-18 10:47:48 +02:00
|
|
|
sub_ext = sub.add_parser('ext', help='extension helpers')
|
|
|
|
cmd_ext.process_args(sub_ext)
|
|
|
|
|
2022-03-01 08:01:56 +01:00
|
|
|
sub_wizard = sub.add_parser('wizard', help='An interactive wizard for creating and publishing contracts')
|
|
|
|
cmd_wizard.process_args(sub_wizard)
|
2021-10-09 18:50:43 +02:00
|
|
|
|
|
|
|
args = argparser.parse_args(sys.argv[1:])
|
|
|
|
|
2022-03-01 08:01:56 +01:00
|
|
|
if args.command is None:
|
2021-10-09 18:50:43 +02:00
|
|
|
logg.critical('Subcommand missing')
|
2021-12-05 08:12:36 +01:00
|
|
|
sys.stderr.write("\033[;91m" + 'subcommand missing' + "\033[;39m\n")
|
2022-03-01 08:01:56 +01:00
|
|
|
argparser.print_help(sys.stderr)
|
2021-10-09 18:50:43 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
2022-03-01 08:01:56 +01:00
|
|
|
modname = f'cic.cmd.{args.command}'
|
|
|
|
logg.debug(f'using module {modname}')
|
2021-10-09 18:50:43 +02:00
|
|
|
cmd_mod = importlib.import_module(modname)
|
|
|
|
|
2021-10-11 21:18:51 +02:00
|
|
|
extra_args = {
|
|
|
|
'p': 'RPC_PROVIDER',
|
2022-03-01 08:01:56 +01:00
|
|
|
}
|
2022-03-16 09:04:38 +01:00
|
|
|
ensure_base_configs(user_config_dir)
|
2022-03-01 08:01:56 +01:00
|
|
|
|
2021-10-11 21:18:51 +02:00
|
|
|
config = chainlib.cli.Config.from_args(args, arg_flags=arg_flags, base_config_dir=base_config_dir, extra_args=extra_args)
|
2021-10-09 18:50:43 +02:00
|
|
|
|
|
|
|
def main():
|
2021-12-05 08:12:36 +01:00
|
|
|
try:
|
|
|
|
cmd_mod.execute(config, args)
|
|
|
|
except Exception as e:
|
2022-03-01 08:01:56 +01:00
|
|
|
logg.exception(e)
|
2021-12-05 08:12:36 +01:00
|
|
|
sys.stderr.write("\033[;91m" + str(e) + "\033[;39m\n")
|
|
|
|
sys.exit(1)
|
2021-10-09 18:50:43 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|