Crystal CLI tool: OptionParser, exit codes and specs

9 steps · about 2 h 50 min · Intermediate

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. Testing - Crystal (guide, Crystal official reference, 25 min)

    Covers describe/it, should matchers, spec_helper and the crystal spec options for running specs.

  8. 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.

  9. 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.