```
The first task is to make `minigrep` accept its two command line arguments: the
-filename and a string to search for. That is, we want to be able to run our
-program with `cargo run`, a string to search for, and a path to a file to
-search in, like so:
+file path and a string to search for. That is, we want to be able to run our
+program with `cargo run`, two hyphens to indicate the following arguments are
+for our program rather than for `cargo`, a string to search for, and a path to
+a file to search in, like so:
```console
-$ cargo run searchstring example-filename.txt
+$ cargo run -- searchstring example-filename.txt
```
Right now, the program generated by `cargo new` cannot process arguments we
can use its `args` function. Notice that the `std::env::args` function is
nested in two levels of modules. As we discussed in [Chapter
7][ch7-idiomatic-use]<!-- ignore -->, in cases where the desired function is
-nested in more than one module, it’s conventional to bring the parent module
-into scope rather than the function. By doing so, we can easily use other
-functions from `std::env`. It’s also less ambiguous than adding `use
-std::env::args` and then calling the function with just `args`, because `args`
-might easily be mistaken for a function that’s defined in the current module.
+nested in more than one module, we’ve chosen to bring the parent module into
+scope rather than the function. By doing so, we can easily use other functions
+from `std::env`. It’s also less ambiguous than adding `use std::env::args` and
+then calling the function with just `args`, because `args` might easily be
+mistaken for a function that’s defined in the current module.
> ### The `args` Function and Invalid Unicode
>
Rust, `collect` is one function you do often need to annotate because Rust
isn’t able to infer the kind of collection you want.
-Finally, we print the vector using the debug formatter, `:?`. Let’s try running
-the code first with no arguments and then with two arguments:
+Finally, we print the vector using the debug macro. Let’s try running the code
+first with no arguments and then with two arguments:
```console
{{#include ../listings/ch12-an-io-project/listing-12-01/output.txt}}
```
<span class="caption">Listing 12-2: Creating variables to hold the query
-argument and filename argument</span>
+argument and file path argument</span>
As we saw when we printed the vector, the program’s name takes up the first
value in the vector at `args[0]`, so we’re starting arguments at index `1`. The
first argument `minigrep` takes is the string we’re searching for, so we put a
reference to the first argument in the variable `query`. The second argument
-will be the filename, so we put a reference to the second argument in the
-variable `filename`.
+will be the file path, so we put a reference to the second argument in the
+variable `file_path`.
We temporarily print the values of these variables to prove that the code is
working as we intend. Let’s run this program again with the arguments `test`