Skip to content

Commit

Permalink
rulegen docs (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshfried-aws authored Feb 20, 2024
1 parent 999474f commit 61215ac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions guard/src/commands/rulegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,27 @@ const OUTPUT_HELP: &str = "Write to output file";
#[derive(Debug, Clone, Eq, PartialEq, Args)]
#[clap(arg_required_else_help = true)]
#[clap(about=ABOUT)]
/// .
/// The Rulegen command auto generates rules from an existing CloudFormation template
/// Please note this currently only works on CloudFormation templates
pub struct Rulegen {
/// the path to the file which the generated rules will be outputted to
/// default None
/// if set to None rules will be outputted to the stdout
#[arg(short, long, help=OUTPUT_HELP)]
pub(crate) output: Option<String>,
/// the path to the CloudFormation template
#[arg(short, long, help=TEMPLATE_HELP)]
pub(crate) template: String,
}

impl Executable for Rulegen {
/// .
/// autogenerate rules from an existing CloudFormation template
///
/// This function will return an error if
/// - any of the specified paths do not exist
/// - illegal json or yaml syntax present in any of the data/input parameter files
fn execute(&self, writer: &mut Writer, _: &mut Reader) -> Result<i32> {
let template_contents = fs::read_to_string(&self.template)?;

Expand Down
6 changes: 6 additions & 0 deletions guard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,25 +416,31 @@ impl TestBuilder {
}

#[derive(Debug, Default)]
/// .
/// A builder to help construct the `Rulegen` command
pub struct RulegenBuilder {
output: Option<String>,
template: String,
}

impl CommandBuilder<Rulegen> for RulegenBuilder {
/// construct a rulegen command
fn try_build(self) -> crate::rules::Result<Rulegen> {
let RulegenBuilder { output, template } = self;
Ok(Rulegen { output, template })
}
}

impl RulegenBuilder {
/// path for the output file where the generated rules will be written to
/// if no path is specified output will be printed to the stdout
pub fn output(mut self, output: Option<String>) -> Self {
self.output = output;

self
}

/// path to the template which the rules will be autogenerated from
pub fn template(mut self, template: String) -> Self {
self.template = template;

Expand Down

0 comments on commit 61215ac

Please sign in to comment.