recent#

As a CLI app, it prompt to select from multiple choice. We want to remember the recent choice and use it as the default choice next time.

class ssh2awsec2.recent.ListChoices(key: str, expire: int = 86400, max_item: int = 20)[source]#

A utility class that prompt to select from multiple choice. It remembers the recent choice and use it as the default choice next time.

Parameters:

key – the unique Key for this choice.

save_selected_choice(id: str, value: str)[source]#

Save the selected choice to cache.

Parameters:
  • id – id of selected choice

  • value – value of selected choice

read_recent_choices() Deque[Tuple[str, str]][source]#

Get recently selected cache from cache.

clear_cache()[source]#

Delete the cached recent choices.

ask(message: str, choices: Dict[str, str], merge_selected: bool = False) Tuple[str, str][source]#

Prompt to select from multiple choice, and return the selected choice id and value. It remembers the recent choice and use it as the default choice next time.

Parameters:
  • message – the message of the prompt

  • choices – the id / value pair of all choices

  • merge_selected – if True, then the recently selected choices will be merged into the choices. If False, then only the given choices will prompt.

Returns:

the selected choice id and value