Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to write output to a file and fix minor TypeScript coding style & formatting issues. #50

Merged
merged 3 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ json into beautiful typescript...until now.

Noctilucent will take your json and output the equivalent typescript.

## User Guide
```
cargo build --release
./target/release/noctilucent <INPUT> <OUTPUT>
```
* `INPUT` is the input file path.
* `OUTPUT` is the output file path; if not specified, output will be printed on your command line.

## Implemented

- [x] Fn::FindInMap
Expand Down
14 changes: 13 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ fn main() {
.required(true)
.index(1),
)
.arg(
Arg::new("OUTPUT")
.help("Sets the output file to use")
.required(false)
.index(2),
)
.get_matches();

let txt_location: &str = matches.value_of("INPUT").unwrap();
Expand All @@ -24,5 +30,11 @@ fn main() {

let cfn_tree = CloudformationParseTree::build(&value).unwrap();
let ir = CloudformationProgramIr::new_from_parse_tree(&cfn_tree).unwrap();
TypescriptSynthesizer::output(ir);
let output: String = TypescriptSynthesizer::output(ir);

if matches.is_present("OUTPUT") {
fs::write(matches.value_of("OUTPUT").unwrap(), output).expect("Unable to write file");
} else {
println!("{}", output);
}
}
6 changes: 3 additions & 3 deletions src/parser/lookup_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ pub enum MappingInnerValue {
impl Display for MappingInnerValue {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
return match self {
MappingInnerValue::String(string_val) => write!(f, "\"{}\"", string_val),
MappingInnerValue::String(string_val) => write!(f, "'{}'", string_val),
MappingInnerValue::List(list_val) => {
let quoted_list_values: Vec<String> =
list_val.iter().map(|val| format!("\"{}\"", val)).collect();
list_val.iter().map(|val| format!("'{}'", val)).collect();
write!(f, "[{}]", quoted_list_values.join(","))
}
};
Expand Down Expand Up @@ -123,7 +123,7 @@ fn convert_to_string_vector(
"List values for mappings must be a string. Found {:?}, for key {}",
inner_key, vector_val
),
})
});
}
};
string_vector.push(converted_val);
Expand Down
Loading