flagon-io/hello

public

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

Say goodbye too #10

Mergedg1tbot merged into mainrequested by syntaqx

Approved by g1t

  1. Note

    Running on Claude Sonnet 5.5.

  2. Prompt

    You are a coding agent working in the git repository checked out in the current directory.

    Issue #4: Say goodbye too

    A farewell(name) next to greeting(name) would let other tools reuse this crate for both ends of a conversation.

    It should return Goodbye, <name>!.

    These commands must pass when you are done. Run them if the tools are installed:

    • cargo test

    Make the change and keep it focused on the issue. Commit your work with a clear message. Do not push; that is done for you. Finish with a short summary of what you changed and why. It becomes the description of your pull request, so write it for a reviewer: plain sentences, no headings, no emoji, no checklists, and nothing about whether anything was committed or pushed. Say what you did not verify.

  3. Bashls && cat src/lib.rs
    ls && cat src/lib.rs
  4. result→ Cargo.lock
    Cargo.lock
    Cargo.toml
    README.md
    src
    //! Greetings.
    
    /// The greeting for `name`.
    pub fn greeting(name: &str) -> String {
        let trimmed = name.trim();
        let display_name = if trimmed.is_empty() { "world" } else { trimmed };
        format!("Hello, {display_name}!")
    }
    
    #[cfg(test)]
    mod tests {
        use super::*;
    
        #[test]
        fn greets_by_name() {
            assert_eq!(greeting("Ada"), "Hello, Ada!");
        }
    
        #[test]
        fn greets_world_with_empty_string() {
            assert_eq!(greeting(""), "Hello, world!");
        }
    
        #[test]
        fn greets_world_with_whitespace_only() {
            assert_eq!(greeting("  "), "Hello, world!");
        }
    
        #[test]
        fn trims_whitespace_from_name() {
            assert_eq!(greeting("  Ada  "), "Hello, Ada!");
        }
    }
  5. g1t

    I'll mirror greeting's name handling (trim, fall back to "world") for consistency.

  6. Bashpython3 - <<'E'
    python3 - <<'E'
    p='src/lib.rs'
    s=open(p).read()
    s=s.replace('''#[cfg(test)]''','''/// The farewell for `name`.
    pub fn farewell(name: &str) -> String {
        let trimmed = name.trim();
        let display_name = if trimmed.is_empty() { "world" } else { trimmed };
        format!("Goodbye, {display_name}!")
    }
    
    #[cfg(test)]''',1)
    s=s.rstrip()[:-1]+'''
        #[test]
        fn says_goodbye_by_name() {
            assert_eq!(farewell("Ada"), "Goodbye, Ada!");
        }
    
        #[test]
        fn says_goodbye_to_world_when_blank() {
            assert_eq!(farewell("  "), "Goodbye, world!");
        }
    
        #[test]
        fn farewell_trims_whitespace() {
            assert_eq!(farewell("  Ada  "), "Goodbye, Ada!");
        }
    }
    '''
    open(p,'w').write(s)
    E
    cargo test 2>&1 | tail -5; git commit -qam "Add farewell function alongside greeting" && echo ok
  7. result→ running 0 tests
    running 0 tests
    
    test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
    
    ok
  8. Bashcargo test 2>&1 | grep "test result"
    cargo test 2>&1 | grep "test result"
  9. result→ test result: ok. 7 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
    test result: ok. 7 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
    test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
    test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
  10. g1t

    I added farewell(name) to src/lib.rs, next to greeting. It returns Goodbye, <name>!.

    The issue only specified the plain case. I made it handle names the way greeting does: it trims surrounding whitespace, and an empty or whitespace-only name becomes "world". So farewell("") returns Goodbye, world!. I did this so the two functions behave the same for callers, but it's an assumption. It's easy to change if you'd rather have different behaviour for blank names.

    I added three unit tests, covering a plain name, a blank name, and a name with extra whitespace. cargo test passes, 7 tests in all. I did not change the CLI or the README, and I did not check whether the CLI should expose a farewell.

  11. Note

    Pushed cfd8ba0f3f98.