You need a script that ops engineers run from laptops and that CI runs nightly. How do you design its interface?
IntermediateScenarioAutomation scripting & CLI design
Answer
Situation read → Two audiences: humans (readable output, prompts) and machines (stable output, exit codes, no prompts).
What I'd do →
- click CLI with subcommands, every option settable via env var (
envvar=). --format table|json; default to table whensys.stdout.isatty()and JSON otherwise.- Logs on stderr, data on stdout;
-v/-vvfor verbosity. - Documented exit codes: 0 clean, 1 error, 2 findings.
- No interactive prompt when stdin is not a TTY; destructive actions require
--yes. - Package it with a console script so both laptop (
pipx install) and CI (docker run) use the same entry point.
Why → One tool, two consumers, no forked logic.
Interview tip → "stdout is an API" is the phrase interviewers like to hear.
More on Automation scripting & CLI design
Your team has a 300-line Bash script that parses JSON with `jq`, loops over AWS accounts and retries with `sleep`. It breaks every month. Do you rewrite it in Python?BeginnerA colleague's script deletes files older than 30 days from `/var/log/app`. You are asked to review it before it goes into cron. What do you look for?IntermediateA script reads a 15 GB access log to count 5xx errors per endpoint, and the box runs out of memory. How do you fix it?BeginnerYou must run the same Python automation on 40 servers that have Python 3.6, 3.9 and 3.12. What do you do?IntermediateA cron job that runs a Python script fails silently. Nobody noticed for two weeks. How do you make sure that never happens again?IntermediateProduct wants a Slack notification whenever a deploy finishes. You have 30 minutes. What do you build?Beginner