flagon-io/hello

public

Greets people from the command line. The sample repository for g1t.

Plans

The outcome

The greeter should grow three small command-line features. A --shout flag upper-cases the greeting. A --version flag prints the crate's version and exits. A --times N flag prints the greeting N times. Each should have a test, and the README's usage section should describe all three.

Asked for by syntaqx

What happened

What was opened

5 issues, 1 that can start at once

All three flags touch the argument handling in src/main.rs (and the same tests in src/lib.rs), so first a small refactor moves argument parsing into a testable function in the library, then each flag is added in turn as a dependent issue, and the README is updated last once the behaviour is settled.

  1. 1

    Starts at oncecargo buildcargo test

    src/lib.rssrc/main.rs

    What the agent will be told

    Currently src/main.rs reads the name straight from env::args().nth(1). Add to src/lib.rs a pub struct Options { pub name: Option<String> } and pub fn parse_args<I: IntoIterator<Item = String>>(args: I) -> Options (args excludes the program name). Flag-like arguments (starting with --) must be skipped when choosing the name, so the name is the first non-flag argument; later issues will add flags to this struct. Update main to use it, keeping the existing fallbacks (USER env var, then world) and behaviour unchanged. Add unit tests in src/lib.rs for: no args, a name, and a leading unknown --flag followed by a name.

  2. 2

    After #19cargo testcargo run -- --shout Ada

    src/lib.rssrc/main.rs

    What the agent will be told

    Add pub shout: bool to Options in src/lib.rs, set by --shout in parse_args. In src/main.rs, when set, print the greeting upper-cased (HELLO, ADA!). Add unit tests in src/lib.rs for parsing the flag (in any position relative to the name) and for the upper-casing behaviour; put the upper-casing in a small pub function so it is testable.

  3. 3

    After #20cargo testcargo run -- --version

    src/lib.rssrc/main.rstests/cli.rs

    What the agent will be told

    Add pub version: bool to Options in src/lib.rs, set by --version in parse_args. In src/main.rs, when set, print env!("CARGO_PKG_VERSION") (e.g. 0.1.0) and exit with status 0 without printing a greeting. Add a unit test for parsing the flag, and an integration test in tests/cli.rs that runs the binary (use env!("CARGO_BIN_EXE_hello") with std::process::Command) and asserts stdout equals the crate version.

  4. 4

    After #21cargo testcargo run -- --times 3 Ada

    src/lib.rssrc/main.rstests/cli.rs

    What the agent will be told

    Add pub times: usize (default 1) to Options in src/lib.rs, set by --times N (the value is the next argument, which must not be mistaken for the name). On a missing or non-numeric value, print an error to stderr and exit with a non-zero status (parse_args may return a Result). In src/main.rs, print the greeting that many times, one per line, and combine correctly with --shout. Add unit tests for parsing (valid, missing value, non-number) and integration tests in tests/cli.rs running the binary with --times 3 Ada and with --times 2 --shout Ada.

  5. 5

    After #22cargo run -- --shout Adacargo run -- --times 2 Adacargo run -- --version

    README.md

    What the agent will be told

    In README.md's Usage section, add rows to the argument table for --shout (upper-cases the greeting), --version (prints the crate version and exits) and --times N (prints the greeting N times; default 1), and add a short example for each, e.g. cargo run -- --shout Ada giving HELLO, ADA!. Verify examples against the real binary. Leave the other sections unchanged.

Everything in this plan has landed.