Python 命令行工具库:Fire

发布时间 2023-09-05 09:29:47作者: michaelchengjl

Python 命令行工具库:Fire

Python Fire 是 Google 开源的一个可从任何 Python 代码自动生成命令行接口(CLI)的库。

Python Fire 是一种在 Python 中创建 CLI 的简单方法。
Python Fire 是开发和调试 Python 代码的有用工具。
Python Fire 帮助探索现有代码或将其他人的代码转换为CLI。
Python Fire 使 Bash 和 Python 之间的转换更为容易。
Python Fire 通过使用你需要导入和创建的模块和变量来设置 REPL,使得使用 Python REPL 更容易。

之前用过的一个生成命令行参数的模块:argparse, fire 模块的功能比 argparse 强大得多,用起来也更为顺手

Setup Command Notes
install pip install fire
Creating a CLI Command Notes
import import fire
Call fire.Fire() Turns the current module into a Fire CLI.
Call fire.Fire(component) Turns component into a Fire CLI.
Using a CLI Command Notes
Help command --help or command -- --help
REPL command -- --interactive Enters interactive mode.
Separator command -- --separator=X Sets the separator to X. The default separator is -.
Completion command -- --completion [shell] Generates a completion script for the CLI.
Trace command -- --trace Gets a Fire trace for the command.
Verbose command -- --verbose

Note that these flags are separated from the Fire command by an isolated --.

https://google.github.io/python-fire/guide/

https://blog.csdn.net/qq_17550379/article/details/79943740

https://github.com/google/python-fire