flagon-io/hello

public

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

Commit

Add CI workflow for formatting, lints and tests

g1t agentand Claude Sonnet 5.5committed Parent42c2b9aBrowse files
5 files+58−90/5 viewed
+28−0
1+name: CI
2+on:
3+ push:
4+ branches: [main]
5+ pull_request:
6+ merge_group:
7+jobs:
8+ check:
9+ runs-on: ubuntu-latest
10+ steps:
11+ - uses: actions/checkout@v7
12+ - uses: dtolnay/rust-toolchain@stable
13+ with:
14+ components: rustfmt, clippy
15+ - uses: actions/cache@v6
16+ with:
17+ path: |
18+ ~/.cargo/registry
19+ ~/.cargo/git
20+ target
21+ key: cargo-${{ runner.os }}-${{ hashFiles('Cargo.lock') }}
22+ restore-keys: cargo-${{ runner.os }}-
23+ - name: Formatting
24+ run: cargo fmt --check
25+ - name: Lints
26+ run: cargo clippy --all-targets -- -D warnings
27+ - name: Tests
28+ run: cargo test
+2−0
8383 cargo test
8484 ```
8585
86+Every pull request runs formatting, lints and tests.
87+
8688 ## Troubleshooting
8789
8890 **`error: --times value must be a number, got "abc"`**
+10−5
9898 let value = args
9999 .next()
100100 .ok_or_else(|| "--lang requires a value".to_owned())?;
101− options.lang = Lang::parse(&value).ok_or_else(|| {
102− format!("--lang value must be one of en, es, fr, got {value:?}")
103− })?;
101+ options.lang = Lang::parse(&value)
102+ .ok_or_else(|| format!("--lang value must be one of en, es, fr, got {value:?}"))?;
104103 } else if !arg.starts_with("--") && options.name.is_none() {
105104 options.name = Some(arg);
106105 }
196195
197196 #[test]
198197 fn parse_args_name() {
199− assert_eq!(parse_args(args(&["Ada"])).unwrap().name.as_deref(), Some("Ada"));
198+ assert_eq!(
199+ parse_args(args(&["Ada"])).unwrap().name.as_deref(),
200+ Some("Ada")
201+ );
200202 }
201203
202204 #[test]
203205 fn parse_args_skips_leading_flag() {
204206 assert_eq!(
205− parse_args(args(&["--unknown", "Ada"])).unwrap().name.as_deref(),
207+ parse_args(args(&["--unknown", "Ada"]))
208+ .unwrap()
209+ .name
210+ .as_deref(),
206211 Some("Ada")
207212 );
208213 }
+10−2
2323 .or_else(|| env::var("USER").ok())
2424 .unwrap_or_else(|| "world".to_owned());
2525 let message = greeting_in(&name, options.lang);
26− let message = if options.loud { loud(&message) } else { message };
27− let line = if options.shout { shout(&message) } else { message };
26+ let message = if options.loud {
27+ loud(&message)
28+ } else {
29+ message
30+ };
31+ let line = if options.shout {
32+ shout(&message)
33+ } else {
34+ message
35+ };
2836 for _ in 0..options.times {
2937 println!("{line}");
3038 }
+8−2
5858 fn lang_fr_greets_in_french() {
5959 let output = run(&["--lang", "fr", "Luc"]);
6060 assert!(output.status.success());
61− assert_eq!(String::from_utf8(output.stdout).unwrap(), "Bonjour, Luc !\n");
61+ assert_eq!(
62+ String::from_utf8(output.stdout).unwrap(),
63+ "Bonjour, Luc !\n"
64+ );
6265 }
6366
6467 #[test]
8386 let output = run(&["--lang"]);
8487 assert_eq!(output.status.code(), Some(2));
8588 let stderr = String::from_utf8(output.stderr).unwrap();
86− assert!(stderr.contains("--lang requires a value"), "stderr was {stderr:?}");
89+ assert!(
90+ stderr.contains("--lang requires a value"),
91+ "stderr was {stderr:?}"
92+ );
8793 }
8894
8995 #[test]