epcpower / sunspec-demo

MIT License
1 stars 0 forks source link

Use Click #1

Closed altendky closed 5 years ago

altendky commented 5 years ago

@toddsnider-epc, I would like to think this makes for a better program... But given the purpose of this code I understand it might go a bit far. Though, the actual demo functions are still as straightforward as before. It's just the permutations of gridtied/dcdc and serial/tcp that make it a bit weird.

 @attr.s
 class Config:
     common = attr.ib(default=None)

  @click.group()
 @click.pass_context
 def cli(context):
     context.obj = Config()

  @cli.group()
 @click.pass_obj
 def gridtied(config):
     config.common = epcsunspecdemo.samples.gridtied

  @cli.group()
 @click.pass_obj
 def dcdc(config):
     config.common = epcsunspecdemo.samples.dcdc

and

for group in (gridtied, dcdc):
     group.add_command(serial, name='serial')
     group.add_command(tcp, name='tcp')