4
4
5
5
## Basic usage
6
6
7
- Every Fire command (even just running your Fire CLI with no arguments) always
8
- corresponds to a Python component.
7
+ Every Fire command corresponds to a Python component.
9
8
10
- This can be any Python component, e.g. an object, a function, a class, or a
11
- module. To see what Python component a Fire command corresponds to, append
12
- ` -- --help ` to the command. For example, to see what Python component the
13
- command ` widget whack ` corresponds to, run ` widget whack -- --help ` . To see what
14
- Python component the command ` widget whack 5 ` corresponds to, run
15
- ` widget whack 5 -- --help ` . To see what Python component the command ` widget `
16
- corresponds to, run ` widget -- --help ` .
9
+ The simplest Fire command consists of running your program with no additional
10
+ arguments. This command corresponds to the Python component you called the
11
+ ` Fire ` function on. If you did not supply an object in the call to ` Fire ` , then
12
+ the context in which ` Fire ` was called will be used as the Python component.
17
13
18
- When you first go to use a Fire CLI you're unfamiliar with, let's say it is
19
- called ` widget ` , start by seeing what Python component the command corresponds
20
- to without any arguments, by calling ` widget -- --help ` .
14
+ You can append ` -- --help ` to any command to see what Python component it
15
+ corresponds to, as well as the various ways in which you can extend the command.
16
+ Flags are always separated from the Fire command by an isolated ` -- ` in order
17
+ to distinguish between flags and named arguments.
18
+
19
+ Given a Fire command that corresponds to a Python object, you can extend that
20
+ command to access a member of that object, call it with arguments if it is a
21
+ function, instantiate it if it is a class, or index into it if it is a list.
22
+
23
+ Read on to learn about how you can write a Fire command corresponding to
24
+ whatever Python component you're looking for.
21
25
22
- The following sections discuss how you can write a Fire command corresponding
23
- to whatever Python component you're looking for.
24
26
25
27
### Accessing members of an object
26
28
@@ -37,14 +39,15 @@ named high_score, then you can add the argument 'high-score' to your command,
37
39
and the resulting new command corresponds to the value of the high_score
38
40
property.
39
41
42
+
40
43
### Accessing members of a dict
41
44
42
45
If your command corresponds to a dict, you can extend your command by adding
43
46
the name of one of the dict's keys as an argument.
44
47
45
- For example, ` widget function-that-returns-dict key ` will correspond to the
46
- value of the item with key " key" in the dict returned by
47
- function_that_returns_dict.
48
+ For example, ` widget function-that-returns-dict key ` will correspond to the
49
+ value of the item with key ` key ` in the dict returned by
50
+ ` function_that_returns_dict ` .
48
51
49
52
50
53
### Accessing members of a list or tuple
@@ -77,18 +80,18 @@ You can force a function that takes a variable number of arguments to be
77
80
evaluated by adding a separator (the default separator is the hyphen, "-"). This
78
81
will prevent arguments to the right of the separator from being consumed for
79
82
calling the function. This is useful if the function has arguments with default
80
- values, or if the function accepts * varargs, or if the function accepts
81
- * * kwargs.
83
+ values, or if the function accepts \ * varargs, or if the function accepts
84
+ \*\ * kwargs.
82
85
83
86
See also the section on [ Changing the Separator] ( #separator-flag ) .
84
87
85
88
86
89
### Instantiating a class
87
90
88
91
If your command corresponds to a class, you can extend your command by adding
89
- the arguments of the class's __ init __ function. Arguments can be specified
90
- positionally, or by name. To specify an argument by name, use flag syntax. See
91
- the section on [ calling a function] ( #calling-a-function ) for more details.
92
+ the arguments of the class's \_\_ init \_\_ function. Arguments must be specified
93
+ by name, using the flags syntax. See the section on
94
+ [ calling a function] ( #calling-a-function ) for more details.
92
95
93
96
94
97
## Using Flags with Fire CLIs <a name =" using-flags " ></a >
0 commit comments