Skip to content

Commit

Permalink
update args
Browse files Browse the repository at this point in the history
  • Loading branch information
bartvanbenthem committed Jul 4, 2023
1 parent f81a591 commit 2806154
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ FLAGS:
OPTIONS:
-o, --output <output_file> Path to the output file
-t, --template <template_file> Path to the template file
-v, --variables <variables_json> Path to the JSON file
-v, --variables <variables_file> Path to the JSON file

```

Expand Down
29 changes: 12 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ struct KeyValuePairs(BTreeMap<String, String>);
struct Config {
template_file: String,
output_file: String,
json_file: String,
yaml_file: String,
variables_file: String,
}

fn main() -> Result<(), Box<dyn Error>> {
Expand All @@ -27,14 +26,14 @@ fn main() -> Result<(), Box<dyn Error>> {
// initialize KeyValuePair type
let key_value_pairs: KeyValuePairs;

if config.json_file.is_empty() {
if config.variables_file.is_empty() {
// Process the JSON value trough stdin
let mut input = String::new();
io::stdin().read_to_string(&mut input)?;
key_value_pairs = serde_json::from_str(&input)?;
} else {
// Read JSON file
let json_content = fs::read_to_string(config.json_file)?;
let json_content = fs::read_to_string(config.variables_file)?;
key_value_pairs = serde_json::from_str(&json_content)?;
}

Expand Down Expand Up @@ -78,28 +77,19 @@ fn get_args() -> Result<Config, Box<dyn Error>> {
.help("Path to the output file"),
)
.arg(
Arg::with_name("variables_json")
.short("j")
.long("variables-json")
Arg::with_name("variables_file")
.short("v")
.long("variables")
.required(false)
.takes_value(true)
.help("Path to the JSON file"),
)
.arg(
Arg::with_name("variables_yaml")
.short("y")
.long("variables-yaml")
.required(false)
.takes_value(true)
.help("Path to the YAML file"),
)
.get_matches();

Ok(Config {
template_file: matches.value_of("template_file").unwrap().to_string(),
output_file: matches.value_of("output_file").unwrap_or("").to_string(),
json_file: matches.value_of("variables_json").unwrap_or("").to_string(),
yaml_file: matches.value_of("variables_yaml").unwrap_or("").to_string(),
variables_file: matches.value_of("variables_file").unwrap_or("").to_string(),
})
}

Expand All @@ -125,6 +115,11 @@ fn manifest_writer(output: &String, template: &String) -> Result<(), Box<dyn Err
Ok(())
}

//fn yaml_to_json(cfg: &Config) -> Result<(), Box<dyn Error>> {
//
// Ok(())
//}

// --------------------------------------------------
fn print_current_dir() {
if let Ok(current_dir) = env::current_dir() {
Expand Down

0 comments on commit 2806154

Please sign in to comment.