Add a --list flag that prints the available vehicles #1

Merged
rev merged 1 commit from feat/add-a-list-flag-that-prints-the-available-vehicles into main 2026-09-04 04:53:16 +00:00
2 changed files with 26 additions and 0 deletions

View file

@ -177,6 +177,7 @@ $ sl -s 0.1 # You do not
| `-w` | `--whistle` | Sound the whistle as the train or ship passes |
| `-s` | `--speed` | Animation speed multiplier, 0.120 (default: 1.0) |
| | `--no-color` | Disable colors (`NO_COLOR` is also honored) |
| | `--list` | List the available vehicles with a one-line description and exit |
| `-v` | `--version` | Show version information |
| `-h` | `--help` | Show help message |

25
sl
View file

@ -176,6 +176,14 @@ class Train:
"c51": C51,
}
# One-line descriptions for --list
DESCRIPTIONS = {
"classic": "the classic steam locomotive, no surprises",
"small": "a small locomotive for narrow terminals",
"d51": "D51 locomotive (Japanese style), pulls coal cars with -l",
"c51": "C51 locomotive, the -c engine",
}
# Wheel animation: (row index, pattern, 4-frame cycle). Each cycle entry
# must be the same width as the pattern it replaces.
WHEEL_SPEC = {
@ -348,6 +356,15 @@ class Vessel:
"tug": TUG,
}
# One-line descriptions for --list
DESCRIPTIONS = {
"galleon": "three-masted pirate galleon, flapping Jolly Roger, "
"rubber-duck figurehead",
"steamer": "sternwheel steamer whose paddle wheel actually turns",
"sloop": "a racing sloop for narrow terminals",
"tug": "harbor tug in three-quarter perspective, travels diagonally",
}
SIDE_VIEW = ("galleon", "steamer", "sloop") # ride the drawn sea
PERSPECTIVE = ("tug",) # travel their drawn angle
@ -1038,11 +1055,19 @@ def main():
'clamped to 0.1-20 (default: 1.0)')
parser.add_argument('--no-color', action='store_true',
help='disable colors (NO_COLOR is also honored)')
parser.add_argument('--list', action='store_true',
help='list the available vehicles and exit')
parser.add_argument('-v', '--version', action='version',
version=f'sl version {__version__}')
args = parser.parse_args()
if args.list:
descriptions = {**Train.DESCRIPTIONS, **Vessel.DESCRIPTIONS}
for name in sorted(Train.TRAINS) + sorted(Vessel.VESSELS):
print(f"{name:<8} {descriptions[name]}")
return
# Determine what rolls out (or sets sail)
if args.type:
craft = args.type