Initialize autoenv and autoenv trust

This commit is contained in:
Sam Hedin 2020-06-18 18:58:50 +02:00
parent 35bb9f2d1e
commit a54a596afd
5 changed files with 65 additions and 5 deletions

View File

@ -345,6 +345,8 @@ pub fn create_default_context(
whole_stream_command(Headers),
// Data processing
whole_stream_command(Histogram),
whole_stream_command(Autoenv),
whole_stream_command(AutoenvTrust),
whole_stream_command(Math),
whole_stream_command(Average),
whole_stream_command(Minimum),

View File

@ -7,6 +7,8 @@ mod to_delimited_data;
pub(crate) mod alias;
pub(crate) mod append;
pub(crate) mod args;
pub(crate) mod autoenv;
pub(crate) mod autoenv_trust;
pub(crate) mod autoview;
pub(crate) mod build_string;
pub(crate) mod cal;
@ -135,6 +137,8 @@ pub(crate) use command::{
pub(crate) use alias::Alias;
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 cal::Cal;
pub(crate) use calc::Calc;

View File

@ -1,7 +1,7 @@
use crate::commands::WholeStreamCommand;
use crate::prelude::*;
use nu_errors::ShellError;
use nu_protocol::{Primitive, ReturnSuccess, UntaggedValue, Value};
use nu_protocol::{Primitive, ReturnSuccess, UntaggedValue, Value, Signature};
pub struct Autoenv;
@ -11,20 +11,29 @@ impl WholeStreamCommand for Autoenv {
"autoenv"
}
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(
&self,
args: CommandArgs,
registry: &CommandRegistry,
) -> Result<OutputStream, ShellError> {
allow(args, registry).await
let registry = registry.clone();
Ok(OutputStream::one(ReturnSuccess::value(
UntaggedValue::string(crate::commands::help::get_help(&Autoenv, &registry))
.into_value(Tag::unknown()),
)))
}
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Allow .nu-env file in current directory",
example: "autoenv trust",
result: "Current "
result: None
}]
}
}
}

View 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))))
}
}

View File

@ -1,6 +1,8 @@
mod alias;
mod append;
mod average;
mod autoenv;
mod autoenv_trust;
mod cal;
mod calc;
mod cd;