迷你便捷提示库
项目描述
tinyprompt
一个用于创建优美、便捷提示的迷你库,主要用于操作脚本。
此README包含所有文档。
用法
pip install tinyprompt
使用tinyprompt.skippable将带有是/跳过/退出提示的脚本步骤包装起来。这对于简单的脚本操作非常有用,其中 是 是正常情况,跳过可以在失败后恢复或终止,退出用于在遇到问题时终止。
import tinyprompt
# note: tinyprompt.skippable passes arguments through verbatim, but it's
# not guaranteed to return a meaningful result
# `quit` does a sys.exit(1) and `skip` makes it return `None`
@tinyprompt.skippable('skippable script step')
def my_func():
"""
Do some things, this docstring will show up as a command description
when the script is run.
The "skippable script step" arg will be uppercased and used as the step
name.
"""
print('this skippable step')
@tinyprompt.skippable('other skippable script step', color=False)
def my_func2():
"""another func"""
print('hi')
def otherfunc():
# yes, it's on purpose
tinyprompt.color_print('red string', tinyprompt.RED)
tinyprompt.color_print('yellow string', tinyprompt.BLUE)
tinyprompt.color_print('green string', tinyprompt.GRAY)
tinyprompt.color_print('blue string', tinyprompt.GREEN)
tinyprompt.color_print('gray string', tinyprompt.YELLOW)
def main():
my_func() # skippable
my_func2() # skippable
otherfunc() # not skippable, but not reached on quit
if __name__ == '__main__':
main()
贡献
所有代码都必须通过 make test
所有代码都使用 black 和 isort 自动格式化
当你发现一个错误时,尽量编写一个测试
确保你的PR干净。通过重新基线化以避免合并冲突并压缩修复提交