2017-06-29 09:31:27 +02:00
|
|
|
use std::env;
|
|
|
|
use std::process::exit;
|
|
|
|
|
|
|
|
use args::{Args, ArgsError};
|
|
|
|
use getopts::Occur;
|
|
|
|
use irc::client::data::Config;
|
|
|
|
|
2018-01-02 04:25:25 +01:00
|
|
|
const PROGRAM_DESC: &str = "Use this program to convert configs between {JSON, TOML, YAML}.";
|
|
|
|
const PROGRAM_NAME: &str = "convertconf";
|
2017-06-29 09:31:27 +02:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let args: Vec<_> = env::args().collect();
|
|
|
|
match parse(&args) {
|
|
|
|
Ok(Some((ref input, ref output))) => {
|
2018-01-28 00:52:11 +01:00
|
|
|
let mut cfg = Config::load(input).unwrap();
|
2017-06-29 09:31:27 +02:00
|
|
|
cfg.save(output).unwrap();
|
|
|
|
println!("Converted {} to {}.", input, output);
|
|
|
|
}
|
|
|
|
Ok(None) => {
|
|
|
|
println!("Failed to provide required arguments.");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
Err(err) => {
|
|
|
|
println!("{}", err);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-02 04:25:25 +01:00
|
|
|
fn parse(input: &[String]) -> Result<Option<(String, String)>, ArgsError> {
|
2017-06-29 09:31:27 +02:00
|
|
|
let mut args = Args::new(PROGRAM_NAME, PROGRAM_DESC);
|
|
|
|
args.flag("h", "help", "Print the usage menu");
|
2019-08-27 15:05:51 +02:00
|
|
|
args.option(
|
|
|
|
"i",
|
|
|
|
"input",
|
|
|
|
"The path to the input config",
|
|
|
|
"FILE",
|
|
|
|
Occur::Req,
|
|
|
|
None,
|
|
|
|
);
|
|
|
|
args.option(
|
|
|
|
"o",
|
|
|
|
"output",
|
|
|
|
"The path to output the new config to",
|
|
|
|
"FILE",
|
|
|
|
Occur::Req,
|
|
|
|
None,
|
|
|
|
);
|
2017-06-29 09:31:27 +02:00
|
|
|
|
|
|
|
args.parse(input)?;
|
|
|
|
|
|
|
|
let help = args.value_of("help")?;
|
|
|
|
if help {
|
|
|
|
args.full_usage();
|
|
|
|
return Ok(None);
|
|
|
|
}
|
|
|
|
|
2019-08-27 15:05:51 +02:00
|
|
|
Ok(Some((args.value_of("input")?, args.value_of("output")?)))
|
2017-06-29 09:31:27 +02:00
|
|
|
}
|