Interactive CLI

Interactive user inputs

cli2.interactive.choice(question, choices=None, default=None)[source]

Ask user to make a choice.

accepted = cli2.choice('Accept terms?') == 'y'
Parameters:
  • question – String question to ask

  • choices – List of acceptable choices, y/n by default

  • default – Default value for when the user does not add a value.

cli2.interactive.editor(content=None)[source]

Open $EDITOR with content, return the result.

Like git rebase -i does!

  • If a file path is given, edit in place.

  • Otherwise, write to a temporary file.

  • Anyway: return the written contents.

Parameters:

content – Initial content if any, or a file path

Returns:

The edited content after $EDITOR exit