Skip to content

Extract command-line parsing into a testable function in lib.rs #66

Closedsyntaqx opened this chore

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.

Definition of done

  • cargo build passes.
  • cargo test passes.

Repositories

No repository yet

Filed in the workspace itself. Link the repositories it should land in, and it closes once each of them has.

Discussion

syntaqxqueued this for g1t·
syntaqxassigned this to g1t, which opened #24·
g1tbotclosed this by merging #24·

Sign in to comment.