-
-
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
2 changed files
with
145 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,61 @@ | ||
use crate::model::{Block, Comment, SimpleVariable, Variable}; | ||
use std::env::args; | ||
use std::io::{stdout, BufWriter}; | ||
|
||
use anyhow::Result; | ||
Check failure on line 4 in src/main.rs GitHub Actions / test-rs
|
||
|
||
use crate::model::{ | ||
AutoGeneratedVariable, Block, Comment, SimpleVariable, VariableWithDefaultValue, | ||
VariableWithRandomValue, Variables, | ||
}; | ||
use crate::parser::Parser; | ||
Check failure on line 10 in src/main.rs GitHub Actions / test-rs
|
||
|
||
mod model; | ||
mod parser; | ||
Check failure on line 13 in src/main.rs GitHub Actions / test-rs
|
||
|
||
fn main() -> Result<()> { | ||
if let Some(path) = args().nth(1) { | ||
let out = BufWriter::new(stdout()); | ||
let mut parser = Parser::new(out); | ||
parser.parse(path)?; | ||
return Ok(()); | ||
} | ||
|
||
fn main() { | ||
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