Skip to content
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

feat: accept multiple arguments as inputs #104

Merged
merged 3 commits into from
Nov 3, 2024
Merged
Changes from all 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
30 changes: 20 additions & 10 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,10 +71,11 @@ 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)?;
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")
}
Expand All @@ -83,19 +85,27 @@ fn main() -> Result<()> {
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),
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"));
}

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

let audit_state = AuditState::new(config);

Expand Down