From c3f87dde3017e98845378148acc4cd2268572a7a Mon Sep 17 00:00:00 2001 From: Ross MacArthur Date: Thu, 13 Oct 2022 12:54:08 +0200 Subject: [PATCH] Use XDG directories by default Fallback to the old directory and log a deprecation warning. --- README.md | 51 ++++------- docs/src/Command-line-interface.md | 21 ++--- docs/src/Configuration.md | 21 ++--- docs/src/Examples.md | 2 +- docs/src/Getting-started.md | 9 +- src/cli/mod.rs | 91 +++++++++++++------ src/macros.rs | 6 -- tests/helpers/dirs.rs | 4 - tests/helpers/process.rs | 8 ++ tests/lib.rs | 49 +++++++--- tests/testdata/clean/lock.stderr | 6 +- tests/testdata/clean/source.stderr | 2 +- .../clean_permission_denied/lock.stderr | 6 +- .../clean_permission_denied/source.stderr | 2 +- tests/testdata/directories/lock.stderr | 4 - tests/testdata/directories/source.stderr | 3 - .../lock.stderr | 0 .../plugins.lock | 0 .../plugins.toml | 0 .../source.stderr | 0 .../source.stdout | 0 tests/testdata/directories_old/lock.stderr | 17 ++++ tests/testdata/directories_old/plugins.lock | 23 +++++ .../plugins.toml | 0 tests/testdata/directories_old/source.stderr | 16 ++++ tests/testdata/directories_old/source.stdout | 2 + .../directories_xdg_default/plugins.lock | 23 ----- .../directories_xdg_default/source.stdout | 2 - tests/testdata/empty/lock.stderr | 4 +- tests/testdata/empty/source.stderr | 2 +- .../testdata/github_bad_reinstall/lock.stderr | 2 +- tests/testdata/github_bad_url/lock.stderr | 2 +- tests/testdata/github_bad_url/source.stderr | 2 +- tests/testdata/github_branch/lock.stderr | 4 +- tests/testdata/github_branch/source.stderr | 2 +- tests/testdata/github_https/lock.stderr | 4 +- tests/testdata/github_https/source.stderr | 2 +- tests/testdata/github_submodule/lock.stderr | 4 +- tests/testdata/github_submodule/source.stderr | 2 +- tests/testdata/github_tag/lock.stderr | 4 +- tests/testdata/github_tag/source.stderr | 2 +- tests/testdata/inline/lock.stderr | 4 +- tests/testdata/inline/source.stderr | 2 +- .../testdata/override_config_file/lock.stderr | 4 +- .../override_config_file/source.stderr | 2 +- tests/testdata/override_data_dir/lock.stderr | 2 +- tests/testdata/profiles/lock.stderr | 4 +- tests/testdata/profiles/source.stderr | 2 +- 48 files changed, 239 insertions(+), 185 deletions(-) delete mode 100644 tests/testdata/directories/lock.stderr delete mode 100644 tests/testdata/directories/source.stderr rename tests/testdata/{directories_xdg_default => directories_default}/lock.stderr (100%) rename tests/testdata/{directories => directories_default}/plugins.lock (100%) rename tests/testdata/{directories => directories_default}/plugins.toml (100%) rename tests/testdata/{directories_xdg_default => directories_default}/source.stderr (100%) rename tests/testdata/{directories => directories_default}/source.stdout (100%) create mode 100644 tests/testdata/directories_old/lock.stderr create mode 100644 tests/testdata/directories_old/plugins.lock rename tests/testdata/{directories_xdg_default => directories_old}/plugins.toml (100%) create mode 100644 tests/testdata/directories_old/source.stderr create mode 100644 tests/testdata/directories_old/source.stdout delete mode 100644 tests/testdata/directories_xdg_default/plugins.lock delete mode 100644 tests/testdata/directories_xdg_default/source.stdout diff --git a/README.md b/README.md index 16850f01..c7b3c536 100644 --- a/README.md +++ b/README.md @@ -144,16 +144,17 @@ or sheldon init --shell zsh ``` -This will create `plugins.toml` under `~/.sheldon` or, if defined, -`$XDG_CONFIG_HOME/sheldon`. You can either edit this file directly or use the -provided command line interface to add or remove plugins. +This will create `plugins.toml` under `$XDG_CONFIG_HOME/sheldon`, on most +systems this will be `~/.config/sheldon/plugins.toml`. You can either edit this +file directly or use the provided command line interface to add or remove +plugins. ### Adding a plugin To add your first plugin append the following to the Sheldon config file. ```toml -# ~/.sheldon/plugins.toml +# ~/.config/sheldon/plugins.toml [plugins.base16] github = "chriskempson/base16-shell" @@ -217,10 +218,10 @@ sheldon init --shell zsh ### `lock` -The `lock` command installs the plugins sources and generates the lock file -(`~/.sheldon/plugins.lock`). Rerunning this command without any extra options -will not reinstall plugin sources, just verify that they are correctly -installed. It will always regenerate the lock file. +The `lock` command installs the plugins sources and generates the lock file. +Rerunning this command without any extra options will not reinstall plugin +sources, just verify that they are correctly installed. It will always +regenerate the lock file. ```sh sheldon lock @@ -324,20 +325,15 @@ be required if you are using an obscure operating system. *Environment variable:* `SHELDON_CONFIG_DIR` -Set the config directory where config will store the configuration file. If -Sheldon detects an XDG directory structure ([as described -below](#xdg-directory-structure)) then this will default to -`XDG_CONFIG_HOME/sheldon` otherwise it will default to `/.sheldon` where -`` is the users home directory. +Set the config directory where the configuration file will be stored. This +defaults to `$XDG_CONFIG_HOME/sheldon` or `~/.config/sheldon`. ##### `--data-dir ` *Environment variable:* `SHELDON_DATA_DIR` -Set the data directory where plugins will be downloaded to. If Sheldon detects -an XDG directory structure ([as described below](#xdg-directory-structure)) then -this will default to `XDG_DATA_HOME/sheldon` otherwise it will default to -`/.sheldon` where `` is the users home directory. +Set the data directory where plugins will be downloaded to. This defaults to +`$XDG_DATA_HOME/sheldon` or `~/.local/share/sheldon`. ##### `--config-file ` @@ -400,7 +396,7 @@ location of the source. There are three types of sources, each kind is described in this section. A plugin may only specify *one* source type. ```toml -# ~/.sheldon/plugins.toml +# ~/.config/sheldon/plugins.toml # ┌─ Unique name for the plugin # ┌──┴─┐ @@ -588,11 +584,10 @@ plugins. #### `profiles` -A list of profiles this plugin should be used in. If this field is not given -the plugin will be used regardless of the profile. Otherwise, the plugin is -only used if the specified -[profile](https://sheldon.cli.rs/Command-line-interface.html#--profile-profile) is included in the -configured list of profiles. +A list of profiles this plugin should be used in. If this field is not given the +plugin will be used regardless of the profile. Otherwise, the plugin is only +used if the specified [profile](https://sheldon.cli.rs/Command-line-interface.html#--profile-profile) is +included in the configured list of profiles. ### Inline plugins @@ -643,10 +638,6 @@ github = "owner/repo" apply = ["PATH", "fpath"] ``` -The `each` value, as used in the `source` template above, specifies that the -template should be applied to each matched file for the plugin. This defaults to -`false`. - #### Custom templates It is possible to create your own custom templates, and you can even override @@ -664,10 +655,8 @@ Plugins all have the following information that can be used in templates. * **One or more files.** These are the matched files in the plugin directory either discovered using the the global `match` field or specified as a plugin - option with `use`. These can be used in templates using `{{ file }}`. This - information only makes sense in templates with `each` set to `true`. - -* **The Sheldon data directory.** This directory can be used as `{{ data_dir }}`. + option with `use`. These can be used in templates by iterating over the files. + For example: `{% for file in files %} ... {{ file }} ... {% endfor %}`. To add or update a template add a new key to the `[templates]` table in the config file. Take a look at the [examples](https://sheldon.cli.rs/Examples.html) for some interesting diff --git a/docs/src/Command-line-interface.md b/docs/src/Command-line-interface.md index 85cd6a0b..a6e12a22 100644 --- a/docs/src/Command-line-interface.md +++ b/docs/src/Command-line-interface.md @@ -33,10 +33,10 @@ sheldon init --shell zsh ## `lock` -The `lock` command installs the plugins sources and generates the lock file -(`~/.sheldon/plugins.lock`). Rerunning this command without any extra options -will not reinstall plugin sources, just verify that they are correctly -installed. It will always regenerate the lock file. +The `lock` command installs the plugins sources and generates the lock file. +Rerunning this command without any extra options will not reinstall plugin +sources, just verify that they are correctly installed. It will always +regenerate the lock file. ```sh sheldon lock @@ -140,20 +140,15 @@ be required if you are using an obscure operating system. *Environment variable:* `SHELDON_CONFIG_DIR` -Set the config directory where config will store the configuration file. If -Sheldon detects an XDG directory structure ([as described -below](#xdg-directory-structure)) then this will default to -`XDG_CONFIG_HOME/sheldon` otherwise it will default to `/.sheldon` where -`` is the users home directory. +Set the config directory where the configuration file will be stored. This +defaults to `$XDG_CONFIG_HOME/sheldon` or `~/.config/sheldon`. #### `--data-dir ` *Environment variable:* `SHELDON_DATA_DIR` -Set the data directory where plugins will be downloaded to. If Sheldon detects -an XDG directory structure ([as described below](#xdg-directory-structure)) then -this will default to `XDG_DATA_HOME/sheldon` otherwise it will default to -`/.sheldon` where `` is the users home directory. +Set the data directory where plugins will be downloaded to. This defaults to +`$XDG_DATA_HOME/sheldon` or `~/.local/share/sheldon`. #### `--config-file ` diff --git a/docs/src/Configuration.md b/docs/src/Configuration.md index d2b17900..77b36175 100644 --- a/docs/src/Configuration.md +++ b/docs/src/Configuration.md @@ -9,7 +9,7 @@ location of the source. There are three types of sources, each kind is described in this section. A plugin may only specify *one* source type. ```toml -# ~/.sheldon/plugins.toml +# ~/.config/sheldon/plugins.toml # ┌─ Unique name for the plugin # ┌──┴─┐ @@ -197,11 +197,10 @@ plugins. ### `profiles` -A list of profiles this plugin should be used in. If this field is not given -the plugin will be used regardless of the profile. Otherwise, the plugin is -only used if the specified -[profile](Command-line-interface.md#--profile-profile) is included in the -configured list of profiles. +A list of profiles this plugin should be used in. If this field is not given the +plugin will be used regardless of the profile. Otherwise, the plugin is only +used if the specified [profile](Command-line-interface.md#--profile-profile) is +included in the configured list of profiles. ## Inline plugins @@ -252,10 +251,6 @@ github = "owner/repo" apply = ["PATH", "fpath"] ``` -The `each` value, as used in the `source` template above, specifies that the -template should be applied to each matched file for the plugin. This defaults to -`false`. - ### Custom templates It is possible to create your own custom templates, and you can even override @@ -273,10 +268,8 @@ Plugins all have the following information that can be used in templates. * **One or more files.** These are the matched files in the plugin directory either discovered using the the global `match` field or specified as a plugin - option with `use`. These can be used in templates using `{{ file }}`. This - information only makes sense in templates with `each` set to `true`. - -* **The Sheldon data directory.** This directory can be used as `{{ data_dir }}`. + option with `use`. These can be used in templates by iterating over the files. + For example: `{% for file in files %} ... {{ file }} ... {% endfor %}`. To add or update a template add a new key to the `[templates]` table in the config file. Take a look at the [examples](Examples.md) for some interesting diff --git a/docs/src/Examples.md b/docs/src/Examples.md index a6118190..2001eba1 100644 --- a/docs/src/Examples.md +++ b/docs/src/Examples.md @@ -82,7 +82,7 @@ Add the following to your `~/.zshrc` file. ```sh # ~/.zshrc -export ZSH="$HOME/.sheldon/repos/github.com/ohmyzsh/ohmyzsh" +export ZSH="$HOME/.local/share/sheldon/repos/github.com/ohmyzsh/ohmyzsh" # Oh My Zsh settings here diff --git a/docs/src/Getting-started.md b/docs/src/Getting-started.md index d4374c6e..6d792e0e 100644 --- a/docs/src/Getting-started.md +++ b/docs/src/Getting-started.md @@ -16,16 +16,17 @@ or sheldon init --shell zsh ``` -This will create `plugins.toml` under `~/.sheldon` or, if defined, -`$XDG_CONFIG_HOME/sheldon`. You can either edit this file directly or use the -provided command line interface to add or remove plugins. +This will create `plugins.toml` under `$XDG_CONFIG_HOME/sheldon`, on most +systems this will be `~/.config/sheldon/plugins.toml`. You can either edit this +file directly or use the provided command line interface to add or remove +plugins. ## Adding a plugin To add your first plugin append the following to the Sheldon config file. ```toml -# ~/.sheldon/plugins.toml +# ~/.config/sheldon/plugins.toml [plugins.base16] github = "chriskempson/base16-shell" diff --git a/src/cli/mod.rs b/src/cli/mod.rs index c8567bc0..b78092eb 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -8,7 +8,7 @@ mod tests; use std::env; use std::io; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::process; use anyhow::anyhow; @@ -135,35 +135,7 @@ impl Opt { } }; - let xdg_config_user = env::var_os("XDG_CONFIG_HOME").map(PathBuf::from); - let xdg_data_user = env::var_os("XDG_DATA_HOME").map(PathBuf::from); - - // Note: `XDG_RUNTIME_DIR` is not checked as it can be set by the system rather - // than the user, and cannot be relied upon to indicate a preference for XDG - // directory layout. - let using_xdg = any!( - xdg_data_user, - xdg_config_user, - env::var_os("XDG_CACHE_HOME"), - env::var_os("XDG_DATA_DIRS"), - env::var_os("XDG_CONFIG_DIRS") - ); - - let (config_pre, data_pre) = if using_xdg { - ( - xdg_config_user - .unwrap_or_else(|| home.join(".config")) - .join("sheldon"), - xdg_data_user - .unwrap_or_else(|| home.join(".local/share")) - .join("sheldon"), - ) - } else { - (home.join(".sheldon"), home.join(".sheldon")) - }; - - let config_dir = config_dir.unwrap_or(config_pre); - let data_dir = data_dir.unwrap_or(data_pre); + let (config_dir, data_dir) = resolve_dirs(&home, config_dir, data_dir, output.no_color); let config_file = config_file.unwrap_or_else(|| config_dir.join("plugins.toml")); let lock_file = match profile.as_deref() { Some("") | None => data_dir.join("plugins.lock"), @@ -260,3 +232,62 @@ impl LockMode { } } } + +fn resolve_dirs( + home: &Path, + config_dir: Option, + data_dir: Option, + no_color: bool, +) -> (PathBuf, PathBuf) { + // TODO: Remove this warning in a later release and stop falling back to + // the old directory. + let err = anyhow!( + r#"using deprecated config file location ~/.sheldon/plugins.toml. + +To use the new location move the config file to +~/.config/sheldon/plugins.toml ($XDG_CONFIG_HOME/sheldon/plugins.toml), +~/.sheldon can then be safely deleted. + +Or to instead preserve the old behaviour set the following environment variables: + SHELDON_CONFIG_DIR="$HOME/.sheldon" + SHELDON_DATA_DIR="$HOME/.sheldon" + +See the release notes at https://github.com/rossmacarthur/sheldon for more information. +"#, + ); + let mut using_old = false; + let config_dir = config_dir.unwrap_or_else(|| { + let default = default_config_dir(home); + let old = home.join(".sheldon"); + if old.exists() && !default.exists() { + log_error(no_color, Color::Yellow, "warning", &err); + using_old = true; + return old; + } + default + }); + let data_dir = data_dir.unwrap_or_else(|| { + let default = default_data_dir(home); + if using_old && !default.exists() { + return config_dir.clone(); + } + default + }); + (config_dir, data_dir) +} + +fn default_config_dir(home: &Path) -> PathBuf { + let mut p = env::var_os("XDG_CONFIG_HOME") + .map(PathBuf::from) + .unwrap_or_else(|| home.join(".config")); + p.push("sheldon"); + p +} + +fn default_data_dir(home: &Path) -> PathBuf { + let mut p = env::var_os("XDG_DATA_HOME") + .map(PathBuf::from) + .unwrap_or_else(|| home.join(".local/share")); + p.push("sheldon"); + p +} diff --git a/src/macros.rs b/src/macros.rs index 262f61f5..aa7e6b49 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -5,12 +5,6 @@ macro_rules! s { ($fmt:expr, $($arg:tt)+) => (|| format!($fmt, $($arg)+)) } -/// Evaluates a sequence of Options to see if any is a `Some`. -macro_rules! any { - ($opt:expr) => { $opt.is_some() }; - ($opt:expr, $($rest:expr),+) => { $opt.is_some() || { any!($($rest),+) }}; -} - /// Call .into() on each element in a vec! initialization. macro_rules! vec_into { ($($i:expr),*) => (vec![$($i.into()),*]); diff --git a/tests/helpers/dirs.rs b/tests/helpers/dirs.rs index 9f5dcf7a..f0aa6512 100644 --- a/tests/helpers/dirs.rs +++ b/tests/helpers/dirs.rs @@ -22,10 +22,6 @@ impl TestDirs { } pub fn default() -> io::Result { - Self::new(".sheldon", ".sheldon") - } - - pub fn default_xdg() -> io::Result { Self::new(".config/sheldon", ".local/share/sheldon") } diff --git a/tests/helpers/process.rs b/tests/helpers/process.rs index 030cb21e..2c7ca55e 100644 --- a/tests/helpers/process.rs +++ b/tests/helpers/process.rs @@ -88,6 +88,14 @@ impl TestCommand { self } + pub fn env_remove(mut self, key: K) -> Self + where + K: AsRef, + { + self.command.env_remove(key); + self + } + pub fn envs(mut self, vars: I) -> Self where I: IntoIterator, diff --git a/tests/lib.rs b/tests/lib.rs index a7eeeaff..a4fd280f 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -83,6 +83,10 @@ impl TestCase { fs::write(self.dirs.config.join(name), self.get(name)) } + fn write_file(&self, path: &Path, name: &str) -> io::Result<()> { + fs::write(path, self.get(name)) + } + fn assert_contents(&self, name: &str) -> io::Result<()> { self.assert_contents_path(name, &self.dirs.data.join(name)) } @@ -386,24 +390,33 @@ fn lock_and_source_profiles() -> io::Result<()> { } #[test] -fn directories_default() -> io::Result<()> { - let case = TestCase::load("directories")?; - case.run()?; - case.dirs.assert_conforms(); - assert_eq!(&case.dirs.data, &case.dirs.config); +fn directories_old() -> io::Result<()> { + let case = TestCase::load("directories_old")?; + let config_dir = case.dirs.home.path().join(".sheldon"); + fs::remove_dir(&case.dirs.data).ok(); + fs::remove_dir(&case.dirs.config).ok(); + fs::create_dir_all(&config_dir)?; + case.write_file(&config_dir.join("plugins.toml"), "plugins.toml")?; + case.command("lock") + .env_remove("SHELDON_CONFIG_DIR") + .env_remove("SHELDON_DATA_DIR") + .run()?; + case.assert_contents_path("plugins.lock", &config_dir.join("plugins.lock"))?; + case.command("source") + .env_remove("SHELDON_CONFIG_DIR") + .env_remove("SHELDON_DATA_DIR") + .run()?; Ok(()) } #[test] -fn directories_xdg_default() -> io::Result<()> { - let dirs = TestDirs::default_xdg()?; - let case = TestCase::load_with_dirs("directories_xdg_default", dirs)?; - let xdg_cache = case.dirs.home.path().join(".cache"); - let envs = [("XDG_CACHE_HOME", &xdg_cache)]; +fn directories_default() -> io::Result<()> { + let dirs = TestDirs::default()?; + let case = TestCase::load_with_dirs("directories_default", dirs)?; case.write_config_file("plugins.toml")?; - case.command("lock").envs(envs).run()?; + case.command("lock").run()?; case.assert_contents("plugins.lock")?; - case.command("source").envs(envs).run()?; + case.command("source").run()?; case.dirs.assert_conforms(); Ok(()) } @@ -419,9 +432,17 @@ fn directories_xdg_from_env() -> io::Result<()> { ("XDG_DATA_HOME", &xdg_data), ]; case.write_config_file("plugins.toml")?; - case.command("lock").envs(envs).run()?; + case.command("lock") + .env_remove("SHELDON_CONFIG_DIR") + .env_remove("SHELDON_DATA_DIR") + .envs(envs) + .run()?; case.assert_contents("plugins.lock")?; - case.command("source").envs(envs).run()?; + case.command("source") + .env_remove("SHELDON_CONFIG_DIR") + .env_remove("SHELDON_DATA_DIR") + .envs(envs) + .run()?; case.dirs.assert_conforms(); Ok(()) } diff --git a/tests/testdata/clean/lock.stderr b/tests/testdata/clean/lock.stderr index 21d1792d..62092a82 100644 --- a/tests/testdata/clean/lock.stderr +++ b/tests/testdata/clean/lock.stderr @@ -1,3 +1,3 @@ -[LOADED] ~/.sheldon/plugins.toml - [REMOVED] ~/.sheldon/repos/test.com -[LOCKED] ~/.sheldon/plugins.lock +[LOADED] ~/.config/sheldon/plugins.toml + [REMOVED] ~/.local/share/sheldon/repos/test.com +[LOCKED] ~/.local/share/sheldon/plugins.lock diff --git a/tests/testdata/clean/source.stderr b/tests/testdata/clean/source.stderr index 2f3b14d3..14b0e381 100644 --- a/tests/testdata/clean/source.stderr +++ b/tests/testdata/clean/source.stderr @@ -1 +1 @@ -[UNLOCKED] ~/.sheldon/plugins.lock +[UNLOCKED] ~/.local/share/sheldon/plugins.lock diff --git a/tests/testdata/clean_permission_denied/lock.stderr b/tests/testdata/clean_permission_denied/lock.stderr index 0f1203a2..c46ccb3f 100644 --- a/tests/testdata/clean_permission_denied/lock.stderr +++ b/tests/testdata/clean_permission_denied/lock.stderr @@ -1,5 +1,5 @@ -[LOADED] ~/.sheldon/plugins.toml -[LOCKED] ~/.sheldon/plugins.lock +[LOADED] ~/.config/sheldon/plugins.toml +[LOCKED] ~/.local/share/sheldon/plugins.lock -[WARNING] failed to remove directory `~/.sheldon/repos/test.com` +[WARNING] failed to remove directory `~/.local/share/sheldon/repos/test.com` due to: Permission denied (os error 13) diff --git a/tests/testdata/clean_permission_denied/source.stderr b/tests/testdata/clean_permission_denied/source.stderr index 2f3b14d3..14b0e381 100644 --- a/tests/testdata/clean_permission_denied/source.stderr +++ b/tests/testdata/clean_permission_denied/source.stderr @@ -1 +1 @@ -[UNLOCKED] ~/.sheldon/plugins.lock +[UNLOCKED] ~/.local/share/sheldon/plugins.lock diff --git a/tests/testdata/directories/lock.stderr b/tests/testdata/directories/lock.stderr deleted file mode 100644 index 466e3a31..00000000 --- a/tests/testdata/directories/lock.stderr +++ /dev/null @@ -1,4 +0,0 @@ -[LOADED] ~/.sheldon/plugins.toml - [FETCHED] https://raw.githubusercontent.com/rossmacarthur/sheldon-test/master/test.plugin.zsh - [CLONED] https://github.com/rossmacarthur/sheldon-test -[LOCKED] ~/.sheldon/plugins.lock diff --git a/tests/testdata/directories/source.stderr b/tests/testdata/directories/source.stderr deleted file mode 100644 index 676e1c00..00000000 --- a/tests/testdata/directories/source.stderr +++ /dev/null @@ -1,3 +0,0 @@ -[UNLOCKED] ~/.sheldon/plugins.lock - [RENDERED] testa - [RENDERED] testb diff --git a/tests/testdata/directories_xdg_default/lock.stderr b/tests/testdata/directories_default/lock.stderr similarity index 100% rename from tests/testdata/directories_xdg_default/lock.stderr rename to tests/testdata/directories_default/lock.stderr diff --git a/tests/testdata/directories/plugins.lock b/tests/testdata/directories_default/plugins.lock similarity index 100% rename from tests/testdata/directories/plugins.lock rename to tests/testdata/directories_default/plugins.lock diff --git a/tests/testdata/directories/plugins.toml b/tests/testdata/directories_default/plugins.toml similarity index 100% rename from tests/testdata/directories/plugins.toml rename to tests/testdata/directories_default/plugins.toml diff --git a/tests/testdata/directories_xdg_default/source.stderr b/tests/testdata/directories_default/source.stderr similarity index 100% rename from tests/testdata/directories_xdg_default/source.stderr rename to tests/testdata/directories_default/source.stderr diff --git a/tests/testdata/directories/source.stdout b/tests/testdata/directories_default/source.stdout similarity index 100% rename from tests/testdata/directories/source.stdout rename to tests/testdata/directories_default/source.stdout diff --git a/tests/testdata/directories_old/lock.stderr b/tests/testdata/directories_old/lock.stderr new file mode 100644 index 00000000..00383e2a --- /dev/null +++ b/tests/testdata/directories_old/lock.stderr @@ -0,0 +1,17 @@ + +[WARNING] using deprecated config file location ~/.sheldon/plugins.toml. + +To use the new location move the config file to +~/.config/sheldon/plugins.toml ($XDG_CONFIG_HOME/sheldon/plugins.toml), +~/.sheldon can then be safely deleted. + +Or to instead preserve the old behaviour set the following environment variables: + SHELDON_CONFIG_DIR="$HOME/.sheldon" + SHELDON_DATA_DIR="$HOME/.sheldon" + +See the release notes at https://github.com/rossmacarthur/sheldon for more information. + +[LOADED] ~/.sheldon/plugins.toml + [FETCHED] https://raw.githubusercontent.com/rossmacarthur/sheldon-test/master/test.plugin.zsh + [CLONED] https://github.com/rossmacarthur/sheldon-test +[LOCKED] ~/.sheldon/plugins.lock diff --git a/tests/testdata/directories_old/plugins.lock b/tests/testdata/directories_old/plugins.lock new file mode 100644 index 00000000..7c22f396 --- /dev/null +++ b/tests/testdata/directories_old/plugins.lock @@ -0,0 +1,23 @@ +version = "" +home = "" +config_dir = "/.sheldon" +data_dir = "/.sheldon" +config_file = "/.sheldon/plugins.toml" + +[[plugins]] +name = "testa" +source_dir = "/.sheldon/downloads/raw.githubusercontent.com/rossmacarthur/sheldon-test/master" +files = ["/.sheldon/downloads/raw.githubusercontent.com/rossmacarthur/sheldon-test/master/test.plugin.zsh"] +apply = ["source"] + +[[plugins]] +name = "testb" +source_dir = "/.sheldon/repos/github.com/rossmacarthur/sheldon-test" +files = ["/.sheldon/repos/github.com/rossmacarthur/sheldon-test/test.plugin.zsh"] +apply = ["source"] + +[templates] +PATH = "export PATH=\"{{ dir }}:$PATH\"" +path = "path=( \"{{ dir }}\" $path )" +fpath = "fpath=( \"{{ dir }}\" $fpath )" +source = "{% for file in files %}source \"{{ file }}\"\n{% endfor %}" diff --git a/tests/testdata/directories_xdg_default/plugins.toml b/tests/testdata/directories_old/plugins.toml similarity index 100% rename from tests/testdata/directories_xdg_default/plugins.toml rename to tests/testdata/directories_old/plugins.toml diff --git a/tests/testdata/directories_old/source.stderr b/tests/testdata/directories_old/source.stderr new file mode 100644 index 00000000..506730f7 --- /dev/null +++ b/tests/testdata/directories_old/source.stderr @@ -0,0 +1,16 @@ + +[WARNING] using deprecated config file location ~/.sheldon/plugins.toml. + +To use the new location move the config file to +~/.config/sheldon/plugins.toml ($XDG_CONFIG_HOME/sheldon/plugins.toml), +~/.sheldon can then be safely deleted. + +Or to instead preserve the old behaviour set the following environment variables: + SHELDON_CONFIG_DIR="$HOME/.sheldon" + SHELDON_DATA_DIR="$HOME/.sheldon" + +See the release notes at https://github.com/rossmacarthur/sheldon for more information. + +[UNLOCKED] ~/.sheldon/plugins.lock + [RENDERED] testa + [RENDERED] testb diff --git a/tests/testdata/directories_old/source.stdout b/tests/testdata/directories_old/source.stdout new file mode 100644 index 00000000..7c320a7f --- /dev/null +++ b/tests/testdata/directories_old/source.stdout @@ -0,0 +1,2 @@ +source "/.sheldon/downloads/raw.githubusercontent.com/rossmacarthur/sheldon-test/master/test.plugin.zsh" +source "/.sheldon/repos/github.com/rossmacarthur/sheldon-test/test.plugin.zsh" diff --git a/tests/testdata/directories_xdg_default/plugins.lock b/tests/testdata/directories_xdg_default/plugins.lock deleted file mode 100644 index e0b6bc36..00000000 --- a/tests/testdata/directories_xdg_default/plugins.lock +++ /dev/null @@ -1,23 +0,0 @@ -version = "" -home = "" -config_dir = "" -data_dir = "" -config_file = "/plugins.toml" - -[[plugins]] -name = "testa" -source_dir = "/downloads/raw.githubusercontent.com/rossmacarthur/sheldon-test/master" -files = ["/downloads/raw.githubusercontent.com/rossmacarthur/sheldon-test/master/test.plugin.zsh"] -apply = ["source"] - -[[plugins]] -name = "testb" -source_dir = "/repos/github.com/rossmacarthur/sheldon-test" -files = ["/repos/github.com/rossmacarthur/sheldon-test/test.plugin.zsh"] -apply = ["source"] - -[templates] -PATH = "export PATH=\"{{ dir }}:$PATH\"" -path = "path=( \"{{ dir }}\" $path )" -fpath = "fpath=( \"{{ dir }}\" $fpath )" -source = "{% for file in files %}source \"{{ file }}\"\n{% endfor %}" diff --git a/tests/testdata/directories_xdg_default/source.stdout b/tests/testdata/directories_xdg_default/source.stdout deleted file mode 100644 index e135a643..00000000 --- a/tests/testdata/directories_xdg_default/source.stdout +++ /dev/null @@ -1,2 +0,0 @@ -source "/downloads/raw.githubusercontent.com/rossmacarthur/sheldon-test/master/test.plugin.zsh" -source "/repos/github.com/rossmacarthur/sheldon-test/test.plugin.zsh" diff --git a/tests/testdata/empty/lock.stderr b/tests/testdata/empty/lock.stderr index f0c3f6df..481191e8 100644 --- a/tests/testdata/empty/lock.stderr +++ b/tests/testdata/empty/lock.stderr @@ -1,2 +1,2 @@ -[LOADED] ~/.sheldon/plugins.toml -[LOCKED] ~/.sheldon/plugins.lock +[LOADED] ~/.config/sheldon/plugins.toml +[LOCKED] ~/.local/share/sheldon/plugins.lock diff --git a/tests/testdata/empty/source.stderr b/tests/testdata/empty/source.stderr index 2f3b14d3..14b0e381 100644 --- a/tests/testdata/empty/source.stderr +++ b/tests/testdata/empty/source.stderr @@ -1 +1 @@ -[UNLOCKED] ~/.sheldon/plugins.lock +[UNLOCKED] ~/.local/share/sheldon/plugins.lock diff --git a/tests/testdata/github_bad_reinstall/lock.stderr b/tests/testdata/github_bad_reinstall/lock.stderr index 8b0d52d1..ecbb2ccc 100644 --- a/tests/testdata/github_bad_reinstall/lock.stderr +++ b/tests/testdata/github_bad_reinstall/lock.stderr @@ -1,4 +1,4 @@ -[LOADED] ~/.sheldon/plugins.toml +[LOADED] ~/.config/sheldon/plugins.toml [ERROR] failed to install source `https://github.com/rossmacarthur/sheldon-test@bad-tag` due to: failed to find tag `bad-tag` diff --git a/tests/testdata/github_bad_url/lock.stderr b/tests/testdata/github_bad_url/lock.stderr index 6a771861..d1900bd5 100644 --- a/tests/testdata/github_bad_url/lock.stderr +++ b/tests/testdata/github_bad_url/lock.stderr @@ -1,4 +1,4 @@ -[LOADED] ~/.sheldon/plugins.toml +[LOADED] ~/.config/sheldon/plugins.toml [CLONED] https://github.com/rossmacarthur/sheldon-test [ERROR] failed to install source `https://github.com/rossmacarthur/sheldon-bad-url` diff --git a/tests/testdata/github_bad_url/source.stderr b/tests/testdata/github_bad_url/source.stderr index 1b08f5b9..23eac295 100644 --- a/tests/testdata/github_bad_url/source.stderr +++ b/tests/testdata/github_bad_url/source.stderr @@ -1,4 +1,4 @@ -[LOADED] ~/.sheldon/plugins.toml +[LOADED] ~/.config/sheldon/plugins.toml [CHECKED] https://github.com/rossmacarthur/sheldon-test [RENDERED] test diff --git a/tests/testdata/github_branch/lock.stderr b/tests/testdata/github_branch/lock.stderr index 8cdcd761..bc29b651 100644 --- a/tests/testdata/github_branch/lock.stderr +++ b/tests/testdata/github_branch/lock.stderr @@ -1,3 +1,3 @@ -[LOADED] ~/.sheldon/plugins.toml +[LOADED] ~/.config/sheldon/plugins.toml [CLONED] https://github.com/rossmacarthur/sheldon-test@feature -[LOCKED] ~/.sheldon/plugins.lock +[LOCKED] ~/.local/share/sheldon/plugins.lock diff --git a/tests/testdata/github_branch/source.stderr b/tests/testdata/github_branch/source.stderr index 773d9cfa..8ed4b1c9 100644 --- a/tests/testdata/github_branch/source.stderr +++ b/tests/testdata/github_branch/source.stderr @@ -1,2 +1,2 @@ -[UNLOCKED] ~/.sheldon/plugins.lock +[UNLOCKED] ~/.local/share/sheldon/plugins.lock [RENDERED] test diff --git a/tests/testdata/github_https/lock.stderr b/tests/testdata/github_https/lock.stderr index 0baef708..fb1d2b9b 100644 --- a/tests/testdata/github_https/lock.stderr +++ b/tests/testdata/github_https/lock.stderr @@ -1,3 +1,3 @@ -[LOADED] ~/.sheldon/plugins.toml +[LOADED] ~/.config/sheldon/plugins.toml [CLONED] https://github.com/rossmacarthur/sheldon-test -[LOCKED] ~/.sheldon/plugins.lock +[LOCKED] ~/.local/share/sheldon/plugins.lock diff --git a/tests/testdata/github_https/source.stderr b/tests/testdata/github_https/source.stderr index 773d9cfa..8ed4b1c9 100644 --- a/tests/testdata/github_https/source.stderr +++ b/tests/testdata/github_https/source.stderr @@ -1,2 +1,2 @@ -[UNLOCKED] ~/.sheldon/plugins.lock +[UNLOCKED] ~/.local/share/sheldon/plugins.lock [RENDERED] test diff --git a/tests/testdata/github_submodule/lock.stderr b/tests/testdata/github_submodule/lock.stderr index b37578f6..2dc92ccf 100644 --- a/tests/testdata/github_submodule/lock.stderr +++ b/tests/testdata/github_submodule/lock.stderr @@ -1,3 +1,3 @@ -[LOADED] ~/.sheldon/plugins.toml +[LOADED] ~/.config/sheldon/plugins.toml [CLONED] https://github.com/rossmacarthur/sheldon-test@recursive-recursive -[LOCKED] ~/.sheldon/plugins.lock +[LOCKED] ~/.local/share/sheldon/plugins.lock diff --git a/tests/testdata/github_submodule/source.stderr b/tests/testdata/github_submodule/source.stderr index 773d9cfa..8ed4b1c9 100644 --- a/tests/testdata/github_submodule/source.stderr +++ b/tests/testdata/github_submodule/source.stderr @@ -1,2 +1,2 @@ -[UNLOCKED] ~/.sheldon/plugins.lock +[UNLOCKED] ~/.local/share/sheldon/plugins.lock [RENDERED] test diff --git a/tests/testdata/github_tag/lock.stderr b/tests/testdata/github_tag/lock.stderr index 8fda426d..f05ff7fd 100644 --- a/tests/testdata/github_tag/lock.stderr +++ b/tests/testdata/github_tag/lock.stderr @@ -1,3 +1,3 @@ -[LOADED] ~/.sheldon/plugins.toml +[LOADED] ~/.config/sheldon/plugins.toml [CLONED] https://github.com/rossmacarthur/sheldon-test@v0.1.0 -[LOCKED] ~/.sheldon/plugins.lock +[LOCKED] ~/.local/share/sheldon/plugins.lock diff --git a/tests/testdata/github_tag/source.stderr b/tests/testdata/github_tag/source.stderr index 773d9cfa..8ed4b1c9 100644 --- a/tests/testdata/github_tag/source.stderr +++ b/tests/testdata/github_tag/source.stderr @@ -1,2 +1,2 @@ -[UNLOCKED] ~/.sheldon/plugins.lock +[UNLOCKED] ~/.local/share/sheldon/plugins.lock [RENDERED] test diff --git a/tests/testdata/inline/lock.stderr b/tests/testdata/inline/lock.stderr index 0baef708..fb1d2b9b 100644 --- a/tests/testdata/inline/lock.stderr +++ b/tests/testdata/inline/lock.stderr @@ -1,3 +1,3 @@ -[LOADED] ~/.sheldon/plugins.toml +[LOADED] ~/.config/sheldon/plugins.toml [CLONED] https://github.com/rossmacarthur/sheldon-test -[LOCKED] ~/.sheldon/plugins.lock +[LOCKED] ~/.local/share/sheldon/plugins.lock diff --git a/tests/testdata/inline/source.stderr b/tests/testdata/inline/source.stderr index 4aae5a7d..062cba1a 100644 --- a/tests/testdata/inline/source.stderr +++ b/tests/testdata/inline/source.stderr @@ -1,3 +1,3 @@ -[UNLOCKED] ~/.sheldon/plugins.lock +[UNLOCKED] ~/.local/share/sheldon/plugins.lock [RENDERED] test [INLINED] inline-test diff --git a/tests/testdata/override_config_file/lock.stderr b/tests/testdata/override_config_file/lock.stderr index 166c2ab4..ba91de3f 100644 --- a/tests/testdata/override_config_file/lock.stderr +++ b/tests/testdata/override_config_file/lock.stderr @@ -1,2 +1,2 @@ -[LOADED] ~/.sheldon/test.toml -[LOCKED] ~/.sheldon/plugins.lock +[LOADED] ~/.config/sheldon/test.toml +[LOCKED] ~/.local/share/sheldon/plugins.lock diff --git a/tests/testdata/override_config_file/source.stderr b/tests/testdata/override_config_file/source.stderr index 2f3b14d3..14b0e381 100644 --- a/tests/testdata/override_config_file/source.stderr +++ b/tests/testdata/override_config_file/source.stderr @@ -1 +1 @@ -[UNLOCKED] ~/.sheldon/plugins.lock +[UNLOCKED] ~/.local/share/sheldon/plugins.lock diff --git a/tests/testdata/override_data_dir/lock.stderr b/tests/testdata/override_data_dir/lock.stderr index 4a00108d..4f674e7e 100644 --- a/tests/testdata/override_data_dir/lock.stderr +++ b/tests/testdata/override_data_dir/lock.stderr @@ -1,2 +1,2 @@ -[LOADED] ~/.sheldon/plugins.toml +[LOADED] ~/.config/sheldon/plugins.toml [LOCKED] ~/test/plugins.lock diff --git a/tests/testdata/profiles/lock.stderr b/tests/testdata/profiles/lock.stderr index e1859f99..defa2ab3 100644 --- a/tests/testdata/profiles/lock.stderr +++ b/tests/testdata/profiles/lock.stderr @@ -1,4 +1,4 @@ -[LOADED] ~/.sheldon/plugins.toml +[LOADED] ~/.config/sheldon/plugins.toml [SKIPPED] https://github.com/rossmacarthur/sheldon-test2 [CLONED] https://github.com/rossmacarthur/sheldon-test -[LOCKED] ~/.sheldon/plugins.p1.lock +[LOCKED] ~/.local/share/sheldon/plugins.p1.lock diff --git a/tests/testdata/profiles/source.stderr b/tests/testdata/profiles/source.stderr index dc64b513..d6a575e4 100644 --- a/tests/testdata/profiles/source.stderr +++ b/tests/testdata/profiles/source.stderr @@ -1,3 +1,3 @@ -[UNLOCKED] ~/.sheldon/plugins.p1.lock +[UNLOCKED] ~/.local/share/sheldon/plugins.p1.lock [RENDERED] test [INLINED] inline-test