-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds context to generate AutoGeneratedVariable values
- Loading branch information
Showing
4 changed files
with
151 additions
and
40 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,27 +1,59 @@ | ||
use crate::model::{Block, Comment, SimpleVariable, Variable}; | ||
use std::env::args; | ||
use std::io::{stdout, BufWriter}; | ||
|
||
use anyhow::Result; | ||
|
||
use crate::model::{ | ||
AutoGeneratedVariable, Block, Comment, SimpleVariable, VariableWithDefaultValue, | ||
VariableWithRandomValue, Variables, | ||
}; | ||
|
||
mod model; | ||
|
||
fn main() { | ||
fn main() -> Result<()> { | ||
if let Some(path) = args().nth(1) { | ||
let out = BufWriter::new(stdout()); | ||
let mut parser = Parser::new(out); | ||
Check failure on line 16 in src/main.rs GitHub Actions / test-rs
|
||
parser.parse(path)?; | ||
return Ok(()); | ||
} | ||
|
||
let title = Comment { | ||
contents: "42".to_string(), | ||
}; | ||
let description = Some(Comment { | ||
contents: "Fourty-two".to_string(), | ||
}); | ||
let variable1 = Box::new(SimpleVariable { | ||
let variable1 = Variables::Simple(SimpleVariable { | ||
name: "ANSWER".to_string(), | ||
input: "42".to_string(), | ||
}) as Box<dyn Variable>; | ||
let variable2 = Box::new(SimpleVariable { | ||
}); | ||
let variable2 = Variables::Simple(SimpleVariable { | ||
name: "AS_TEXT".to_string(), | ||
input: "fourty two".to_string(), | ||
}) as Box<dyn Variable>; | ||
let variables = vec![variable1, variable2]; | ||
let block = Block { | ||
title, | ||
description, | ||
variables, | ||
}; | ||
println!("{}", block) | ||
}); | ||
let variable3 = Variables::DefaultValue(VariableWithDefaultValue { | ||
name: "DEFAULT_VALUE_ONE".to_string(), | ||
input: "".to_string(), | ||
default: "default".to_string(), | ||
}); | ||
let variable4 = Variables::DefaultValue(VariableWithDefaultValue { | ||
name: "DEFAULT_VALUE_ONE".to_string(), | ||
input: "custom".to_string(), | ||
default: "default".to_string(), | ||
}); | ||
let variable5 = Variables::Random(VariableWithRandomValue { | ||
name: "SECRET_KEY".to_string(), | ||
length: None, | ||
}); | ||
let variable6 = Variables::AutoGenerated(AutoGeneratedVariable::new( | ||
"AUTO_GENERATED".to_string(), | ||
"{ANSWER}-{DEFAULT_VALUE_ONE}".to_string(), | ||
)); | ||
let variables = vec![ | ||
variable1, variable2, variable3, variable4, variable5, variable6, | ||
]; | ||
let block = Block::new(title, description, variables); | ||
println!("{block}"); | ||
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