flagon-io/hello

public

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

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

Closedsyntaqx opened this chore
Resolved by Extract command-line parsing into a testable function in lib.rs #24, merged by g1t

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.

Pull requests

1 for this issue

Discussion

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

Sign in to comment.