opts_main.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/env python3
  2. import os
  3. from mmgen.cfg import Config
  4. from mmgen.util import msg
  5. opts_data = {
  6. 'sets': [('print_checksum', True, 'quiet', True)],
  7. 'text': {
  8. 'desc': 'Opts test',
  9. 'usage':'[args] [opts]',
  10. 'options': """
  11. -h, --help Print this help message
  12. --, --longhelp Print help message for long (global) options
  13. -i, --in-fmt= f Input is from wallet format 'f'
  14. -d, --outdir= d Use outdir 'd'
  15. -C, --print-checksum Print a checksum
  16. -E, --fee-estimate-mode=M Specify the network fee estimate mode.
  17. -F, --no-foobleize Do not foobleize the output, even on user request
  18. -H, --hidden-incog-input-params=f,o Read hidden incognito data from file
  19. 'f' at offset 'o' (comma-separated)
  20. -k, --keep-label Reuse label of input wallet for output wallet
  21. -l, --seed-len= l Specify wallet seed length of 'l' bits.
  22. -L, --label= l Specify a label 'l' for output wallet
  23. -m, --minconf= n Minimum number of confirmations required to spend
  24. outputs (default: 1)
  25. -o, --show-opts= L List of cfg opts to display
  26. -p, --hash-preset= p Use the scrypt hash parameters defined by preset 'p'
  27. -P, --passwd-file= f Get wallet passphrase from file 'f'
  28. -q, --quiet Be quieter
  29. -t, --min-temp= t Minimum temperature (in degrees Celsius)
  30. -T, --max-temp= t Maximum temperature (in degrees Celsius)
  31. -x, --point= P Point in Euclidean space
  32. -X, --cached-balances Use cached balances (Ethereum only)
  33. -v, --verbose Be more verbose
  34. sample help_note: {kgs}
  35. sample help_note: {coin_id}
  36. """,
  37. 'notes': """
  38. NOTES FOR THIS COMMAND
  39. sample note: {nn}
  40. """
  41. },
  42. 'code': {
  43. 'options': lambda cfg, help_notes, s: s.format(
  44. kgs = help_notes('keygen_backends'),
  45. coin_id = help_notes('coin_id'),
  46. ),
  47. 'notes': lambda s: s.format(nn='a note'),
  48. }
  49. }
  50. cfg = Config(opts_data=opts_data, need_proto=os.getenv('TEST_MISC_OPTS_NEEDS_PROTO'))
  51. if cfg.show_opts:
  52. opts = cfg.show_opts.split(',')
  53. col1_w = max(len(s) for s in opts) + 5
  54. for opt in opts:
  55. msg('{:{w}} {}'.format(f'cfg.{opt}:', getattr(cfg, opt), w=col1_w))
  56. if cfg._proto:
  57. coin, *rem = opt.split('_')
  58. network = rem[0] if rem[0] in cfg._proto.network_names else None
  59. opt_name = '_'.join(rem[bool(network):])
  60. msg('{:{w}} {}'.format(f'proto.{opt_name}:', getattr(cfg._proto, opt_name), w=col1_w))
  61. msg('')
  62. for n, arg in enumerate(cfg._args, 1):
  63. msg(f'arg{n}: {arg}')