main_tool.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2020 The MMGen Project <mmgen@tuta.io>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. """
  19. mmgen-tool: Perform various MMGen- and cryptocoin-related operations.
  20. Part of the MMGen suite
  21. """
  22. from .common import *
  23. def make_cmd_help():
  24. import mmgen.tool
  25. def make_help():
  26. for bc in mmgen.tool.MMGenToolCmds.classes.values():
  27. cls_doc = bc.__doc__.strip().split('\n')
  28. for l in cls_doc:
  29. if l is cls_doc[0]:
  30. l += ':'
  31. l = l.replace('\t','',1)
  32. if l:
  33. l = l.replace('\t',' ')
  34. yield l[0].upper() + l[1:]
  35. else:
  36. yield ''
  37. yield ''
  38. max_w = max(map(len,bc.user_commands))
  39. fs = ' {{:{}}} - {{}}'.format(max_w)
  40. for name,code in sorted(bc.user_commands.items()):
  41. if code.__doc__:
  42. yield fs.format(name,
  43. pretty_format(
  44. code.__doc__.strip().replace('\n\t\t',' '),
  45. width=79-(max_w+7),
  46. pfx=' '*(max_w+5)).lstrip()
  47. )
  48. yield ''
  49. return '\n'.join(make_help())
  50. opts_data = {
  51. 'text': {
  52. 'desc': 'Perform various {pnm}- and cryptocoin-related operations'.format(pnm=g.proj_name),
  53. 'usage': '[opts] <command> <command args>',
  54. 'options': """
  55. -d, --outdir= d Specify an alternate directory 'd' for output
  56. -h, --help Print this help message
  57. --, --longhelp Print help message for long options (common options)
  58. -k, --use-internal-keccak-module Force use of the internal keccak module
  59. -p, --hash-preset= p Use the scrypt hash parameters defined by preset 'p'
  60. for password hashing (default: '{g.hash_preset}')
  61. -P, --passwd-file= f Get passphrase from file 'f'.
  62. -q, --quiet Produce quieter output
  63. -r, --usr-randchars=n Get 'n' characters of additional randomness from
  64. user (min={g.min_urandchars}, max={g.max_urandchars})
  65. -t, --type=t Specify address type (valid options: 'legacy',
  66. 'compressed', 'segwit', 'bech32', 'zcash_z')
  67. -v, --verbose Produce more verbose output
  68. -X, --cached-balances Use cached balances (Ethereum only)
  69. """,
  70. 'notes': """
  71. COMMANDS
  72. {ch}
  73. Type '{pn} help <command>' for help on a particular command
  74. """
  75. },
  76. 'code': {
  77. 'options': lambda s: s.format(g=g),
  78. 'notes': lambda s: s.format(
  79. ch=make_cmd_help(),
  80. pn=g.prog_name)
  81. }
  82. }
  83. cmd_args = opts.init(opts_data,add_opts=['hidden_incog_input_params','in_fmt','use_old_ed25519'])
  84. g.use_cached_balances = opt.cached_balances
  85. if len(cmd_args) < 1:
  86. opts.usage()
  87. cmd = cmd_args.pop(0)
  88. import mmgen.tool as tool
  89. if cmd in ('help','usage') and cmd_args:
  90. cmd_args[0] = 'command_name=' + cmd_args[0]
  91. if cmd not in tool.MMGenToolCmds:
  92. die(1,"'{}': no such command".format(cmd))
  93. args,kwargs = tool._process_args(cmd,cmd_args)
  94. ret = tool.MMGenToolCmds.call(cmd,*args,**kwargs)
  95. tool._process_result(ret,pager='pager' in kwargs and kwargs['pager'],print_result=True)