show transition information when new version runs for first time
This commit is contained in:
@@ -38,10 +38,13 @@ impl Config {
|
||||
serde_yaml::from_str(&content).context("parsing yaml config")
|
||||
}
|
||||
|
||||
fn use_default_and_save_to(file: &Path) -> Result<Self> {
|
||||
let result = Self::default();
|
||||
|
||||
let content = serde_yaml::to_string(&result).context("converting Config to yaml")?;
|
||||
/// Save the instance of [`Config`] to disk.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function will return an error if the config file cannot be saved to disk.
|
||||
pub fn save(&self, file: &Path) -> Result<()> {
|
||||
let content = serde_yaml::to_string(&self).context("converting Config to yaml")?;
|
||||
|
||||
let parent = file.parent().context("getting parent of config dir")?;
|
||||
if !parent.is_dir() {
|
||||
@@ -52,7 +55,7 @@ impl Config {
|
||||
let mut output = File::create(file).context("creating default config file")?;
|
||||
write!(output, "{content}").context("writing default config")?;
|
||||
|
||||
Ok(result)
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ mod core;
|
||||
mod env;
|
||||
mod errors;
|
||||
mod grouping;
|
||||
mod path;
|
||||
pub mod path;
|
||||
mod review;
|
||||
mod search;
|
||||
mod ui;
|
||||
@@ -41,6 +41,5 @@ pub use crate::core::Pacdef;
|
||||
pub use crate::errors::Error;
|
||||
pub use crate::grouping::Group;
|
||||
pub(crate) use crate::grouping::Package;
|
||||
pub use crate::path::{get_config_path, get_group_dir};
|
||||
|
||||
extern crate pacdef_macros;
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
/*!
|
||||
All functions related to `pacdef`'s internal paths.
|
||||
*/
|
||||
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
const CONFIG_FILE_NAME: &str = "pacdef.yaml";
|
||||
const CONFIG_FILE_NAME_OLD: &str = "pacdef.conf";
|
||||
|
||||
/// Get the group directory where all group files are located. This is
|
||||
/// `$XDG_CONFIG_HOME/pacdef/groups`, which defaults to `$HOME/.config/pacdef/groups`.
|
||||
@@ -17,7 +22,7 @@ pub fn get_group_dir() -> Result<PathBuf> {
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub fn get_pacdef_base_dir() -> Result<PathBuf> {
|
||||
pub(crate) fn get_pacdef_base_dir() -> Result<PathBuf> {
|
||||
let mut dir = get_xdg_config_home().context("getting XDG_CONFIG_HOME")?;
|
||||
dir.push("pacdef");
|
||||
Ok(dir)
|
||||
@@ -33,7 +38,7 @@ fn get_xdg_config_home() -> Result<PathBuf> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_home_dir() -> Result<PathBuf> {
|
||||
pub(crate) fn get_home_dir() -> Result<PathBuf> {
|
||||
Ok(env::var("HOME").context("getting $HOME variable")?.into())
|
||||
}
|
||||
|
||||
@@ -47,3 +52,14 @@ pub fn get_config_path() -> Result<PathBuf> {
|
||||
file.push(CONFIG_FILE_NAME);
|
||||
Ok(file)
|
||||
}
|
||||
|
||||
/// Get the path to the pacdef config file. This is `$XDG_CONFIG_HOME/pacdef/pacdef.yaml`.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function returns an error if both `$XDG_CONFIG_HOME` and `$HOME` are undefined.
|
||||
pub fn get_config_path_old_version() -> Result<PathBuf> {
|
||||
let mut file = get_pacdef_base_dir().context("getting pacdef base dir for config file")?;
|
||||
file.push(CONFIG_FILE_NAME_OLD);
|
||||
Ok(file)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user