Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ edition = "2024"

[dependencies]
clap = { version = "4.5", features = ["derive", "env"] }
anyhow = "1"

19 changes: 16 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::{Result, bail};
use clap::{ArgGroup, Parser, Subcommand};
use std::path::PathBuf;

Expand Down Expand Up @@ -40,11 +41,23 @@ enum Command {
},
}

fn main() {
fn main() -> Result<()> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like importing result from anyhow, let's specify anyhow::Result every time 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Dropped Result from the import and spelled out anyhow::Result in the signature.

let cli = Cli::parse();
match cli.command {
Command::Analyze { repo, org, check } => {
println!("analyze repo={repo:?} org={org:?} check={check:?}");
Command::Analyze {
repo: repo_arg,
org: _,
check: _,
} => {
if let Some(repo_arg) = repo_arg {
let parts: Vec<&str> = repo_arg.split('/').collect();
if parts.len() != 2 || parts[0].is_empty() || parts[1].is_empty() {
bail!("--repo must be in the form owner/name");
}
let (org, repo) = (parts[0], parts[1]);
println!("parsed org={org} repo={repo}");
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the main function should be small, let's have an analyze function in an analyze.rs file under a command directory.
Then have another function that parses a string and returns a struct with org and repo
Then you can add a test that tests that this function works

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have Moved the analyze logic into src/command/analyze.rs, added a ParsedRepo struct with parse_repo, and added tests for the happy path and four failure cases.

}
}
Ok(())
}