0%

Programs That Take Arguments · capstone

Capstone project: Project: Run the Catalog CLI

The catalog project no longer has one fixed run. Its public boundary is now the command written at the start of the chapter:

python catalog.py INPUT_PATH OUTPUT_PATH [--minimum-quantity COUNT]

Use it in the site’s Bash session to create the project artifact:

python catalog.py catalog.csv selected.json --minimum-quantity 4
cat selected.json

The command should report:

Wrote 2 items to selected.json.

selected.json should contain BK-101 and PN-330 in that order. The item with quantity 0 does not meet the threshold. The JSON shape, , UTF-8 text, indentation, and trailing newline remain the Chapter 7 contract.

The same program outside this Bash session

The Python interface is cross-platform. Only path spelling in the invocation changes when you choose to use platform-specific separators.

python catalog.py catalog.csv selected.json --minimum-quantity 4
echo $?

The second line prints the process status after the run.

Walk the whole contract yourself

You wrote a table at the start of this chapter promising four different outcomes. Now go and collect all four, checking the exit status each time:

python catalog.py --help; echo $?
python catalog.py catalog.csv out.json; echo $?
python catalog.py catalog.csv; echo $?
python catalog.py missing.csv out.json; echo $?

You should see 0, 0, 2, 1, in that order. Try a few option values too: --minimum-quantity 0, then -1, then two. The last two should both be rejected by argparse before your converter opens anything.

Watch where the text lands, not just what it says. Send stdout to a file with > and check that the error messages still appear on your screen. That is the whole point of using two streams, and it is the fastest way to confirm you got it right.

Press Check my work when selected.json and every row of the table agree.

If one of the statuses surprises you, ask Monty to explain which layer produced it. The distinction between argparse exiting with 2 and your own main returning 1 is the one worth being sure about.

Task

Run the accumulated catalog command to create selected.json from catalog.csv with --minimum-quantity 4, inspect the artifact, and submit the saved workspace.

The grader checks the durable artifact and invokes the program with unseen argv. It does not inspect or infer shell history.