mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 14:36:08 +02:00
Get $nu.config-path
and $nu.env-path
from EngineState
(#6366)
* Get `$nu.config-path` and `$nu.env-path` from `EngineState` Signed-off-by: nibon7 <nibon7@163.com> * replace tuple with hashmap Signed-off-by: nibon7 <nibon7@163.com> * refactor set_config_path Signed-off-by: nibon7 <nibon7@163.com> Signed-off-by: nibon7 <nibon7@163.com>
This commit is contained in:
42
src/main.rs
42
src/main.rs
@ -18,6 +18,7 @@ use nu_cli::{
|
||||
use nu_command::{create_default_context, BufferedReader};
|
||||
use nu_engine::{get_full_help, CallExt};
|
||||
use nu_parser::{escape_for_script_arg, escape_quote_string, parse};
|
||||
use nu_path::canonicalize_with;
|
||||
use nu_protocol::{
|
||||
ast::{Call, Expr, Expression},
|
||||
engine::{Command, EngineState, Stack, StateWorkingSet},
|
||||
@ -25,7 +26,7 @@ use nu_protocol::{
|
||||
Spanned, SyntaxShape, Value,
|
||||
};
|
||||
use nu_utils::stdout_write_all_and_flush;
|
||||
use std::cell::RefCell;
|
||||
use std::{cell::RefCell, path::Path};
|
||||
use std::{
|
||||
io::BufReader,
|
||||
sync::{
|
||||
@ -142,6 +143,24 @@ fn main() -> Result<()> {
|
||||
nu_system::signal::set_terminal_leader()
|
||||
}
|
||||
|
||||
if let Ok(ref args) = parsed_nu_cli_args {
|
||||
set_config_path(
|
||||
&mut engine_state,
|
||||
&init_cwd,
|
||||
"config.nu",
|
||||
"config-path",
|
||||
&args.config_file,
|
||||
);
|
||||
|
||||
set_config_path(
|
||||
&mut engine_state,
|
||||
&init_cwd,
|
||||
"env.nu",
|
||||
"env-path",
|
||||
&args.env_file,
|
||||
);
|
||||
}
|
||||
|
||||
match parsed_nu_cli_args {
|
||||
Ok(binary_args) => {
|
||||
if let Some(t) = binary_args.threads {
|
||||
@ -690,3 +709,24 @@ fn set_is_perf_value(value: bool) {
|
||||
*new_value.borrow_mut() = value;
|
||||
});
|
||||
}
|
||||
|
||||
fn set_config_path(
|
||||
engine_state: &mut EngineState,
|
||||
cwd: &Path,
|
||||
default_config_name: &str,
|
||||
key: &str,
|
||||
config_file: &Option<Spanned<String>>,
|
||||
) {
|
||||
let config_path = match config_file {
|
||||
Some(s) => canonicalize_with(&s.item, cwd).ok(),
|
||||
None => nu_path::config_dir().map(|mut p| {
|
||||
p.push(config_files::NUSHELL_FOLDER);
|
||||
p.push(default_config_name);
|
||||
p
|
||||
}),
|
||||
};
|
||||
|
||||
if let Some(path) = config_path {
|
||||
engine_state.set_config_path(key, path);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user