Skip to content

Commit 6e44597

Browse files
committed
feat: accept multiple arguments as inputs
Accept multiple individual files as inputs. Useful with other mutli-file processing like xargs or other tools, so as to not have to invoke zizmor multiple times, and distinct from operating on an entire directory. Signed-off-by: Mike Fiedler <[email protected]>
1 parent e050f08 commit 6e44597

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

Diff for: src/main.rs

+25-22
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ struct Args {
4747
#[arg(long, value_enum)]
4848
format: Option<OutputFormat>,
4949

50-
/// The workflow filename or directory to audit.
51-
input: PathBuf,
50+
/// The workflow filenames or directories to audit.
51+
inputs: Vec<PathBuf>,
5252
}
5353

5454
#[derive(Debug, Copy, Clone, ValueEnum)]
@@ -70,32 +70,35 @@ fn main() -> Result<()> {
7070
let config = AuditConfig::from(&args);
7171

7272
let mut workflow_paths = vec![];
73-
if args.input.is_file() {
74-
workflow_paths.push(args.input.clone());
75-
} else if args.input.is_dir() {
76-
let mut absolute = std::fs::canonicalize(&args.input)?;
77-
if !absolute.ends_with(".github/workflows") {
78-
absolute.push(".github/workflows")
79-
}
73+
for input in args.inputs {
74+
if input.is_file() {
75+
workflow_paths.push(input.clone());
76+
} else if input.is_dir() {
77+
let mut absolute = std::fs::canonicalize(&input)?;
78+
if !absolute.ends_with(".github/workflows") {
79+
absolute.push(".github/workflows")
80+
}
8081

81-
log::debug!("collecting workflows from {absolute:?}");
82+
log::debug!("collecting workflows from {absolute:?}");
8283

83-
for entry in std::fs::read_dir(absolute)? {
84-
let workflow_path = entry?.path();
85-
match workflow_path.extension() {
86-
Some(ext) if ext == "yml" || ext == "yaml" => workflow_paths.push(workflow_path),
87-
_ => continue,
84+
for entry in std::fs::read_dir(absolute)? {
85+
let workflow_path = entry?.path();
86+
match workflow_path.extension() {
87+
Some(ext) if ext == "yml" || ext == "yaml" => workflow_paths.push(workflow_path),
88+
_ => continue,
89+
}
8890
}
89-
}
9091

91-
if workflow_paths.is_empty() {
92-
return Err(anyhow!(
93-
"no workflow files collected; empty or wrong directory?"
94-
));
92+
if workflow_paths.is_empty() {
93+
return Err(anyhow!(
94+
"no workflow files collected; empty or wrong directory?"
95+
));
96+
}
97+
} else {
98+
return Err(anyhow!("input malformed, expected file or directory"));
9599
}
96-
} else {
97-
return Err(anyhow!("input must be a single workflow file or directory"));
98100
}
101+
log::debug!("collected workflows: {workflows:?}", workflows = workflow_paths);
99102

100103
let audit_state = AuditState::new(config);
101104

0 commit comments

Comments
 (0)