src: allow users to specify custom path
This commit is contained in:
parent
1937e1f8c5
commit
433139cfb1
13
src/main.rs
13
src/main.rs
|
@ -76,9 +76,9 @@ fn read_config(path: PathBuf) -> Config {
|
|||
|
||||
fn main() {
|
||||
let options = load_yaml!("options.yaml");
|
||||
let matches = App::from(options).get_matches();
|
||||
let options = App::from(options).get_matches();
|
||||
|
||||
let config_file = match matches.value_of("config") {
|
||||
let config_file = match options.value_of("config") {
|
||||
Some(path) => PathBuf::from(path),
|
||||
None => dirs::config_dir()
|
||||
.unwrap()
|
||||
|
@ -87,9 +87,12 @@ fn main() {
|
|||
};
|
||||
let config = read_config(config_file);
|
||||
|
||||
let path = match config.as_table().unwrap().get("path") {
|
||||
Some(path) => PathBuf::from(path.as_str().unwrap()),
|
||||
None => dirs::home_dir().unwrap().join(".cosmoline"),
|
||||
let path = match options.value_of("path") {
|
||||
Some(path) => PathBuf::from(path),
|
||||
None => match config.get("path") {
|
||||
Some(path) => PathBuf::from(path.as_str().unwrap()),
|
||||
None => dirs::home_dir().unwrap().join(".cosmoline"),
|
||||
}
|
||||
};
|
||||
let keypair = Keypair::read_or_generate(path.join("secret"));
|
||||
println!("{}", keypair.to_json().pretty(2));
|
||||
|
|
|
@ -9,3 +9,9 @@ args:
|
|||
value_name: FILE
|
||||
about: Sets a custom config file
|
||||
takes_value: true
|
||||
- path:
|
||||
short: p
|
||||
long: path
|
||||
value_name: DIRECTORY
|
||||
about: Sets repository path to DIRECTORY
|
||||
takes_value: true
|
||||
|
|
Loading…
Reference in New Issue