-
Notifications
You must be signed in to change notification settings - Fork 1
Parse --repo owner/name input in analyze command #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,3 +5,5 @@ edition = "2024" | |
|
|
||
| [dependencies] | ||
| clap = { version = "4.5", features = ["derive", "env"] } | ||
| anyhow = "1" | ||
|
|
||
| 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; | ||
|
|
||
|
|
@@ -40,11 +41,23 @@ enum Command { | |
| }, | ||
| } | ||
|
|
||
| fn main() { | ||
| fn main() -> Result<()> { | ||
| 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}"); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the main function should be small, let's have an
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(()) | ||
| } | ||
There was a problem hiding this comment.
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::Resultevery time 😅There was a problem hiding this comment.
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.