mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2025-01-30 20:34:49 +01:00
Add default dir for config gen, fix test
This commit is contained in:
parent
bfacbf6499
commit
a6820ce00e
1 changed files with 15 additions and 5 deletions
20
src/cli.rs
20
src/cli.rs
|
@ -210,10 +210,20 @@ fn generate_config(args: ConfigGen) -> anyhow::Result<()> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let default_dir = xdg::BaseDirectories::with_prefix("pinnacle")?.get_config_home();
|
||||||
|
|
||||||
|
let default_dir_clone = default_dir.clone();
|
||||||
|
|
||||||
let dir_validator = move |s: &String| {
|
let dir_validator = move |s: &String| {
|
||||||
let dir =
|
let mut target_dir = if s.is_empty() {
|
||||||
shellexpand::full(s).map_err(|err| format!("Directory expansion failed: {err}"))?;
|
default_dir_clone.clone()
|
||||||
let mut target_dir = PathBuf::from(dir.to_string());
|
} else {
|
||||||
|
PathBuf::from(
|
||||||
|
shellexpand::full(s)
|
||||||
|
.map_err(|err| format!("Directory expansion failed: {err}"))?
|
||||||
|
.to_string(),
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
if target_dir.is_relative() {
|
if target_dir.is_relative() {
|
||||||
let mut new_dir = std::env::current_dir().map_err(|err| {
|
let mut new_dir = std::env::current_dir().map_err(|err| {
|
||||||
|
@ -280,7 +290,7 @@ fn generate_config(args: ConfigGen) -> anyhow::Result<()> {
|
||||||
assert!(interactive);
|
assert!(interactive);
|
||||||
|
|
||||||
let dir: String = cliclack::input("Choose a directory to place the config in:")
|
let dir: String = cliclack::input("Choose a directory to place the config in:")
|
||||||
// Now this is a grade A bastardization of what this function is supposed to do
|
.default_input(default_dir.to_string_lossy().as_ref())
|
||||||
.validate_interactively(dir_validator)
|
.validate_interactively(dir_validator)
|
||||||
.interact()?;
|
.interact()?;
|
||||||
|
|
||||||
|
@ -448,7 +458,7 @@ mod tests {
|
||||||
let expected_config_gen = ConfigGen {
|
let expected_config_gen = ConfigGen {
|
||||||
lang: Some(Lang::Lua),
|
lang: Some(Lang::Lua),
|
||||||
dir: None,
|
dir: None,
|
||||||
non_interactive: false,
|
non_interactive: !std::io::stdout().is_terminal(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(CliSubcommand::Config(ConfigSubcommand::Gen(config_gen))) = cli.subcommand else {
|
let Some(CliSubcommand::Config(ConfigSubcommand::Gen(config_gen))) = cli.subcommand else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue