mirror of
https://github.com/nushell/nushell.git
synced 2025-05-01 16:44:27 +02:00
Use the directories crate instead of app_dirs (#1782)
The app_dirs crate is abandonned since quite a bit of time. Use the directories crate instead, which is maintained and have more OS support.
This commit is contained in:
parent
f78536333a
commit
5fbe5cf785
54
Cargo.lock
generated
54
Cargo.lock
generated
@ -33,18 +33,6 @@ dependencies = [
|
|||||||
"winapi 0.3.8",
|
"winapi 0.3.8",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "app_dirs"
|
|
||||||
version = "1.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e73a24bad9bd6a94d6395382a6c69fe071708ae4409f763c5475e14ee896313d"
|
|
||||||
dependencies = [
|
|
||||||
"ole32-sys",
|
|
||||||
"shell32-sys",
|
|
||||||
"winapi 0.2.8",
|
|
||||||
"xdg",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "arc-swap"
|
name = "arc-swap"
|
||||||
version = "0.4.5"
|
version = "0.4.5"
|
||||||
@ -752,6 +740,16 @@ dependencies = [
|
|||||||
"winapi 0.3.8",
|
"winapi 0.3.8",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "directories"
|
||||||
|
version = "2.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "551a778172a450d7fc12e629ca3b0428d00f6afa9a43da1b630d54604e97371c"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"dirs-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dirs"
|
name = "dirs"
|
||||||
version = "1.0.5"
|
version = "1.0.5"
|
||||||
@ -2121,7 +2119,6 @@ name = "nu-cli"
|
|||||||
version = "0.14.1"
|
version = "0.14.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ansi_term 0.12.1",
|
"ansi_term 0.12.1",
|
||||||
"app_dirs",
|
|
||||||
"async-stream",
|
"async-stream",
|
||||||
"base64 0.12.0",
|
"base64 0.12.0",
|
||||||
"bigdecimal",
|
"bigdecimal",
|
||||||
@ -2136,6 +2133,7 @@ dependencies = [
|
|||||||
"csv",
|
"csv",
|
||||||
"ctrlc",
|
"ctrlc",
|
||||||
"derive-new",
|
"derive-new",
|
||||||
|
"directories 2.0.2",
|
||||||
"dirs 2.0.2",
|
"dirs 2.0.2",
|
||||||
"dunce",
|
"dunce",
|
||||||
"eml-parser",
|
"eml-parser",
|
||||||
@ -2303,7 +2301,7 @@ dependencies = [
|
|||||||
name = "nu-test-support"
|
name = "nu-test-support"
|
||||||
version = "0.14.1"
|
version = "0.14.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"app_dirs",
|
"directories 2.0.2",
|
||||||
"dunce",
|
"dunce",
|
||||||
"getset",
|
"getset",
|
||||||
"glob",
|
"glob",
|
||||||
@ -2600,16 +2598,6 @@ dependencies = [
|
|||||||
"objc",
|
"objc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ole32-sys"
|
|
||||||
version = "0.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5d2c49021782e5233cd243168edfa8037574afed4eba4bbaf538b3d8d1789d8c"
|
|
||||||
dependencies = [
|
|
||||||
"winapi 0.2.8",
|
|
||||||
"winapi-build",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.3.1"
|
version = "1.3.1"
|
||||||
@ -2906,7 +2894,7 @@ checksum = "6b0a3be00b19ee7bd33238c1c523a7ab4df697345f6b36f90827a7860ea938d4"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"ansi_term 0.11.0",
|
"ansi_term 0.11.0",
|
||||||
"config",
|
"config",
|
||||||
"directories",
|
"directories 1.0.2",
|
||||||
"isatty",
|
"isatty",
|
||||||
"petgraph",
|
"petgraph",
|
||||||
"serde 1.0.106",
|
"serde 1.0.106",
|
||||||
@ -3421,16 +3409,6 @@ dependencies = [
|
|||||||
"yaml-rust",
|
"yaml-rust",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "shell32-sys"
|
|
||||||
version = "0.1.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9ee04b46101f57121c9da2b151988283b6beb79b34f5bb29a58ee48cb695122c"
|
|
||||||
dependencies = [
|
|
||||||
"winapi 0.2.8",
|
|
||||||
"winapi-build",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "shellexpand"
|
name = "shellexpand"
|
||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
@ -4199,12 +4177,6 @@ dependencies = [
|
|||||||
"log",
|
"log",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "xdg"
|
|
||||||
version = "2.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d089681aa106a86fade1b0128fb5daf07d5867a509ab036d99988dec80429a57"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "xml-rs"
|
name = "xml-rs"
|
||||||
version = "0.8.2"
|
version = "0.8.2"
|
||||||
|
@ -20,7 +20,7 @@ nu-test-support = { version = "0.14.1", path = "../nu-test-support" }
|
|||||||
|
|
||||||
|
|
||||||
ansi_term = "0.12.1"
|
ansi_term = "0.12.1"
|
||||||
app_dirs = "1.2.1"
|
directories = "2.0.2"
|
||||||
async-stream = "0.2"
|
async-stream = "0.2"
|
||||||
base64 = "0.12.0"
|
base64 = "0.12.0"
|
||||||
bigdecimal = { version = "0.1.0", features = ["serde"] }
|
bigdecimal = { version = "0.1.0", features = ["serde"] }
|
||||||
|
@ -10,7 +10,7 @@ pub(crate) use nuconfig::NuConfig;
|
|||||||
use crate::commands::from_toml::convert_toml_value_to_nu_value;
|
use crate::commands::from_toml::convert_toml_value_to_nu_value;
|
||||||
use crate::commands::to_toml::value_to_toml_value;
|
use crate::commands::to_toml::value_to_toml_value;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use app_dirs::*;
|
use directories::ProjectDirs;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use log::trace;
|
use log::trace;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
@ -20,13 +20,8 @@ use std::fs::{self, OpenOptions};
|
|||||||
use std::io;
|
use std::io;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
pub const APP_INFO: AppInfo = AppInfo {
|
|
||||||
name: "nu",
|
|
||||||
author: "nu shell developers",
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn config_path() -> Result<PathBuf, ShellError> {
|
pub fn config_path() -> Result<PathBuf, ShellError> {
|
||||||
app_path(AppDataType::UserConfig, "config")
|
app_path("config", ProjectDirs::config_dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_path() -> Result<PathBuf, ShellError> {
|
pub fn default_path() -> Result<PathBuf, ShellError> {
|
||||||
@ -34,28 +29,26 @@ pub fn default_path() -> Result<PathBuf, ShellError> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_path_for(file: &Option<PathBuf>) -> Result<PathBuf, ShellError> {
|
pub fn default_path_for(file: &Option<PathBuf>) -> Result<PathBuf, ShellError> {
|
||||||
let filename = &mut config_path()?;
|
let mut filename = config_path()?;
|
||||||
let filename = match file {
|
let file: &Path = file
|
||||||
None => {
|
.as_ref()
|
||||||
filename.push("config.toml");
|
.map(AsRef::as_ref)
|
||||||
filename
|
.unwrap_or_else(|| "config.toml".as_ref());
|
||||||
}
|
filename.push(file);
|
||||||
Some(file) => {
|
|
||||||
filename.push(file);
|
|
||||||
filename
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(filename.clone())
|
Ok(filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn user_data() -> Result<PathBuf, ShellError> {
|
pub fn user_data() -> Result<PathBuf, ShellError> {
|
||||||
app_path(AppDataType::UserData, "user data")
|
app_path("user data", ProjectDirs::data_local_dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn app_path(app_data_type: AppDataType, display: &str) -> Result<PathBuf, ShellError> {
|
fn app_path<F: FnOnce(&ProjectDirs) -> &Path>(display: &str, f: F) -> Result<PathBuf, ShellError> {
|
||||||
let path = app_root(app_data_type, &APP_INFO).map_err(|err| {
|
let dir = ProjectDirs::from("org", "nushell", "nu")
|
||||||
ShellError::untagged_runtime_error(&format!("Couldn't open {} path:\n{}", display, err))
|
.ok_or_else(|| ShellError::untagged_runtime_error("Couldn't find project directory"))?;
|
||||||
|
let path = f(&dir).to_owned();
|
||||||
|
std::fs::create_dir_all(&path).map_err(|err| {
|
||||||
|
ShellError::untagged_runtime_error(&format!("Couldn't create {} path:\n{}", display, err))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(path)
|
Ok(path)
|
||||||
|
@ -14,7 +14,7 @@ nu-parser = { path = "../nu-parser", version = "0.14.1" }
|
|||||||
nu-source = { path = "../nu-source", version = "0.14.1" }
|
nu-source = { path = "../nu-source", version = "0.14.1" }
|
||||||
nu-protocol = { path = "../nu-protocol", version = "0.14.1" }
|
nu-protocol = { path = "../nu-protocol", version = "0.14.1" }
|
||||||
|
|
||||||
app_dirs = "1.2.1"
|
directories = "2.0.2"
|
||||||
dunce = "1.0.0"
|
dunce = "1.0.0"
|
||||||
getset = "0.1.0"
|
getset = "0.1.0"
|
||||||
glob = "0.3.0"
|
glob = "0.3.0"
|
||||||
|
@ -41,7 +41,7 @@ path = "/home/shaurya/Desktop"
|
|||||||
> open cargo_sample.toml | to toml
|
> open cargo_sample.toml | to toml
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ansi_term = "0.11.0"
|
ansi_term = "0.11.0"
|
||||||
app_dirs = "1.2.1"
|
directories = "2.0.2"
|
||||||
byte-unit = "2.1.0"
|
byte-unit = "2.1.0"
|
||||||
bytes = "0.4.12"
|
bytes = "0.4.12"
|
||||||
chrono-humanize = "0.0.11"
|
chrono-humanize = "0.0.11"
|
||||||
|
2
tests/fixtures/formats/cargo_sample.toml
vendored
2
tests/fixtures/formats/cargo_sample.toml
vendored
@ -43,7 +43,7 @@ getset = "0.0.7"
|
|||||||
logos = "0.10.0-rc2"
|
logos = "0.10.0-rc2"
|
||||||
logos-derive = "0.10.0-rc2"
|
logos-derive = "0.10.0-rc2"
|
||||||
language-reporting = "0.3.0"
|
language-reporting = "0.3.0"
|
||||||
app_dirs = "1.2.1"
|
directories = "2.0.2"
|
||||||
toml = "0.5.1"
|
toml = "0.5.1"
|
||||||
toml-query = "0.9.0"
|
toml-query = "0.9.0"
|
||||||
clap = "2.33.0"
|
clap = "2.33.0"
|
||||||
|
Loading…
Reference in New Issue
Block a user