mirror of
https://github.com/nushell/nushell.git
synced 2025-04-30 08:04:25 +02:00
Initialize autoenv and autoenv trust
This commit is contained in:
parent
35bb9f2d1e
commit
a54a596afd
@ -345,6 +345,8 @@ pub fn create_default_context(
|
|||||||
whole_stream_command(Headers),
|
whole_stream_command(Headers),
|
||||||
// Data processing
|
// Data processing
|
||||||
whole_stream_command(Histogram),
|
whole_stream_command(Histogram),
|
||||||
|
whole_stream_command(Autoenv),
|
||||||
|
whole_stream_command(AutoenvTrust),
|
||||||
whole_stream_command(Math),
|
whole_stream_command(Math),
|
||||||
whole_stream_command(Average),
|
whole_stream_command(Average),
|
||||||
whole_stream_command(Minimum),
|
whole_stream_command(Minimum),
|
||||||
|
@ -7,6 +7,8 @@ mod to_delimited_data;
|
|||||||
pub(crate) mod alias;
|
pub(crate) mod alias;
|
||||||
pub(crate) mod append;
|
pub(crate) mod append;
|
||||||
pub(crate) mod args;
|
pub(crate) mod args;
|
||||||
|
pub(crate) mod autoenv;
|
||||||
|
pub(crate) mod autoenv_trust;
|
||||||
pub(crate) mod autoview;
|
pub(crate) mod autoview;
|
||||||
pub(crate) mod build_string;
|
pub(crate) mod build_string;
|
||||||
pub(crate) mod cal;
|
pub(crate) mod cal;
|
||||||
@ -135,6 +137,8 @@ pub(crate) use command::{
|
|||||||
|
|
||||||
pub(crate) use alias::Alias;
|
pub(crate) use alias::Alias;
|
||||||
pub(crate) use append::Append;
|
pub(crate) use append::Append;
|
||||||
|
pub(crate) use autoenv::Autoenv;
|
||||||
|
pub(crate) use autoenv_trust::AutoenvTrust;
|
||||||
pub(crate) use build_string::BuildString;
|
pub(crate) use build_string::BuildString;
|
||||||
pub(crate) use cal::Cal;
|
pub(crate) use cal::Cal;
|
||||||
pub(crate) use calc::Calc;
|
pub(crate) use calc::Calc;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Primitive, ReturnSuccess, UntaggedValue, Value};
|
use nu_protocol::{Primitive, ReturnSuccess, UntaggedValue, Value, Signature};
|
||||||
|
|
||||||
pub struct Autoenv;
|
pub struct Autoenv;
|
||||||
|
|
||||||
@ -11,20 +11,29 @@ impl WholeStreamCommand for Autoenv {
|
|||||||
"autoenv"
|
"autoenv"
|
||||||
}
|
}
|
||||||
fn usage(&self) -> &str {
|
fn usage(&self) -> &str {
|
||||||
"Mark a .nu-env file in a directory as trusted. Needs to be re-made after each change to the file."
|
// "Mark a .nu-env file in a directory as trusted. Needs to be re-run after each change to the file or its filepath."
|
||||||
|
"Manage directory specific environments"
|
||||||
|
}
|
||||||
|
fn signature(&self) -> Signature {
|
||||||
|
Signature::build("autoenv")
|
||||||
}
|
}
|
||||||
async fn run(
|
async fn run(
|
||||||
&self,
|
&self,
|
||||||
args: CommandArgs,
|
args: CommandArgs,
|
||||||
registry: &CommandRegistry,
|
registry: &CommandRegistry,
|
||||||
) -> Result<OutputStream, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
allow(args, registry).await
|
let registry = registry.clone();
|
||||||
|
Ok(OutputStream::one(ReturnSuccess::value(
|
||||||
|
UntaggedValue::string(crate::commands::help::get_help(&Autoenv, ®istry))
|
||||||
|
.into_value(Tag::unknown()),
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
vec![Example {
|
vec![Example {
|
||||||
description: "Allow .nu-env file in current directory",
|
description: "Allow .nu-env file in current directory",
|
||||||
example: "autoenv trust",
|
example: "autoenv trust",
|
||||||
result: "Current "
|
result: None
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
43
crates/nu-cli/src/commands/autoenv_trust.rs
Normal file
43
crates/nu-cli/src/commands/autoenv_trust.rs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
use crate::commands::WholeStreamCommand;
|
||||||
|
use crate::data::value::format_leaf;
|
||||||
|
use crate::prelude::*;
|
||||||
|
use futures::StreamExt;
|
||||||
|
use std::io::Write;
|
||||||
|
use nu_errors::ShellError;
|
||||||
|
use nu_protocol::{Primitive, ReturnSuccess, Signature, UntaggedValue, Value};
|
||||||
|
use nu_source::AnchorLocation;
|
||||||
|
use std::fs::OpenOptions;
|
||||||
|
|
||||||
|
pub struct AutoenvTrust;
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl WholeStreamCommand for AutoenvTrust {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
"autoenv trust"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signature(&self) -> Signature {
|
||||||
|
Signature::build("autoenv trust")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn usage(&self) -> &str {
|
||||||
|
"Trust a .nu-env file in the current directory"
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn run(
|
||||||
|
&self,
|
||||||
|
args: CommandArgs,
|
||||||
|
registry: &CommandRegistry,
|
||||||
|
) -> Result<OutputStream, ShellError> {
|
||||||
|
let mut file = OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.append(true)
|
||||||
|
.create(true)
|
||||||
|
.open("autoenv.txt")
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
write!(&mut file, "I'm here!\n").unwrap();
|
||||||
|
let tag = args.call_info.name_tag.clone();
|
||||||
|
Ok(OutputStream::one(ReturnSuccess::value(UntaggedValue::string("success!").into_value(tag))))
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
mod alias;
|
mod alias;
|
||||||
mod append;
|
mod append;
|
||||||
mod average;
|
mod average;
|
||||||
|
mod autoenv;
|
||||||
|
mod autoenv_trust;
|
||||||
mod cal;
|
mod cal;
|
||||||
mod calc;
|
mod calc;
|
||||||
mod cd;
|
mod cd;
|
||||||
|
Loading…
Reference in New Issue
Block a user