-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Not sure why I made it an option in the first place. A subcommand works better for this, and keeps the interface consistent with the other commands.
- Loading branch information
1 parent
644d008
commit 7eba80c
Showing
3 changed files
with
70 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ pub mod known; | |
pub mod list; | ||
pub mod main; | ||
pub mod run; | ||
pub mod show; | ||
pub mod uninstall; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use crate::config::{ | ||
bin_directory, cache_directory, config_directory, data_directory, | ||
downloads_directory, install_directory, | ||
}; | ||
use crate::error::Error; | ||
use getopts::Options; | ||
|
||
const USAGE: &str = "ivm show [OPTIONS] [SETTING] | ||
Prints the value of a setting. | ||
Available settings: | ||
data The data directory | ||
bin The directory for symbolic links to executables | ||
cache The directory for storing temporary data | ||
install The directory containing all installed versions | ||
config The directory containing configuration files | ||
downloads The directory containing downloaded files"; | ||
|
||
pub fn run(arguments: &[String]) -> Result<(), Error> { | ||
let mut options = Options::new(); | ||
|
||
options.optflag("h", "help", "Shows this help message"); | ||
|
||
let matches = options.parse(arguments)?; | ||
|
||
if matches.opt_present("h") { | ||
usage!(&options, USAGE); | ||
return Ok(()); | ||
} | ||
|
||
match matches.free.get(0).map(|s| s.as_str()) { | ||
Some("data") => { | ||
println!("{}", data_directory()?.to_string_lossy()); | ||
} | ||
Some("bin") => { | ||
println!("{}", bin_directory()?.to_string_lossy()); | ||
} | ||
Some("cache") => { | ||
println!("{}", cache_directory()?.to_string_lossy()); | ||
} | ||
Some("install") => { | ||
println!("{}", install_directory()?.to_string_lossy()); | ||
} | ||
Some("config") => { | ||
println!("{}", config_directory()?.to_string_lossy()); | ||
} | ||
Some("downloads") => { | ||
println!("{}", downloads_directory()?.to_string_lossy()); | ||
} | ||
Some(setting) => { | ||
return Err(Error::generic(format!( | ||
"The setting {} doesn't exist", | ||
setting | ||
))); | ||
} | ||
_ => { | ||
return Err(Error::generic("You must specify a setting name")); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |