-
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.
* feat: explain command * Update explain.rs * feat: pretty print explain * chore: clean * fix: get pretty_print_rule() to work Co-Authored-By: Andrew Thrasher <1165729+adthrasher@users.noreply.github.com> * Update README.md * docs: warning -> rule Co-Authored-By: Andrew Thrasher <1165729+adthrasher@users.noreply.github.com> --------- Co-authored-by: Andrew Thrasher <1165729+adthrasher@users.noreply.github.com>
- Loading branch information
1 parent
8a35eef
commit f4cc42b
Showing
6 changed files
with
73 additions
and
8 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
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,51 @@ | ||
use clap::Parser; | ||
use colored::Colorize; | ||
use wdl::ast::v1::lint as ast_lint; | ||
use wdl::core::concern::lint::Rule; | ||
use wdl::grammar::v1::lint as grammar_lint; | ||
|
||
/// Arguments for the `explain` subcommand. | ||
#[derive(Parser, Debug)] | ||
#[command(author, version, about)] | ||
pub struct Args { | ||
/// The name or code of the rule to explain. | ||
#[arg(required = true)] | ||
pub rule_identifier: String, | ||
} | ||
|
||
pub fn pretty_print_rule<E>(rule: &dyn Rule<E>) { | ||
println!("{}", rule.name().bold().underline()); | ||
println!("{}", format!("{}::{}", rule.code(), rule.tags(),).yellow()); | ||
println!(); | ||
println!("{}", rule.body()); | ||
} | ||
|
||
pub fn explain(args: Args) -> anyhow::Result<()> { | ||
let ident = args.rule_identifier; | ||
|
||
let rule = grammar_lint::rules() | ||
.into_iter() | ||
.find(|rule| rule.name() == ident || rule.code().to_string() == ident); | ||
|
||
match rule { | ||
Some(rule) => { | ||
pretty_print_rule(&*rule); | ||
} | ||
None => { | ||
let rule = ast_lint::rules() | ||
.into_iter() | ||
.find(|rule| rule.name() == ident || rule.code().to_string() == ident); | ||
|
||
match rule { | ||
Some(rule) => { | ||
pretty_print_rule(&*rule); | ||
} | ||
None => { | ||
anyhow::bail!("No rule found with the identifier '{}'", ident); | ||
} | ||
} | ||
} | ||
} | ||
|
||
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