diff --git a/src/lib.rs b/src/lib.rs index f51c23e..4f4b5d2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,7 +49,6 @@ pub fn parse_graph_stages(path: &PathBuf) -> Result<(), PestError> { use std::fs::File; use std::io::Read; - match File::open(path) { Ok(mut file) => { let mut contents = String::new(); @@ -94,13 +93,13 @@ fn stage_graphs(buffer: &str) -> Result, PestError> { fn get_stage_names(pairs: Pairs) -> impl Iterator + '_ { pairs.flat_map(|stage| { if let Rule::stage = stage.as_rule() { - if let Some(stage_name_span) = stage.into_inner().next() { + if let Some(stage_name_span) = stage.into_inner().next() { let stage_name = stage_name_span.as_str(); - return Some(&stage_name[1..stage_name.len()-1]); + return Some(&stage_name[1..stage_name.len() - 1]); } return None; } - return None + return None; }) } @@ -112,16 +111,15 @@ fn stage_graphs(buffer: &str) -> Result, PestError> { pest::Position::from_start(buffer), )); } - + let parser = PipelineParser::parse(Rule::pipeline, buffer)?; - if let Some(a) = parser.flat_map(|parsed| { - match parsed.as_rule() { - Rule::stagesDecl => { - Some(get_stage_names(parsed.into_inner())) - } - _ => None - } - }).next() { + if let Some(a) = parser + .flat_map(|parsed| match parsed.as_rule() { + Rule::stagesDecl => Some(get_stage_names(parsed.into_inner())), + _ => None, + }) + .next() + { return Ok(a.collect::>()); } else { return Err(PestError::new_from_pos( diff --git a/src/main.rs b/src/main.rs index 849b764..b54c26f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ enum Command { #[options(help = "Validate the syntax of a Jenkinsfile")] Check(CheckOpts), #[options(help = "Print the stages graph of a Jenkinsfile")] - Graph(GraphOpts) + Graph(GraphOpts), } // Options accepted for the `make` command @@ -38,7 +38,6 @@ struct GraphOpts { file: std::path::PathBuf, } - /// The number of lines of context to show for errors const LINES_OF_CONTEXT: usize = 4;