Command-Line Program Patterns
Usage Messages
Choose a usage message when a command is missing.
usage-messages
A usage message explains the expected command shape. Programs commonly show it when required input is missing.
Usage Messages
usage_messages.pl
Replay: real traced execution (multi-file project)
use strict;
use warnings;
my $has_command = 0;
my $status = $has_command ? "ready" : "needs-help";
my $message = $has_command ? "run command" : "usage: tool command";
print "has_command=$has_command\n";
print "status=$status\n";
print "message=$message\n";
use strict;
use warnings;
my $has_command = 1;
my $status = $has_command ? "ready" : "needs-help";
my $message = $has_command ? "run command" : "usage: tool command";
print "has_command=$has_command\n";
print "status=$status\n";
print "message=$message\n";
$has_command ← 0, $status ← needs-help, $message ← usage: tool command
4my $has_command→ 0 = 0; #@has_command=15my $status→ needs-help = $has_command0 ? "ready" : "needs-help";6my $message→ usage: tool command = $has_command0 ? "run command" : "usage: tool command";78print "has_command=$has_command0\n";9print "status=$statusneeds-help\n";10print "message=$messageusage: tool command\n";outputhas_command=0 status=needs-help message=usage: tool command
$has_command ← 1, $status ← ready, $message ← run command
4my $has_command→ 1 = 1;5my $status→ ready = $has_command1 ? "ready" : "needs-help";6my $message→ run command = $has_command1 ? "run command" : "usage: tool command";78print "has_command=$has_command1\n";9print "status=$statusready\n";10print "message=$messagerun command\n";outputhas_command=1 status=ready message=run command