flagon-io/hello

public

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

Commit

Greet with Hi instead of Hello

g1t agentcommitted Parent13ffb58Browse files
3 files+13−130/3 viewed
+5−5
1313
1414 ```sh
1515 $ cargo run -- Ada
16−Hello, Ada!
16+Hi, Ada!
1717 ```
1818
1919 ```sh
2020 $ cargo run -- --shout Ada
21−HELLO, ADA!
21+HI, ADA!
2222 ```
2323
2424 ```sh
2525 $ cargo run -- --times 2 Ada
26−Hello, Ada!
27−Hello, Ada!
26+Hi, Ada!
27+Hi, Ada!
2828 ```
2929
3030 ```sh
4848
4949 `--times` needs a whole number of zero or more. If the value is anything else, such as `abc`, `-1` or `2.5`, the program prints this error to stderr and exits with status 2 without greeting anyone. Pass a plain number, for example `--times 3`. A `--times` with no value after it also fails, with `--times requires a value`.
5050
51−**The greeting says `Hello, world!` when I gave a name**
51+**The greeting says `Hi, world!` when I gave a name**
5252
5353 An empty or whitespace-only name, such as `cargo run -- ""`, is treated as no name and the greeting uses `world`. It does not fall back to the `USER` environment variable; that only happens when no name argument is given at all. Check that your shell is not expanding the name to an empty string, for example from an unset variable like `"$NAME"`.
5454
+6−6
6464 pub fn greeting(name: &str) -> String {
6565 let trimmed = name.trim();
6666 let display_name = if trimmed.is_empty() { "world" } else { trimmed };
67− format!("Hello, {display_name}!")
67+ format!("Hi, {display_name}!")
6868 }
6969
7070 /// The farewell for `name`.
162162
163163 #[test]
164164 fn shout_upper_cases_greeting() {
165− assert_eq!(shout(&greeting("Ada")), "HELLO, ADA!");
165+ assert_eq!(shout(&greeting("Ada")), "HI, ADA!");
166166 }
167167
168168 #[test]
169169 fn greets_by_name() {
170− assert_eq!(greeting("Ada"), "Hello, Ada!");
170+ assert_eq!(greeting("Ada"), "Hi, Ada!");
171171 }
172172
173173 #[test]
174174 fn greets_world_with_empty_string() {
175− assert_eq!(greeting(""), "Hello, world!");
175+ assert_eq!(greeting(""), "Hi, world!");
176176 }
177177
178178 #[test]
179179 fn greets_world_with_whitespace_only() {
180− assert_eq!(greeting(" "), "Hello, world!");
180+ assert_eq!(greeting(" "), "Hi, world!");
181181 }
182182
183183 #[test]
184184 fn trims_whitespace_from_name() {
185− assert_eq!(greeting(" Ada "), "Hello, Ada!");
185+ assert_eq!(greeting(" Ada "), "Hi, Ada!");
186186 }
187187
188188 #[test]
+2−2
2626 assert!(output.status.success());
2727 assert_eq!(
2828 String::from_utf8(output.stdout).unwrap(),
29− "Hello, Ada!\n".repeat(3)
29+ "Hi, Ada!\n".repeat(3)
3030 );
3131 }
3232
3636 assert!(output.status.success());
3737 assert_eq!(
3838 String::from_utf8(output.stdout).unwrap(),
39− "HELLO, ADA!\n".repeat(2)
39+ "HI, ADA!\n".repeat(2)
4040 );
4141 }
4242