Display legacy config file warning when 2.x config file found

This commit is contained in:
Marcin Kulik
2025-06-03 15:56:01 +02:00
parent 3f8aec164a
commit 0de3510638
2 changed files with 33 additions and 1 deletions

View File

@@ -9,6 +9,8 @@ use reqwest::Url;
use serde::Deserialize;
use uuid::Uuid;
use crate::status;
const DEFAULT_SERVER_URL: &str = "https://asciinema.org";
const INSTALL_ID_FILENAME: &str = "install-id";
@@ -202,10 +204,14 @@ fn save_install_id(path: &PathBuf, id: &str) -> Result<()> {
Ok(())
}
fn user_config_path() -> Result<PathBuf> {
pub fn user_config_path() -> Result<PathBuf> {
Ok(home()?.join("config.toml"))
}
fn legacy_user_config_path() -> Result<PathBuf> {
Ok(home()?.join("config"))
}
fn user_defaults_path() -> Result<PathBuf> {
Ok(home()?.join("defaults.toml"))
}
@@ -260,3 +266,27 @@ fn parse_key<S: AsRef<str>>(key: S) -> Result<Key> {
Err(anyhow!("invalid key definition '{key}'"))
}
pub fn check_legacy_config_file() {
let Ok(legacy_path) = legacy_user_config_path() else {
return;
};
let Ok(new_path) = user_config_path() else {
return;
};
if legacy_path.exists() {
status::warning!(
"Your config file at {} uses the location and format from asciinema 2.x.",
legacy_path.to_string_lossy()
);
status::warning!(
"For asciinema 3.x (this version) create a new config file at {}.",
new_path.to_string_lossy()
);
status::warning!("Read the documentation (CLI -> Configuration) for details.\n");
}
}

View File

@@ -37,6 +37,8 @@ fn main() -> ExitCode {
let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();
crate::config::check_legacy_config_file();
match cli.command {
Commands::Rec(cmd) => {
let cmd = Session {