CS 111 › Lesson 12 of 12

Capstone: CLI Application Project

Lesson 12 · CS 111: Programming I — Python · OKSTEM College

Capstone: CLI Application Project

Apply everything from CS 111 by building a complete command-line application from scratch.

Work through the concepts using Python in your editor or Replit. Use the knowledge check below to test yourself.

Try It Yourself

Key Exercise

Open a Python file and implement the core concepts from this lesson. Start small, test each part, then combine.

Knowledge Check

In a CLI application, what does parsing arguments mean?

Parsing is a runtime operation, not compilation.
Correct.
Printing is output; parsing is input.
Transpiling is different from argument parsing.
Quick Recap

Argument parsing reads command-line flags and values (like --output file.txt) and makes them available to your program.

Quick Recap

Parsing processes input (command-line arguments). Printing is output to the user.

Quick Recap

Python stays Python. Argument parsing is about processing sys.argv or using argparse to handle CLI input.

Which module provides argument parsing for CLI tools?

sys.argv gives raw args, but sys doesn't parse them.
Correct - the standard library module for CLI arg parsing.
os provides OS interaction, not argument parsing.
json handles JSON data, not CLI arguments.
Quick Recap

sys.argv is a list of raw string arguments. argparse parses them into named flags and values with help text.

Quick Recap

os.path, os.getcwd(), etc. are for file system operations. argparse handles command-line arguments.

Quick Recap

json.loads() parses JSON strings. argparse parses command-line arguments.

What is the purpose of a __main__.py file in a package?

Python doesn't require a main class.
Correct.
Constants can go in any module.
That would be __init__.py (optionally).
Quick Recap

__main__.py makes a package runnable with 'python -m packagename'. It's the entry point for package execution.

Quick Recap

__main__.py is the entry point when running a package as a script. Constants can be defined anywhere.

Quick Recap

__init__.py runs when a package is imported. __main__.py runs when a package is executed with -m.

Which is the best approach for error handling in a CLI tool?

Users should see friendly messages, not tracebacks.
Correct - sys.exit(1) signals failure to the shell.
Silent failures are worse than crashes.
This catches too broadly and hides specific error types.
Quick Recap

Tracebacks expose internals and confuse users. Catch exceptions, print clear messages, and exit with a non-zero status code.

Quick Recap

Swallowing exceptions hides bugs and leaves users confused. Handle errors explicitly with clear messages.

Quick Recap

A single global try/except loses context about where the error occurred. Handle exceptions at the appropriate level.

When should you break a large script into modules?

Large single files become hard to navigate and test.
Correct - modules organize and enable code reuse.
Organization should be based on logic, not line count.
3 functions in one file is perfectly fine.
Quick Recap

Single-file scripts are fine for small programs. As a project grows, modules improve organization and testability.

Quick Recap

A 500-line file with unrelated functions is worse than a 1000-line file that's well-organized. Split by logical responsibility.

Quick Recap

Module splitting is about logical organization and reuse, not a fixed function count threshold.