Package: paperplane
PaperplanePaperplane allows you to build interactive CLIs straight from a configuration file (or a Python dict) without having to write your own code for I/O.Paperplane orchestrates I/O operations by delegating work to different backends. Supported backends:clickMore backends coming soon!Currently supports:Reading an int, string, boolean, one-of-many (choice) inputs.Theclickintegration backend automatically callsclick.prompt()Display a styled output (bold, foreground color, background color, etc)Theclickintegration backend automatically callsclick.secho()The I/O order and parameters (prompt, data type, available choices, default, etc) can be provided in the following formats:YAMLJSONPython dictionarySeeGetting Startedfor more info!InstallationAssuming you have Python (>= 3.6), run:pip install paperplaneDocumentationPreliminary documentation is available atpaperplane.readthedocs.io.Detailed documentation coming soon!FeaturesCollect interactive inputs and display styled output text based on simple configurations.Dynamic defaults and prompts (the question/message shown to the user) via macros.Use the value from one input to calculate the default value for subsequent inputs.For example, collect ausernameinput and usehttps://github.com/<io:username>to auto-compute the default value for the subsequentgithub_urlinput.Use the<cwd>macro to get the current working directoryUse the<env:NAME>macro to fetch the value for an environment variable.Using the macro<env:NAME1,NAME2>will fetch the first available environment variable. Useful if, for example, the environment variable names are different on Windows and Linux. Or simply, if you're unsure about which of them will be set.See the exampleconfig.ymlbelow for more awesome features!Getting StartedPaperplane has a convenientpaperplane collect CONFIG_FILEcommand that lets you run and test your config file. It triggers I/O operations based on the provided parameters and dumps the collected information to your terminal (Python dict format by default or alternatively, JSON) for debugging/verifying.For usage inside a Python script, seehere.To get started, create a new YAML configuration file as follows:config.ymlbackend:clickio:-name:type:strprompt:Your name-username:type:strprompt:Your GitHub usernamedefault:<env:USER,USERNAME>-prompt1:type:echoprompt:|-Hello, <io:name> (<io:username>)!Your GitHub URL is https://github.com/<io:username>Your current working directory is '<cwd>'fg:green-project_dir:type:strprompt:Enter project directorydefault:<cwd>-prompt2:type:echoprompt:Enter a name for your new project. It will be created at <io:project_dir>/<project name>fg:blue-project_name:type:strprompt:Project name-feature_x:type:choiceprompt:Do you want to enable feature X?choices:-'Yes'-'No'default:'Yes'To run and trigger I/O operations:paperplane collect /path/to/config.ymlResult:If you want a JSON output (instead of the default Python dict dump):paperplane collect /path/to/config.yml --json-outIf you have an input JSON config file instead of YAML:paperplane collect /path/to/config.json --format=jsonIf you want DEBUG level logs:paperplane --debug collect /path/to/config.ymlTo see all available options:paparplane --help
paparplane collect --helpUsage within a Python scriptfrompaperplaneimportparse_and_executeconfig={'backend':'click','io':[{'name':{'type':'str','prompt':'Your name'}},{'username':{'type':'str','prompt':'Your GitHub username','default':'<env:USER,USERNAME>'}},{'prompt1':{'type':'echo','prompt':"Hello, <io:name> (<io:username>)!\nYour GitHub URL is https://github.com/<io:username>\nYour current working directory is '<cwd>'",'fg':'green'}},{'project_dir':{'type':'str','prompt':'Enter project directory','default':'<cwd>'}},{'prompt2':{'type':'echo','prompt':'Enter a name for your new project. It will be created at <io:project_dir>/<project_name>','fg':'blue',}},{'project_name':{'type':'str','prompt':'Project name'}},{'feature_x':{'type':'choice','prompt':'Do you want to enable feature X?','choices':['Yes','No'],'default':'Yes',}}]}values=parse_and_execute(config)# Do your own stuff with the collected valuesprint(values)Coming soonTestsInput validatorsLazy Jinja2 template rendering in YAML config