Extensions#

aprompt.ext.argparse#

The argparse extension can be used to prompt the user arguments that have not been set in the command-line. This has a similar effect as the prompt parameter in click.Option.

Example:

from argparse import ArgumentParser
from aprompt.ext.argparse import Namespace, PromptIfAbsent
from aprompt.prompts import number

parser = ArgumentParser(description="Example of argparse extension.")

parser.add_argument(
    "--age",
    default=PromptIfAbsent(
        "Please enter your age.",
        number(minimum=0, maximum=150)
    )
)

args = parser.parse_args(namespace=Namespace()).prompt()
print(args)
class aprompt.ext.argparse.PromptIfAbsent(*args: Any, **kwargs: Any)#

A class to prompt for a value if it has not been provided in the command-line. This class is a subclass of functools.partial() with the difference that the function (aprompt.prompt()) does not need to be provided.

Parameters:
  • args (Any) –

  • kwargs (Any) –

Return type:

PromptIfAbsent

args#

tuple of arguments to future partial calls

func#

function object to use in future partial calls

keywords#

dictionary of keyword arguments to future partial calls

class aprompt.ext.argparse.Namespace(**kwargs)#

A subclass of argparse.Namespace that prompts for arguments with a default value of an instance of PromptIfAbsent if they have not been provided in the command-line.

To invoke the prompts, call prompt() on the object returned by argparse.ArgumentParser.parse_args().

prompt() Namespace#
Return type:

Namespace