From 78f13407e6e607198975b4d264a4d5611b1d4762 Mon Sep 17 00:00:00 2001 From: Sam Hedin Date: Mon, 13 Jul 2020 08:23:19 +0200 Subject: [PATCH] Documentation for autoenv (#2163) * Documentation * Somewhat nicer? * cat --- crates/nu-cli/src/commands/autoenv.rs | 20 ++++++++++++++++--- crates/nu-cli/src/commands/autoenv_trust.rs | 13 +++++++++++- crates/nu-cli/src/commands/autoenv_untrust.rs | 13 +++++++++++- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/crates/nu-cli/src/commands/autoenv.rs b/crates/nu-cli/src/commands/autoenv.rs index 5be58b1afe..a8777e65be 100644 --- a/crates/nu-cli/src/commands/autoenv.rs +++ b/crates/nu-cli/src/commands/autoenv.rs @@ -55,8 +55,13 @@ impl WholeStreamCommand for Autoenv { } fn usage(&self) -> &str { // "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" + r#"Manage directory specific environment variables and scripts. Create a file called .nu-env in any directory and run 'autoenv trust' to let nushell read it when entering the directory. +The file can contain several optional sections: + env: environment variables to set when visiting the directory. The variables are unset after leaving the directory and any overwritten values are restored. + scriptvars: environment variables that should be set to the return value of a script. After they have been set, they behave in the same way as variables set in the env section. + scripts: scripts to run when entering the directory or leaving it. Note that exitscripts are not run in the directory they are declared in."# } + fn signature(&self) -> Signature { Signature::build("autoenv") } @@ -74,8 +79,17 @@ impl WholeStreamCommand for Autoenv { fn examples(&self) -> Vec { vec![Example { - description: "Allow .nu-env file in current directory", - example: "autoenv trust", + description: "Example .nu-env file", + example: r#"cat .nu-env + [env] + mykey = "myvalue" + + [scriptvars] + myscript = "echo myval" + + [scripts] + entryscripts = ["touch hello.txt", "touch hello2.txt"] + exitscripts = ["touch bye.txt"]"#, result: None, }] } diff --git a/crates/nu-cli/src/commands/autoenv_trust.rs b/crates/nu-cli/src/commands/autoenv_trust.rs index 339844f7b9..82ef7510d8 100644 --- a/crates/nu-cli/src/commands/autoenv_trust.rs +++ b/crates/nu-cli/src/commands/autoenv_trust.rs @@ -69,6 +69,17 @@ impl WholeStreamCommand for AutoenvTrust { false } fn examples(&self) -> Vec { - Vec::new() + vec![ + Example { + description: "Allow .nu-env file in current directory", + example: "autoenv trust", + result: None, + }, + Example { + description: "Allow .nu-env file in directory foo", + example: "autoenv trust foo", + result: None, + }, + ] } } diff --git a/crates/nu-cli/src/commands/autoenv_untrust.rs b/crates/nu-cli/src/commands/autoenv_untrust.rs index 7dec2d67dc..512896893b 100644 --- a/crates/nu-cli/src/commands/autoenv_untrust.rs +++ b/crates/nu-cli/src/commands/autoenv_untrust.rs @@ -93,6 +93,17 @@ impl WholeStreamCommand for AutoenvUnTrust { false } fn examples(&self) -> Vec { - Vec::new() + vec![ + Example { + description: "Disallow .nu-env file in current directory", + example: "autoenv untrust", + result: None, + }, + Example { + description: "Disallow .nu-env file in directory foo", + example: "autoenv untrust foo", + result: None, + }, + ] } }