Skip to content

Commit 49ebfea

Browse files
committed
allow passing subdirs for git
1 parent 6f39c1d commit 49ebfea

File tree

3 files changed

+50
-15
lines changed

3 files changed

+50
-15
lines changed

.github/workflows/release.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ jobs:
3030
include:
3131
- target: x86_64-unknown-linux-gnu
3232
os: ubuntu-latest
33-
- target: x86_64-apple-darwin
34-
os: macos-latest
3533
- target: aarch64-apple-darwin
3634
os: macos-latest
3735
- target: x86_64-pc-windows-msvc

src/cli.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub enum Exclude {
3232
)]
3333
pub struct Cli {
3434
/// Files or directories to analyze (multiple allowed), or a single URL/git repository
35-
#[arg(value_parser = validate_input, default_value = ".")]
35+
#[arg(default_value = ".")]
3636
pub paths: Vec<String>,
3737

3838
/// Print the config file path and exit
@@ -158,21 +158,27 @@ impl Cli {
158158
new_cli.paths = vec![path.to_string()];
159159
new_cli
160160
}
161-
}
162-
163-
fn validate_input(input: &str) -> Result<String, String> {
164-
if input.starts_with("http://") || input.starts_with("https://") {
165-
return Ok(input.to_string());
166-
}
167161

168-
let path = PathBuf::from(input);
169-
if path.exists() {
170-
Ok(input.to_string())
171-
} else {
172-
Err(format!("Path '{}' does not exist", input))
162+
pub fn validate_args(&self, is_url: bool) -> anyhow::Result<()> {
163+
if is_url {
164+
return Ok(());
165+
}
166+
if self.paths.is_empty() {
167+
return Err(anyhow::anyhow!("No paths provided"));
168+
}
169+
for input in &self.paths {
170+
if !input.starts_with("http://") && !input.starts_with("https://") {
171+
let path = PathBuf::from(input);
172+
if !path.exists() {
173+
return Err(anyhow::anyhow!("Path '{}' does not exist", input));
174+
}
175+
}
176+
}
177+
Ok(())
173178
}
174179
}
175180

181+
176182
fn parse_exclude(value: &str) -> Result<Exclude, String> {
177183
let path = PathBuf::from(value);
178184
if path.exists() {

src/main.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ fn main() -> anyhow::Result<()> {
3333
|| path.starts_with("http://")
3434
|| path.starts_with("https://")
3535
})
36+
.take(1)
3637
.collect();
3738

3839
if url_paths.len() > 1 {
@@ -45,8 +46,37 @@ fn main() -> anyhow::Result<()> {
4546
if GitProcessor::is_git_url(url_path) {
4647
let git_processor = GitProcessor::new()?;
4748
let repo_path = git_processor.process_repo(url_path)?;
48-
process_directory(&args.with_path(repo_path.to_str().unwrap()))?;
49+
args.validate_args(true)?;
50+
51+
let mut subpaths: Vec<String> = vec![];
52+
let mut found_url = false;
53+
for p in &args.paths {
54+
if !found_url && p.as_str() == url_path.as_str() {
55+
found_url = true;
56+
continue;
57+
}
58+
if found_url {
59+
subpaths.push(p.clone());
60+
}
61+
}
62+
63+
let process_args = if subpaths.is_empty() {
64+
// No subpaths specified, process the whole repo
65+
args.with_path(repo_path.to_str().unwrap())
66+
} else {
67+
// Process only the specified subpaths inside the repo
68+
let mut new_args = args.clone();
69+
new_args.paths = subpaths.iter().map(|sub| {
70+
// Join with repo_path
71+
let mut joined = std::path::PathBuf::from(&repo_path);
72+
joined.push(sub);
73+
joined.to_string_lossy().to_string()
74+
}).collect();
75+
new_args
76+
};
77+
process_directory(&process_args)?;
4978
} else if url_path.starts_with("http://") || url_path.starts_with("https://") {
79+
args.validate_args(true)?;
5080
let link_depth = args.link_depth.unwrap_or(config.default_link_depth);
5181
let traverse = args.traverse_links || config.traverse_links;
5282

@@ -60,6 +90,7 @@ fn main() -> anyhow::Result<()> {
6090
}
6191
}
6292
} else {
93+
args.validate_args(false)?;
6394
process_directory(&args)?;
6495
}
6596

0 commit comments

Comments
 (0)