|
1 | 1 | ## Python Fire Quick Reference |
2 | 2 |
|
3 | 3 | | Setup | Command | Notes |
4 | | -| :------ | :------------------ | :--------- |
5 | | -| install | `pip install fire` | |
| 4 | +| ------- | ------------------- | ---------- |
| 5 | +| install | `pip install fire` | Installs fire from pypi |
6 | 6 |
|
7 | 7 | | Creating a CLI | Command | Notes |
8 | | -| :--------------| :--------------------- | :--------- |
| 8 | +| ---------------| ---------------------- | ---------- |
9 | 9 | | import | `import fire` | |
10 | 10 | | Call | `fire.Fire()` | Turns the current module into a Fire CLI. |
11 | 11 | | Call | `fire.Fire(component)` | Turns `component` into a Fire CLI. |
12 | 12 |
|
13 | | -| Using a CLI | Command | Notes | |
14 | | -| :----------------------------------------- | :------------- | :------------- | |
15 | | -| [Help](using-cli.md#help-flag) | `command | Show the help | |
16 | | -: : --help` : screen. : |
17 | | -| [REPL](using-cli.md#interactive-flag) | `command -- | Enters | |
18 | | -: : --interactive` : interactive : |
19 | | -: : : mode. : |
20 | | -| [Separator](using-cli.md#separator-flag) | `command -- | This sets the | |
21 | | -: : --separator=X` : separator to : |
22 | | -: : : `X`. The : |
23 | | -: : : default : |
24 | | -: : : separator is : |
25 | | -: : : `-`. : |
26 | | -| [Completion](using-cli.md#completion-flag) | `command -- | Generate a | |
27 | | -: : --completion : completion : |
28 | | -: : [shell]` : script for the : |
29 | | -: : : CLI. : |
30 | | -| [Trace](using-cli.md#trace-flag) | `command -- | Gets a Fire | |
31 | | -: : --trace` : trace for the : |
32 | | -: : : command. : |
33 | | -| [Verbose](using-cli.md#verbose-flag) | `command -- | | |
34 | | -: : --verbose` : : |
| 13 | +| Using a CLI | Command | Notes | |
| 14 | +| ------------------------------------------ | ----------------- | -------------- | |
| 15 | +| [Help](using-cli.md#help-flag) | `command --help` | Show the help screen. | |
| 16 | +| [REPL](using-cli.md#interactive-flag) | `command -- --interactive` | Enters interactive mode. | |
| 17 | +| [Separator](using-cli.md#separator-flag) | `command -- --separator=X` | This sets the separator to `X`. The default separator is `-`. | |
| 18 | +| [Completion](using-cli.md#completion-flag) | `command -- --completion [shell]` | Generate a completion script for the CLI. | |
| 19 | +| [Trace](using-cli.md#trace-flag) | `command -- --trace` | Gets a Fire trace for the command. | |
| 20 | +| [Verbose](using-cli.md#verbose-flag) | `command -- --verbose` | | |
35 | 21 |
|
36 | 22 | _Note that flags are separated from the Fire command by an isolated `--` arg. |
37 | 23 | Help is an exception; the isolated `--` is optional for getting help._ |
38 | 24 |
|
39 | 25 | ## Arguments for Calling fire.Fire() |
40 | 26 |
|
41 | 27 | | Argument | Usage | Notes | |
42 | | -| :-------- | :------------------------ | :----------------------------------- | |
43 | | -| component | `fire.Fire(component)` | If omitted, defaults to a dict of | |
44 | | -: : : all locals and globals. : |
45 | | -| command | `fire.Fire(command='hello | Either a string or a list of | |
46 | | -: : --name=5')` : arguments. If a string is provided, : |
47 | | -: : : it is split to determine the : |
48 | | -: : : arguments. If a list or tuple is : |
49 | | -: : : provided, they are the arguments. If : |
50 | | -: : : `command` is omitted, then : |
51 | | -: : : `sys.argv[1\:]` (the arguments from : |
52 | | -: : : the command line) are used by : |
53 | | -: : : default. : |
54 | | -| name | `fire.Fire(name='tool')` | The name of the CLI, ideally the | |
55 | | -: : : name users will enter to run the : |
56 | | -: : : CLI. This name will be used in the : |
57 | | -: : : CLI's help screens. If the argument : |
58 | | -: : : is omitted, it will be inferred : |
59 | | -: : : automatically. : |
| 28 | +| --------- | ------------------------- | ------------------------------------ | |
| 29 | +| component | `fire.Fire(component)` | If omitted, defaults to a dict of all locals and globals. | |
| 30 | +| command | `fire.Fire(command='hello --name=5')` | Either a string or a list of arguments. If a string is provided, it is split to determine the arguments. If a list or tuple is provided, they are the arguments. If `command` is omitted, then `sys.argv[1:]` (the arguments from the command line) are used by default. | |
| 31 | +| name | `fire.Fire(name='tool')` | The name of the CLI, ideally the name users will enter to run the CLI. This name will be used in the CLI's help screens. If the argument is omitted, it will be inferred automatically.| |
| 32 | +| serialize | `fire.Fire(serialize=custom_serializer)` | If omitted, simple types are serialized via their builtin str method, and any objects that define a custom `__str__` method are serialized with that. If specified, all objects are serialized to text via the provided method. | |
60 | 33 |
|
61 | 34 | ## Using a Fire CLI without modifying any code |
62 | 35 |
|
|
0 commit comments