Skip to content

Simple Dynamic Autocomplete #863

@luzik

Description

@luzik

example/tab_autocomp_dynamic.py disapear from git for some reason.

Could you please add simple example of dynamic autocomplete ?
I just need to filter choice of second argument based on the first one


class STGP_Cmd(cmd2.Cmd):
  def __init__(self, *args, **kwargs):
    self.a = {'a': ['ab', 'ac', 'ad'], 'b': ['bb', 'bc', 'bd']}

  def get_groups(self):
    return self.a.keys()

  def get_params(self, group):
    return self.a[group]

  get_param_parser = argparse.ArgumentParser()
  get_param_parser.add_argument('group', choices_method=get_groups)
  get_param_parser.add_argument('param', choices_method=get_params)

  @cmd2.with_argparser(get_param_parser)
    def do_get_param(self, args):
      self.poutput(self.get_param(args.param, args.group))

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions