-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod explain; | ||
pub mod lint; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use clap::Parser; | ||
use wdl::ast::v1::lint as ast_lint; | ||
use wdl::grammar::v1::lint as grammar_lint; | ||
|
||
/// Arguments for the `explain` subcommand. | ||
#[derive(Parser, Debug)] | ||
#[command(author, version, about)] | ||
pub struct Args { | ||
/// The rule name to explain. | ||
#[arg(required = true)] | ||
pub rule_name: String, | ||
} | ||
|
||
pub fn explain(args: Args) -> anyhow::Result<()> { | ||
let name = args.rule_name; | ||
|
||
let rules = grammar_lint::rules() | ||
.iter() | ||
.map(|rule| rule.name()) | ||
.chain(ast_lint::rules().iter().map(|rule| rule.name())) | ||
.collect::<Vec<String>>(); | ||
|
||
if !rules.contains(&name) { | ||
return Err(anyhow::anyhow!("Unknown rule: {}", name)); | ||
} | ||
|
||
let rule = grammar_lint::rules() | ||
.into_iter() | ||
.find(|rule| rule.name() == name); | ||
|
||
match rule { | ||
Some(rule) => { | ||
println!("{}", rule.body()); | ||
} | ||
None => { | ||
let rule = ast_lint::rules() | ||
.into_iter() | ||
.find(|rule| rule.name() == name) | ||
.unwrap(); | ||
println!("{}", rule.body()); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters