Crystal CLI tool: OptionParser, exit codes and specs
9 steps · about 2 h 50 min · Intermediate
- Beginner's Guide: Creating Your First Crystal Project (tutorial, hahwul.com, 25 min)
Start by scaffolding an app with shards, then run, spec and build it, so you have a project to work in.
- Chapter 4: Creating a new project (guide, Crystal for Rubyists, 15 min)
Explains what crystal init app generates (src, spec, shard.yml) and how shards manages dependencies.
- A first look at Crystal as a Gopher (article, DEV Community (Andy Haskell), 15 min)
A short walkthrough of the loop you will repeat: write a method, add a spec, run shards build.
- Command Line Arguments in Crystal (article, Learn X by Example, 10 min)
Shows ARGV, the raw argument array, before you move on to a proper parser.
- OptionParser - Crystal 1.22.0-dev (reference, Crystal official API docs, 30 min)
The official reference for flags, arguments, subcommands and auto-generated help, with a working salute example.
- Top Level Namespace - Crystal 1.20.0 (reference, Crystal official API docs, 15 min)
Covers exit, abort, STDERR and at_exit, which you need to signal errors correctly to the shell.
- Testing - Crystal (guide, Crystal official reference, 25 min)
Covers describe/it, should matchers, spec_helper and the crystal spec options for running specs.
- IO::Memory - Crystal 1.16.3 (reference, Crystal official API docs, 15 min)
IO::Memory lets your tool write to an in-memory buffer that a spec can read back and check.
- Testing Shell Commands with the Crystal CLI (article, FireHydrant, 20 min)
A real-world example of structuring a Crystal CLI and stubbing process calls so it can be tested.