fix home directory path

This commit is contained in:
LordMZTE 2021-10-10 20:44:12 +02:00
parent 2bd3d8c266
commit 05052031e3
3 changed files with 25 additions and 9 deletions

View file

@ -7,6 +7,7 @@ edition = "2018"
[dependencies] [dependencies]
clap = { version = "3.0.0-beta.4", features = ["derive"] } clap = { version = "3.0.0-beta.4", features = ["derive"] }
home = "0.5.3"
miette = { version = "3.2.0", features = ["fancy"] } miette = { version = "3.2.0", features = ["fancy"] }
owo-colors = "2.1.0" owo-colors = "2.1.0"
serde = { version = "1.0.130", features = ["derive"] } serde = { version = "1.0.130", features = ["derive"] }

View file

@ -56,12 +56,12 @@ impl CfgCommand {
let mut cmd = Command::new(args.first().ok_or(IntoCommandError::EmptyArgs)?); let mut cmd = Command::new(args.first().ok_or(IntoCommandError::EmptyArgs)?);
cmd.args(&args[1..]); cmd.args(&args[1..]);
Ok(cmd) Ok(cmd)
} },
Self::Shell(shell_cmd) => { Self::Shell(shell_cmd) => {
let mut cmd = Command::new(shell.first().ok_or(IntoCommandError::EmptyShell)?); let mut cmd = Command::new(shell.first().ok_or(IntoCommandError::EmptyShell)?);
cmd.args(&shell[1..]).arg(shell_cmd); cmd.args(&shell[1..]).arg(shell_cmd);
Ok(cmd) Ok(cmd)
} },
} }
} }
} }

View file

@ -1,9 +1,8 @@
use clap::Clap; use clap::Clap;
use config::CfgCommand; use config::CfgCommand;
use miette::{Context, IntoDiagnostic}; use miette::{miette, Context, IntoDiagnostic};
use owo_colors::OwoColorize; use owo_colors::OwoColorize;
use std::fs::File; use std::{fs::File, io::Read, path::PathBuf};
use std::{io::Read, path::PathBuf};
use crate::config::Config; use crate::config::Config;
@ -11,17 +10,33 @@ pub mod config;
#[derive(Clap)] #[derive(Clap)]
struct Opt { struct Opt {
#[clap(long, short)] #[clap(
long,
short,
about = "Don't run interactive steps, unless they have unint_alt set"
)]
uninteractive: bool, uninteractive: bool,
#[clap(long, short, default_value = "~/.config/upgr/config.toml")] #[clap(
config: PathBuf, long,
short,
about = "The config file to use. Defaults to ~/.config/upgr/config.toml"
)]
config: Option<PathBuf>,
} }
fn main() -> miette::Result<()> { fn main() -> miette::Result<()> {
let opt = Opt::parse(); let opt = Opt::parse();
let mut file = File::open(opt.config) let cfg_path = if let Some(path) = opt.config {
path
} else {
home::home_dir()
.ok_or_else(|| miette!("Couldn't get home directory"))?
.join(".config/upgr/config.toml")
};
let mut file = File::open(cfg_path)
.into_diagnostic() .into_diagnostic()
.wrap_err("Couldn't open config")?; .wrap_err("Couldn't open config")?;