diff --git a/README.md b/README.md index ba1e2af..4e959a7 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ These are the clients I tried but failed to compile or run: -o --os Override the operating system [linux, osx, sunos] -u --update Update the local cache -c --clear-cache Clear the local cache - --config-path Show config directory path + --config-path Show config file path --seed-config Create a basic config Examples: @@ -135,7 +135,7 @@ Creating the config file can be done manually or with the help of tldr: $ tldr --seed-config -The command should print the location where the command created the config file. Alternatively the path can also be queried: +The configuration file path follows OS conventions. It can be queried with the following command: $ tldr --config-path diff --git a/src/config.rs b/src/config.rs index 7ad5657..bbfc2d7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,7 +9,7 @@ use xdg::BaseDirectories; use error::TealdeerError::{self, ConfigError}; -pub const SYNTAX_CONFIG_FILE_NAME: &'static str = "config.toml"; +pub const CONFIG_FILE_NAME: &'static str = "config.toml"; fn default_underline() -> bool { false @@ -161,19 +161,19 @@ fn map_io_err_to_config_err(e: IoError) -> TealdeerError { impl Config { pub fn load() -> Result { - let raw_config = match get_syntax_config_path() { - Ok(syntax_config_file_path) => { - let mut syntax_config_file = fs::File::open(syntax_config_file_path) + let raw_config = match get_config_path() { + Ok(config_file_path) => { + let mut config_file = fs::File::open(config_file_path) .map_err(map_io_err_to_config_err)?; let mut contents = String::new(); - let _rc = syntax_config_file.read_to_string(&mut contents) + let _rc = config_file.read_to_string(&mut contents) .map_err(map_io_err_to_config_err)?; - toml::from_str(&contents).map_err(|err| ConfigError(format!("Failed to parse syntax config file: {}", err)))? + toml::from_str(&contents).map_err(|err| ConfigError(format!("Failed to parse config file: {}", err)))? } Err(ConfigError(_)) => RawConfig::new(), Err(_) => { - return Err(ConfigError("Unknown error while looking up syntax config path".into())); + return Err(ConfigError("Unknown error while looking up config path".into())); } }; @@ -206,20 +206,20 @@ pub fn get_config_dir() -> Result { Ok(xdg_dirs.get_config_home()) } -/// Return the path to the syntax config file. -pub fn get_syntax_config_path() -> Result { +/// Return the path to the config file. +pub fn get_config_path() -> Result { let config_dir = get_config_dir()?; - let syntax_config_file_path = config_dir.join(SYNTAX_CONFIG_FILE_NAME); + let config_file_path = config_dir.join(CONFIG_FILE_NAME); - if syntax_config_file_path.is_file() { - Ok(syntax_config_file_path) + if config_file_path.is_file() { + Ok(config_file_path) } else { - Err(ConfigError(format!("{} is not a file path", syntax_config_file_path.to_str().unwrap()))) + Err(ConfigError(format!("{} is not a file path", config_file_path.to_str().unwrap()))) } } -/// Create default syntax config file. -pub fn make_default_syntax_config() -> Result { +/// Create default config file. +pub fn make_default_config() -> Result { let config_dir = get_config_dir()?; if !config_dir.is_dir() { if let Err(e) = fs::create_dir_all(&config_dir) { @@ -227,23 +227,23 @@ pub fn make_default_syntax_config() -> Result { } } - let syntax_config_file_path = config_dir.join(SYNTAX_CONFIG_FILE_NAME); - if syntax_config_file_path.is_file() { + let config_file_path = config_dir.join(CONFIG_FILE_NAME); + if config_file_path.is_file() { return Err(ConfigError(format!( "A configuration file already exists at {}, no action was taken.", - syntax_config_file_path.to_str().unwrap() + config_file_path.to_str().unwrap() ))); } - let serialized_syntax_config = toml::to_string(&RawConfig::new()) - .map_err(|err| ConfigError(format!("Failed to serialize default syntax config: {}", err)))?; + let serialized_config = toml::to_string(&RawConfig::new()) + .map_err(|err| ConfigError(format!("Failed to serialize default config: {}", err)))?; - let mut syntax_config_file = fs::File::create(&syntax_config_file_path) + let mut config_file = fs::File::create(&config_file_path) .map_err(map_io_err_to_config_err)?; - let _wc = syntax_config_file.write(serialized_syntax_config.as_bytes()) + let _wc = config_file.write(serialized_config.as_bytes()) .map_err(map_io_err_to_config_err)?; - Ok(syntax_config_file_path) + Ok(config_file_path) } #[test] diff --git a/src/main.rs b/src/main.rs index 748657e..9ce2d32 100644 --- a/src/main.rs +++ b/src/main.rs @@ -53,7 +53,7 @@ mod error; use tokenizer::Tokenizer; use cache::Cache; -use config::{get_config_dir, make_default_syntax_config, Config}; +use config::{get_config_path, make_default_config, Config}; use error::TealdeerError::{CacheError, ConfigError, UpdateError}; use formatter::print_lines; use types::OsType; @@ -75,7 +75,7 @@ Options: -o --os Override the operating system [linux, osx, sunos] -u --update Update the local cache -c --clear-cache Clear the local cache - --config-path Show config directory path + --config-path Show config file path --seed-config Create a basic config Examples: @@ -144,7 +144,7 @@ fn check_cache(args: &Args, cache: &Cache) { Some(ago) if ago > MAX_CACHE_AGE => { println!("{}", Color::Red.paint(format!( "Cache wasn't updated in {} days.\n\ - You should probably run `tldr --update` soon.\n", + You should probably run `tldr --update` soon.", MAX_CACHE_AGE / 24 / 3600 ))); }, @@ -275,13 +275,13 @@ fn main() { // Show config file and path and exit if args.flag_config_path { - match get_config_dir() { + match get_config_path() { Ok(config_file_path) => { - println!("Config directory path is: {}", config_file_path.to_str().unwrap()); + println!("Config path is: {}", config_file_path.to_str().unwrap()); process::exit(0); }, Err(ConfigError(msg)) => { - eprintln!("Could not look up syntax_config_path: {}", msg); + eprintln!("Could not look up config_path: {}", msg); process::exit(1); }, Err(_) => { @@ -293,9 +293,9 @@ fn main() { // Create a basic config and exit if args.flag_seed_config { - match make_default_syntax_config() { - Ok(syntax_config_file_path) => { - println!("Successfully created seed syntax config file here: {}", syntax_config_file_path.to_str().unwrap()); + match make_default_config() { + Ok(config_file_path) => { + println!("Successfully created seed config file here: {}", config_file_path.to_str().unwrap()); process::exit(0); }, Err(ConfigError(msg)) => { diff --git a/tests/lib.rs b/tests/lib.rs index 390c4fd..6c3f51b 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -74,7 +74,7 @@ fn test_setup_seed_config() { testenv.assert() .with_args(&["--seed-config"]) .succeeds() - .stdout().contains("Successfully created seed syntax config file") + .stdout().contains("Successfully created seed config file") .unwrap(); } @@ -114,13 +114,13 @@ fn test_correct_rendering_v2() { fn test_correct_rendering_with_config() { let testenv = TestEnv::new(); - // Setup syntax config file - // TODO should be config::SYNTAX_CONFIG_FILE_NAME - let syntax_file_path = testenv.config_dir.path().join("config.toml"); - println!("Syntax config path: {:?}", &syntax_file_path); + // Setup config file + // TODO should be config::CONFIG_FILE_NAME + let config_file_path = testenv.config_dir.path().join("config.toml"); + println!("Config path: {:?}", &config_file_path); - let mut syntax_config_file = File::create(&syntax_file_path).unwrap(); - syntax_config_file.write(include_str!("config.toml").as_bytes()).unwrap(); + let mut config_file = File::create(&config_file_path).unwrap(); + config_file.write(include_str!("config.toml").as_bytes()).unwrap(); // Create input file let file_path = testenv.input_dir.path().join("inkscape-v2.md");