solana/src/bin/keygen.rs

36 lines
940 B
Rust
Raw Normal View History

#[macro_use]
2018-07-12 15:29:49 -07:00
extern crate clap;
use dirs;
2018-07-12 15:29:49 -07:00
use clap::{App, Arg};
use solana::wallet::gen_keypair_file;
use std::error;
fn main() -> Result<(), Box<dyn error::Error>> {
2018-07-12 16:29:10 -07:00
let matches = App::new("solana-keygen")
.version(crate_version!())
2018-07-12 15:29:49 -07:00
.arg(
Arg::with_name("outfile")
.short("o")
.long("outfile")
.value_name("PATH")
.takes_value(true)
2018-09-14 15:32:57 -07:00
.help("Path to generated file"),
)
.get_matches();
2018-07-12 15:29:49 -07:00
2018-07-12 17:16:30 -07:00
let mut path = dirs::home_dir().expect("home directory");
2018-07-12 16:04:42 -07:00
let outfile = if matches.is_present("outfile") {
matches.value_of("outfile").unwrap()
} else {
path.extend(&[".config", "solana", "id.json"]);
path.to_str().unwrap()
};
2018-07-12 15:29:49 -07:00
let serialized_keypair = gen_keypair_file(outfile.to_string())?;
2018-07-12 15:29:49 -07:00
if outfile == "-" {
println!("{}", serialized_keypair);
2018-07-12 15:29:49 -07:00
}
Ok(())
}