examples/

directory
v0.18.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2025 License: MIT

README

Examples

This directory contains a bunch of example programs built with cli to show you how the library works and how you might implement common patterns.

./cover

Not really an example, but holds the source code used to generate the cover image with freeze

./quickstart

Implements the quickstart command from the main project README

quickstart

./subcommands

A CLI with multiple subcommands, each with their own flags and expected arguments. Shows how to easily store parsed flag values in an options struct and pass them around your program.

subcommands

./namedargs

A CLI with named positional arguments that may or may not have default values. Shows how to retrieve these arguments by name and use them without having to care if they were provided or you're using the default.

namedargs

./cancel

This examples shows how cli requiring you to pass a context.Context to your run functions leads to elegant and resilient cancellation and CTRL+C handling.

cancel

TODO
  • Replicate one or two well known CLI tools as an example
    • Docker
    • Cargo

Directories

Path Synopsis
Package cancel demonstrates how to handle CTRL+C and cancellation/timeouts easily with cli.
Package cancel demonstrates how to handle CTRL+C and cancellation/timeouts easily with cli.
Package cover is a simple CLI demonstrating the core features of this library.
Package cover is a simple CLI demonstrating the core features of this library.
Package namedargs demonstrates how to use named positional arguments in cli.
Package namedargs demonstrates how to use named positional arguments in cli.
Package quickstart demonstrates a quickstart example for cli.
Package quickstart demonstrates a quickstart example for cli.
Package subcommands demonstrates how to build a CLI with a full command structure.
Package subcommands demonstrates how to build a CLI with a full command structure.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL