Skip to content

Commit

Permalink
Exec cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
himanoa committed Aug 20, 2021
1 parent ecc14e0 commit 9bffd77
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
24 changes: 11 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ pub fn parse_graph_stages(path: &PathBuf) -> Result<(), PestError<Rule>> {
use std::fs::File;
use std::io::Read;


match File::open(path) {
Ok(mut file) => {
let mut contents = String::new();
Expand Down Expand Up @@ -94,13 +93,13 @@ fn stage_graphs(buffer: &str) -> Result<Vec<&str>, PestError<Rule>> {
fn get_stage_names(pairs: Pairs<Rule>) -> impl Iterator<Item = &str> + '_ {
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;
})
}

Expand All @@ -112,16 +111,15 @@ fn stage_graphs(buffer: &str) -> Result<Vec<&str>, PestError<Rule>> {
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::<Vec<_>>());
} else {
return Err(PestError::new_from_pos(
Expand Down
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down

0 comments on commit 9bffd77

Please sign in to comment.