Skip to content

Commit

Permalink
feat: accept multiple arguments as inputs (#104)
Browse files Browse the repository at this point in the history
Co-authored-by: William Woodruff <[email protected]>
  • Loading branch information
miketheman and woodruffw authored Nov 3, 2024
1 parent 13b598f commit 2faf309
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ struct Args {
#[arg(long, value_enum)]
format: Option<OutputFormat>,

/// The workflow filename or directory to audit.
input: PathBuf,
/// The workflow filenames or directories to audit.
#[arg(required = true)]
inputs: Vec<PathBuf>,
}

#[derive(Debug, Copy, Clone, ValueEnum)]
Expand All @@ -70,33 +71,42 @@ fn main() -> Result<()> {
let config = AuditConfig::from(&args);

let mut workflow_paths = vec![];
if args.input.is_file() {
workflow_paths.push(args.input.clone());
} else if args.input.is_dir() {
let mut absolute = std::fs::canonicalize(&args.input)?;
if !absolute.ends_with(".github/workflows") {
absolute.push(".github/workflows")
}
for input in args.inputs {
if input.is_file() {
workflow_paths.push(input.clone());
} else if input.is_dir() {
let mut absolute = std::fs::canonicalize(&input)?;
if !absolute.ends_with(".github/workflows") {
absolute.push(".github/workflows")
}

log::debug!("collecting workflows from {absolute:?}");
log::debug!("collecting workflows from {absolute:?}");

for entry in std::fs::read_dir(absolute)? {
let workflow_path = entry?.path();
match workflow_path.extension() {
Some(ext) if ext == "yml" || ext == "yaml" => workflow_paths.push(workflow_path),
_ => continue,
for entry in std::fs::read_dir(absolute)? {
let workflow_path = entry?.path();
match workflow_path.extension() {
Some(ext) if ext == "yml" || ext == "yaml" => {
workflow_paths.push(workflow_path)
}
_ => continue,
}
}
} else {
return Err(anyhow!("input malformed, expected file or directory"));
}
}

if workflow_paths.is_empty() {
return Err(anyhow!(
"no workflow files collected; empty or wrong directory?"
));
}
} else {
return Err(anyhow!("input must be a single workflow file or directory"));
if workflow_paths.is_empty() {
return Err(anyhow!(
"no workflow files collected; empty or wrong directory?"
));
}

log::debug!(
"collected workflows: {workflows:?}",
workflows = workflow_paths
);

let audit_state = AuditState::new(config);

let mut workflow_registry = WorkflowRegistry::new();
Expand Down

0 comments on commit 2faf309

Please sign in to comment.