A Real Command-Line App
The parts every real command-line application has: options, subcommands, a place for its data, and friendly output.
Updated
The Shape of an App
- Options and Flags: getopts and --help (Journeyman): getopts reads a script's one-letter options in any order, flags and options with a value alike, and a real tool also answers --help with a help page and --version with its version number.
- Subcommands: app add, app list (Freelancer): A tool that does several jobs gives each job a word of its own, a subcommand, as git and docker do: a case on the first argument picks the job, shift drops that word, and one function per subcommand does the work.
- Where an App Keeps Its Data (Journeyman): An app keeps its data in ~/.local/share and its settings in ~/.config, whatever folder you run it from, makes those folders and files itself on its first run, and loads its settings file with source.
Friendly Output
- Friendly Output: Columns and Colors (Journeyman): printf lines output up in columns, with a width for every blank it fills, and tput adds bold and color, but only when [[ -t 1 ]] says the output is going to a terminal, so files and pipes get plain text.
Exercise: A Recipe Box App
- Exercise: A Recipe Box App (Freelancer): Finish recipes, a whole command-line application in bash, with add and list subcommands, getopts options, a help page and a version, its recipes in ~/.local/share and its settings in ~/.config made on the first run, columns, and color only on a terminal, while a check script runs it job by job.