44
55## Basic usage
66
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.
98
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.
1713
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.
2125
22- The following sections discuss how you can write a Fire command corresponding
23- to whatever Python component you're looking for.
2426
2527### Accessing members of an object
2628
@@ -37,14 +39,15 @@ named high_score, then you can add the argument 'high-score' to your command,
3739and the resulting new command corresponds to the value of the high_score
3840property.
3941
42+
4043### Accessing members of a dict
4144
4245If your command corresponds to a dict, you can extend your command by adding
4346the name of one of the dict's keys as an argument.
4447
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 ` .
4851
4952
5053### 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
7780evaluated by adding a separator (the default separator is the hyphen, "-"). This
7881will prevent arguments to the right of the separator from being consumed for
7982calling 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.
8285
8386See also the section on [ Changing the Separator] ( #separator-flag ) .
8487
8588
8689### Instantiating a class
8790
8891If 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.
9295
9396
9497## Using Flags with Fire CLIs <a name =" using-flags " ></a >
0 commit comments