mirror of
https://github.com/nushell/nushell.git
synced 2024-12-25 08:29:07 +01:00
parent
352cf31db2
commit
1c964cdfe7
@ -1,66 +0,0 @@
|
||||
trigger:
|
||||
- main
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
linux-stable:
|
||||
image: ubuntu-18.04
|
||||
style: 'unflagged'
|
||||
linux-minimal:
|
||||
image: ubuntu-18.04
|
||||
style: 'minimal'
|
||||
linux-extra:
|
||||
image: ubuntu-18.04
|
||||
style: 'extra'
|
||||
linux-wasm:
|
||||
image: ubuntu-18.04
|
||||
style: 'wasm'
|
||||
macos-stable:
|
||||
image: macOS-10.15
|
||||
style: 'unflagged'
|
||||
windows-stable:
|
||||
image: windows-2019
|
||||
style: 'unflagged'
|
||||
fmt:
|
||||
image: ubuntu-18.04
|
||||
style: 'fmt'
|
||||
|
||||
pool:
|
||||
vmImage: $(image)
|
||||
|
||||
steps:
|
||||
- bash: |
|
||||
set -e
|
||||
if [ -e /etc/debian_version ]
|
||||
then
|
||||
sudo apt-get -y install libxcb-composite0-dev libx11-dev
|
||||
fi
|
||||
if [ "$(uname)" == "Darwin" ]; then
|
||||
curl https://sh.rustup.rs -sSf | sh -s -- -y --no-modify-path --default-toolchain "stable"
|
||||
echo "Installing clippy"
|
||||
rustup component add clippy --toolchain stable-x86_64-apple-darwin
|
||||
export PATH=$HOME/.cargo/bin:$PATH
|
||||
fi
|
||||
# rustup update
|
||||
# rustc -Vv
|
||||
# echo "##vso[task.prependpath]$HOME/.cargo/bin"
|
||||
# rustup component add rustfmt
|
||||
displayName: Install Rust
|
||||
- bash: RUSTFLAGS="-D warnings" cargo test --all
|
||||
condition: eq(variables['style'], 'unflagged')
|
||||
displayName: Run tests
|
||||
- bash: RUSTFLAGS="-D warnings" cargo clippy --all -- -D clippy::unwrap_used -A clippy::needless_collect
|
||||
condition: eq(variables['style'], 'unflagged')
|
||||
displayName: Check clippy lints
|
||||
- bash: cd samples/wasm && npm install wasm-pack && node ./node_modules/wasm-pack/run.js build
|
||||
condition: eq(variables['style'], 'wasm')
|
||||
displayName: Wasm build
|
||||
- bash: RUSTFLAGS="-D warnings" cargo test --all --no-default-features --features=rustyline-support
|
||||
condition: eq(variables['style'], 'minimal')
|
||||
displayName: Run tests
|
||||
- bash: RUSTFLAGS="-D warnings" cargo test --all --features=extra
|
||||
condition: eq(variables['style'], 'extra')
|
||||
displayName: Run tests
|
||||
- bash: cargo fmt --all -- --check
|
||||
condition: eq(variables['style'], 'fmt')
|
||||
displayName: Lint
|
42
Cargo.lock
generated
42
Cargo.lock
generated
@ -2130,7 +2130,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nu"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
dependencies = [
|
||||
"assert_cmd",
|
||||
"chrono",
|
||||
@ -2180,7 +2180,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nu-cli"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
dependencies = [
|
||||
"crossterm",
|
||||
"crossterm_winapi",
|
||||
@ -2200,7 +2200,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nu-color-config"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
dependencies = [
|
||||
"nu-ansi-term",
|
||||
"nu-json",
|
||||
@ -2211,7 +2211,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nu-command"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
dependencies = [
|
||||
"Inflector",
|
||||
"base64",
|
||||
@ -2292,7 +2292,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nu-engine"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"itertools",
|
||||
@ -2303,7 +2303,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nu-glob"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
dependencies = [
|
||||
"doc-comment",
|
||||
"tempdir",
|
||||
@ -2311,7 +2311,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nu-json"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"linked-hash-map",
|
||||
@ -2324,7 +2324,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nu-parser"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"log",
|
||||
@ -2338,7 +2338,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nu-path"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
dependencies = [
|
||||
"dirs-next",
|
||||
"dunce",
|
||||
@ -2346,7 +2346,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nu-plugin"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
dependencies = [
|
||||
"capnp",
|
||||
"nu-engine",
|
||||
@ -2357,7 +2357,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nu-pretty-hex"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
dependencies = [
|
||||
"heapless 0.7.10",
|
||||
"nu-ansi-term",
|
||||
@ -2366,7 +2366,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nu-protocol"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
dependencies = [
|
||||
"byte-unit",
|
||||
"chrono",
|
||||
@ -2385,7 +2385,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nu-system"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"errno",
|
||||
@ -2401,7 +2401,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nu-table"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
dependencies = [
|
||||
"ansi-cut",
|
||||
"atty",
|
||||
@ -2414,7 +2414,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nu-term-grid"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
dependencies = [
|
||||
"strip-ansi-escapes",
|
||||
"unicode-width",
|
||||
@ -2422,7 +2422,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nu-test-support"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
dependencies = [
|
||||
"bigdecimal",
|
||||
"chrono",
|
||||
@ -2438,14 +2438,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nu-utils"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
dependencies = [
|
||||
"crossterm_winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nu_plugin_example"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
dependencies = [
|
||||
"nu-plugin",
|
||||
"nu-protocol",
|
||||
@ -2453,7 +2453,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nu_plugin_gstat"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
dependencies = [
|
||||
"git2",
|
||||
"nu-engine",
|
||||
@ -2463,7 +2463,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nu_plugin_inc"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
dependencies = [
|
||||
"nu-plugin",
|
||||
"nu-protocol",
|
||||
@ -2472,7 +2472,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nu_plugin_query"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
dependencies = [
|
||||
"gjson",
|
||||
"nu-engine",
|
||||
|
30
Cargo.toml
30
Cargo.toml
@ -10,7 +10,7 @@ license = "MIT"
|
||||
name = "nu"
|
||||
readme = "README.md"
|
||||
repository = "https://github.com/nushell/nushell"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@ -38,20 +38,20 @@ ctrlc = "3.2.1"
|
||||
log = "0.4"
|
||||
miette = "4.1.0"
|
||||
nu-ansi-term = "0.45.0"
|
||||
nu-cli = { path="./crates/nu-cli", version = "0.59.1" }
|
||||
nu-color-config = { path = "./crates/nu-color-config", version = "0.59.1" }
|
||||
nu-command = { path="./crates/nu-command", version = "0.59.1" }
|
||||
nu-engine = { path="./crates/nu-engine", version = "0.59.1" }
|
||||
nu-json = { path="./crates/nu-json", version = "0.59.1" }
|
||||
nu-parser = { path="./crates/nu-parser", version = "0.59.1" }
|
||||
nu-path = { path="./crates/nu-path", version = "0.59.1" }
|
||||
nu-plugin = { path = "./crates/nu-plugin", optional = true, version = "0.59.1" }
|
||||
nu-pretty-hex = { path = "./crates/nu-pretty-hex", version = "0.59.1" }
|
||||
nu-protocol = { path = "./crates/nu-protocol", version = "0.59.1" }
|
||||
nu-system = { path = "./crates/nu-system", version = "0.59.1" }
|
||||
nu-table = { path = "./crates/nu-table", version = "0.59.1" }
|
||||
nu-term-grid = { path = "./crates/nu-term-grid", version = "0.59.1" }
|
||||
nu-utils = { path = "./crates/nu-utils", version = "0.59.1" }
|
||||
nu-cli = { path="./crates/nu-cli", version = "0.60.0" }
|
||||
nu-color-config = { path = "./crates/nu-color-config", version = "0.60.0" }
|
||||
nu-command = { path="./crates/nu-command", version = "0.60.0" }
|
||||
nu-engine = { path="./crates/nu-engine", version = "0.60.0" }
|
||||
nu-json = { path="./crates/nu-json", version = "0.60.0" }
|
||||
nu-parser = { path="./crates/nu-parser", version = "0.60.0" }
|
||||
nu-path = { path="./crates/nu-path", version = "0.60.0" }
|
||||
nu-plugin = { path = "./crates/nu-plugin", optional = true, version = "0.60.0" }
|
||||
nu-pretty-hex = { path = "./crates/nu-pretty-hex", version = "0.60.0" }
|
||||
nu-protocol = { path = "./crates/nu-protocol", version = "0.60.0" }
|
||||
nu-system = { path = "./crates/nu-system", version = "0.60.0" }
|
||||
nu-table = { path = "./crates/nu-table", version = "0.60.0" }
|
||||
nu-term-grid = { path = "./crates/nu-term-grid", version = "0.60.0" }
|
||||
nu-utils = { path = "./crates/nu-utils", version = "0.60.0" }
|
||||
pretty_env_logger = "0.4.0"
|
||||
rayon = "1.5.1"
|
||||
reedline = "0.3.0"
|
||||
|
229
Cargo.toml.old
229
Cargo.toml.old
@ -1,229 +0,0 @@
|
||||
[package]
|
||||
authors = ["The Nushell Project Developers"]
|
||||
default-run = "nu"
|
||||
description = "A new type of shell"
|
||||
documentation = "https://www.nushell.sh/book/"
|
||||
edition = "2018"
|
||||
exclude = ["images"]
|
||||
homepage = "https://www.nushell.sh"
|
||||
license = "MIT"
|
||||
name = "nu"
|
||||
readme = "README.md"
|
||||
repository = "https://github.com/nushell/nushell"
|
||||
version = "0.44.0"
|
||||
|
||||
[workspace]
|
||||
members = ["crates/*/"]
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
nu-cli = { version = "0.44.0", path="./crates/nu-cli", default-features=false }
|
||||
nu-command = { version = "0.44.0", path="./crates/nu-command" }
|
||||
nu-completion = { version = "0.44.0", path="./crates/nu-completion" }
|
||||
nu-data = { version = "0.44.0", path="./crates/nu-data" }
|
||||
nu-engine = { version = "0.44.0", path="./crates/nu-engine" }
|
||||
nu-errors = { version = "0.44.0", path="./crates/nu-errors" }
|
||||
nu-parser = { version = "0.44.0", path="./crates/nu-parser" }
|
||||
nu-path = { version = "0.44.0", path="./crates/nu-path" }
|
||||
nu-plugin = { version = "0.44.0", path="./crates/nu-plugin" }
|
||||
nu-protocol = { version = "0.44.0", path="./crates/nu-protocol" }
|
||||
nu-source = { version = "0.44.0", path="./crates/nu-source" }
|
||||
nu-value-ext = { version = "0.44.0", path="./crates/nu-value-ext" }
|
||||
|
||||
nu_plugin_binaryview = { version = "0.44.0", path="./crates/nu_plugin_binaryview", optional=true }
|
||||
nu_plugin_chart = { version = "0.44.0", path="./crates/nu_plugin_chart", optional=true }
|
||||
nu_plugin_from_bson = { version = "0.44.0", path="./crates/nu_plugin_from_bson", optional=true }
|
||||
nu_plugin_from_sqlite = { version = "0.44.0", path="./crates/nu_plugin_from_sqlite", optional=true }
|
||||
nu_plugin_inc = { version = "0.44.0", path="./crates/nu_plugin_inc", optional=true }
|
||||
nu_plugin_match = { version = "0.44.0", path="./crates/nu_plugin_match", optional=true }
|
||||
nu_plugin_query_json = { version = "0.44.0", path="./crates/nu_plugin_query_json", optional=true }
|
||||
nu_plugin_s3 = { version = "0.44.0", path="./crates/nu_plugin_s3", optional=true }
|
||||
nu_plugin_selector = { version = "0.44.0", path="./crates/nu_plugin_selector", optional=true }
|
||||
nu_plugin_start = { version = "0.44.0", path="./crates/nu_plugin_start", optional=true }
|
||||
nu_plugin_textview = { version = "0.44.0", path="./crates/nu_plugin_textview", optional=true }
|
||||
nu_plugin_to_bson = { version = "0.44.0", path="./crates/nu_plugin_to_bson", optional=true }
|
||||
nu_plugin_to_sqlite = { version = "0.44.0", path="./crates/nu_plugin_to_sqlite", optional=true }
|
||||
nu_plugin_tree = { version = "0.44.0", path="./crates/nu_plugin_tree", optional=true }
|
||||
nu_plugin_xpath = { version = "0.44.0", path="./crates/nu_plugin_xpath", optional=true }
|
||||
|
||||
# Required to bootstrap the main binary
|
||||
ctrlc = { version="3.1.7", optional=true }
|
||||
futures = { version="0.3.12", features=["compat", "io-compat"] }
|
||||
itertools = "0.10.0"
|
||||
|
||||
[dev-dependencies]
|
||||
nu-test-support = { version = "0.44.0", path="./crates/nu-test-support" }
|
||||
serial_test = "0.5.1"
|
||||
hamcrest2 = "0.3.0"
|
||||
rstest = "0.10.0"
|
||||
|
||||
[build-dependencies]
|
||||
|
||||
[features]
|
||||
fetch-support = ["nu-command/fetch", "nu-command/post"]
|
||||
sys-support = ["nu-command/sys", "nu-command/ps"]
|
||||
ctrlc-support = ["nu-cli/ctrlc", "nu-command/ctrlc"]
|
||||
rustyline-support = ["nu-cli/rustyline-support", "nu-command/rustyline-support"]
|
||||
term-support = ["nu-command/term"]
|
||||
uuid-support = ["nu-command/uuid_crate"]
|
||||
which-support = ["nu-command/which", "nu-engine/which"]
|
||||
|
||||
default = [
|
||||
"nu-cli/shadow-rs",
|
||||
"sys-support",
|
||||
"ctrlc-support",
|
||||
"which-support",
|
||||
"term-support",
|
||||
"rustyline-support",
|
||||
"match",
|
||||
"fetch-support",
|
||||
"zip-support",
|
||||
"dataframe",
|
||||
]
|
||||
|
||||
stable = ["default"]
|
||||
extra = [
|
||||
"default",
|
||||
"binaryview",
|
||||
"inc",
|
||||
"tree",
|
||||
"textview",
|
||||
"trash-support",
|
||||
"uuid-support",
|
||||
"start",
|
||||
"bson",
|
||||
"sqlite",
|
||||
"s3",
|
||||
"chart",
|
||||
"xpath",
|
||||
"selector",
|
||||
"query-json",
|
||||
]
|
||||
|
||||
wasi = ["inc", "match", "match", "tree", "rustyline-support"]
|
||||
|
||||
# Stable (Default)
|
||||
inc = ["nu_plugin_inc"]
|
||||
match = ["nu_plugin_match"]
|
||||
textview = ["nu_plugin_textview"]
|
||||
|
||||
# Extra
|
||||
binaryview = ["nu_plugin_binaryview"]
|
||||
bson = ["nu_plugin_from_bson", "nu_plugin_to_bson"]
|
||||
chart = ["nu_plugin_chart"]
|
||||
query-json = ["nu_plugin_query_json"]
|
||||
s3 = ["nu_plugin_s3"]
|
||||
selector = ["nu_plugin_selector"]
|
||||
sqlite = ["nu_plugin_from_sqlite", "nu_plugin_to_sqlite"]
|
||||
start = ["nu_plugin_start"]
|
||||
trash-support = [
|
||||
"nu-command/trash-support",
|
||||
"nu-engine/trash-support",
|
||||
]
|
||||
tree = ["nu_plugin_tree"]
|
||||
xpath = ["nu_plugin_xpath"]
|
||||
zip-support = ["nu-command/zip"]
|
||||
|
||||
#dataframe feature for nushell
|
||||
dataframe = [
|
||||
"nu-engine/dataframe",
|
||||
"nu-protocol/dataframe",
|
||||
"nu-command/dataframe",
|
||||
"nu-value-ext/dataframe",
|
||||
"nu-data/dataframe",
|
||||
"nu_plugin_to_bson/dataframe",
|
||||
]
|
||||
|
||||
[profile.release]
|
||||
opt-level = "s" # Optimize for size.
|
||||
|
||||
# Core plugins that ship with `cargo install nu` by default
|
||||
# Currently, Cargo limits us to installing only one binary
|
||||
# unless we use [[bin]], so we use this as a workaround
|
||||
[[bin]]
|
||||
name = "nu_plugin_core_textview"
|
||||
path = "src/plugins/nu_plugin_core_textview.rs"
|
||||
required-features = ["textview"]
|
||||
|
||||
[[bin]]
|
||||
name = "nu_plugin_core_inc"
|
||||
path = "src/plugins/nu_plugin_core_inc.rs"
|
||||
required-features = ["inc"]
|
||||
|
||||
[[bin]]
|
||||
name = "nu_plugin_core_match"
|
||||
path = "src/plugins/nu_plugin_core_match.rs"
|
||||
required-features = ["match"]
|
||||
|
||||
# Extra plugins
|
||||
|
||||
[[bin]]
|
||||
name = "nu_plugin_extra_binaryview"
|
||||
path = "src/plugins/nu_plugin_extra_binaryview.rs"
|
||||
required-features = ["binaryview"]
|
||||
|
||||
[[bin]]
|
||||
name = "nu_plugin_extra_tree"
|
||||
path = "src/plugins/nu_plugin_extra_tree.rs"
|
||||
required-features = ["tree"]
|
||||
|
||||
[[bin]]
|
||||
name = "nu_plugin_extra_query_json"
|
||||
path = "src/plugins/nu_plugin_extra_query_json.rs"
|
||||
required-features = ["query-json"]
|
||||
|
||||
[[bin]]
|
||||
name = "nu_plugin_extra_start"
|
||||
path = "src/plugins/nu_plugin_extra_start.rs"
|
||||
required-features = ["start"]
|
||||
|
||||
[[bin]]
|
||||
name = "nu_plugin_extra_s3"
|
||||
path = "src/plugins/nu_plugin_extra_s3.rs"
|
||||
required-features = ["s3"]
|
||||
|
||||
[[bin]]
|
||||
name = "nu_plugin_extra_chart_bar"
|
||||
path = "src/plugins/nu_plugin_extra_chart_bar.rs"
|
||||
required-features = ["chart"]
|
||||
|
||||
[[bin]]
|
||||
name = "nu_plugin_extra_chart_line"
|
||||
path = "src/plugins/nu_plugin_extra_chart_line.rs"
|
||||
required-features = ["chart"]
|
||||
|
||||
[[bin]]
|
||||
name = "nu_plugin_extra_xpath"
|
||||
path = "src/plugins/nu_plugin_extra_xpath.rs"
|
||||
required-features = ["xpath"]
|
||||
|
||||
[[bin]]
|
||||
name = "nu_plugin_extra_selector"
|
||||
path = "src/plugins/nu_plugin_extra_selector.rs"
|
||||
required-features = ["selector"]
|
||||
|
||||
[[bin]]
|
||||
name = "nu_plugin_extra_from_bson"
|
||||
path = "src/plugins/nu_plugin_extra_from_bson.rs"
|
||||
required-features = ["bson"]
|
||||
|
||||
[[bin]]
|
||||
name = "nu_plugin_extra_to_bson"
|
||||
path = "src/plugins/nu_plugin_extra_to_bson.rs"
|
||||
required-features = ["bson"]
|
||||
|
||||
[[bin]]
|
||||
name = "nu_plugin_extra_from_sqlite"
|
||||
path = "src/plugins/nu_plugin_extra_from_sqlite.rs"
|
||||
required-features = ["sqlite"]
|
||||
|
||||
[[bin]]
|
||||
name = "nu_plugin_extra_to_sqlite"
|
||||
path = "src/plugins/nu_plugin_extra_to_sqlite.rs"
|
||||
required-features = ["sqlite"]
|
||||
|
||||
# Main nu binary
|
||||
[[bin]]
|
||||
name = "nu"
|
||||
path = "src/main.rs"
|
@ -1,14 +1,14 @@
|
||||
[package]
|
||||
name = "nu-cli"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
nu-engine = { path = "../nu-engine", version = "0.59.1" }
|
||||
nu-path = { path = "../nu-path", version = "0.59.1" }
|
||||
nu-parser = { path = "../nu-parser", version = "0.59.1" }
|
||||
nu-protocol = { path = "../nu-protocol", version = "0.59.1" }
|
||||
nu-utils = { path = "../nu-utils", version = "0.59.1" }
|
||||
nu-engine = { path = "../nu-engine", version = "0.60.0" }
|
||||
nu-path = { path = "../nu-path", version = "0.60.0" }
|
||||
nu-parser = { path = "../nu-parser", version = "0.60.0" }
|
||||
nu-protocol = { path = "../nu-protocol", version = "0.60.0" }
|
||||
nu-utils = { path = "../nu-utils", version = "0.60.0" }
|
||||
nu-ansi-term = "0.45.0"
|
||||
|
||||
nu-color-config = { path = "../nu-color-config" }
|
||||
|
@ -1,13 +1,13 @@
|
||||
[package]
|
||||
name = "nu-color-config"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
nu-protocol = { path = "../nu-protocol", version = "0.59.1" }
|
||||
nu-protocol = { path = "../nu-protocol", version = "0.60.0" }
|
||||
nu-ansi-term = "0.45.0"
|
||||
|
||||
nu-json = { path = "../nu-json", version = "0.59.1" }
|
||||
nu-table = { path = "../nu-table", version = "0.59.1" }
|
||||
nu-json = { path = "../nu-json", version = "0.60.0" }
|
||||
nu-table = { path = "../nu-table", version = "0.60.0" }
|
||||
|
||||
serde = { version="1.0.123", features=["derive"] }
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "nu-command"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
edition = "2021"
|
||||
build = "build.rs"
|
||||
|
||||
@ -8,19 +8,19 @@ build = "build.rs"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
nu-color-config = { path = "../nu-color-config", version = "0.59.1" }
|
||||
nu-engine = { path = "../nu-engine", version = "0.59.1" }
|
||||
nu-glob = { path = "../nu-glob", version = "0.59.1" }
|
||||
nu-json = { path = "../nu-json", version = "0.59.1" }
|
||||
nu-parser = { path = "../nu-parser", version = "0.59.1" }
|
||||
nu-path = { path = "../nu-path", version = "0.59.1" }
|
||||
nu-pretty-hex = { path = "../nu-pretty-hex", version = "0.59.1" }
|
||||
nu-protocol = { path = "../nu-protocol", version = "0.59.1" }
|
||||
nu-system = { path = "../nu-system", version = "0.59.1" }
|
||||
nu-table = { path = "../nu-table", version = "0.59.1" }
|
||||
nu-term-grid = { path = "../nu-term-grid", version = "0.59.1" }
|
||||
nu-test-support = { path = "../nu-test-support", version = "0.59.1" }
|
||||
nu-utils = { path = "../nu-utils", version = "0.59.1" }
|
||||
nu-color-config = { path = "../nu-color-config", version = "0.60.0" }
|
||||
nu-engine = { path = "../nu-engine", version = "0.60.0" }
|
||||
nu-glob = { path = "../nu-glob", version = "0.60.0" }
|
||||
nu-json = { path = "../nu-json", version = "0.60.0" }
|
||||
nu-parser = { path = "../nu-parser", version = "0.60.0" }
|
||||
nu-path = { path = "../nu-path", version = "0.60.0" }
|
||||
nu-pretty-hex = { path = "../nu-pretty-hex", version = "0.60.0" }
|
||||
nu-protocol = { path = "../nu-protocol", version = "0.60.0" }
|
||||
nu-system = { path = "../nu-system", version = "0.60.0" }
|
||||
nu-table = { path = "../nu-table", version = "0.60.0" }
|
||||
nu-term-grid = { path = "../nu-term-grid", version = "0.60.0" }
|
||||
nu-test-support = { path = "../nu-test-support", version = "0.60.0" }
|
||||
nu-utils = { path = "../nu-utils", version = "0.60.0" }
|
||||
nu-ansi-term = "0.45.0"
|
||||
|
||||
# Potential dependencies for extras
|
||||
|
@ -2,8 +2,8 @@ use nu_engine::CallExt;
|
||||
use nu_protocol::ast::{Call, Expr, Expression};
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, DataSource, Example, IntoPipelineData, PipelineData, PipelineMetadata, ShellError,
|
||||
Signature, Span, SyntaxShape, Value,
|
||||
Category, DataSource, Example, IntoPipelineData, PipelineData, PipelineMetadata, Signature,
|
||||
Span, SyntaxShape, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -41,6 +41,7 @@ impl Command for Metadata {
|
||||
match arg {
|
||||
Some(Expression {
|
||||
expr: Expr::FullCellPath(full_cell_path),
|
||||
span,
|
||||
..
|
||||
}) => {
|
||||
if full_cell_path.tail.is_empty() {
|
||||
@ -49,30 +50,25 @@ impl Command for Metadata {
|
||||
expr: Expr::Var(var_id),
|
||||
..
|
||||
} => {
|
||||
let variable = engine_state.get_var(*var_id);
|
||||
let origin = stack.get_var_with_origin(*var_id, *span)?;
|
||||
|
||||
Ok(build_metadata_record(
|
||||
Ok(variable.declaration_span),
|
||||
&input.metadata(),
|
||||
head,
|
||||
)
|
||||
.into_pipeline_data())
|
||||
Ok(build_metadata_record(&origin, &input.metadata(), head)
|
||||
.into_pipeline_data())
|
||||
}
|
||||
_ => {
|
||||
let val: Value = call.req(engine_state, stack, 0)?;
|
||||
Ok(build_metadata_record(val.span(), &input.metadata(), head)
|
||||
Ok(build_metadata_record(&val, &input.metadata(), head)
|
||||
.into_pipeline_data())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let val: Value = call.req(engine_state, stack, 0)?;
|
||||
Ok(build_metadata_record(val.span(), &input.metadata(), head)
|
||||
.into_pipeline_data())
|
||||
Ok(build_metadata_record(&val, &input.metadata(), head).into_pipeline_data())
|
||||
}
|
||||
}
|
||||
Some(_) => {
|
||||
let val: Value = call.req(engine_state, stack, 0)?;
|
||||
Ok(build_metadata_record(val.span(), &input.metadata(), head).into_pipeline_data())
|
||||
Ok(build_metadata_record(&val, &input.metadata(), head).into_pipeline_data())
|
||||
}
|
||||
None => {
|
||||
let mut cols = vec![];
|
||||
@ -117,15 +113,11 @@ impl Command for Metadata {
|
||||
}
|
||||
}
|
||||
|
||||
fn build_metadata_record(
|
||||
span: Result<Span, ShellError>,
|
||||
metadata: &Option<PipelineMetadata>,
|
||||
head: Span,
|
||||
) -> Value {
|
||||
fn build_metadata_record(arg: &Value, metadata: &Option<PipelineMetadata>, head: Span) -> Value {
|
||||
let mut cols = vec![];
|
||||
let mut vals = vec![];
|
||||
|
||||
if let Ok(span) = span {
|
||||
if let Ok(span) = arg.span() {
|
||||
cols.push("span".into());
|
||||
vals.push(Value::Record {
|
||||
cols: vec!["start".into(), "end".into()],
|
||||
|
@ -1,12 +1,12 @@
|
||||
[package]
|
||||
name = "nu-engine"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
nu-protocol = { path = "../nu-protocol", features = ["plugin"], version = "0.59.1" }
|
||||
nu-path = { path = "../nu-path", version = "0.59.1" }
|
||||
nu-glob = { path = "../nu-glob", version = "0.59.1" }
|
||||
nu-protocol = { path = "../nu-protocol", features = ["plugin"], version = "0.60.0" }
|
||||
nu-path = { path = "../nu-path", version = "0.60.0" }
|
||||
nu-glob = { path = "../nu-glob", version = "0.60.0" }
|
||||
|
||||
itertools = "0.10.1"
|
||||
chrono = { version="0.4.19", features=["serde"] }
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "nu-glob"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
authors = ["The Nushell Project Developers", "The Rust Project Developers"]
|
||||
license = "MIT/Apache-2.0"
|
||||
description = """
|
||||
|
@ -4,7 +4,7 @@ description = "Fork of serde-hjson"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
name = "nu-json"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@ -20,5 +20,5 @@ lazy_static = "1"
|
||||
linked-hash-map = { version="0.5", optional=true }
|
||||
|
||||
[dev-dependencies]
|
||||
nu-path = { path="../nu-path", version = "0.59.1" }
|
||||
nu-path = { path="../nu-path", version = "0.60.0" }
|
||||
serde_json = "1.0.39"
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "nu-parser"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
@ -9,8 +9,8 @@ miette = "4.1.0"
|
||||
thiserror = "1.0.29"
|
||||
serde_json = "1.0"
|
||||
nu-path = {path = "../nu-path"}
|
||||
nu-protocol = { path = "../nu-protocol", version = "0.59.1" }
|
||||
nu-plugin = { path = "../nu-plugin", optional = true, version = "0.59.1" }
|
||||
nu-protocol = { path = "../nu-protocol", version = "0.60.0" }
|
||||
nu-plugin = { path = "../nu-plugin", optional = true, version = "0.60.0" }
|
||||
log = "0.4"
|
||||
|
||||
[features]
|
||||
|
@ -4,7 +4,7 @@ description = "Path handling library for Nushell"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
name = "nu-path"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
|
||||
[dependencies]
|
||||
dirs-next = "2.0.0"
|
||||
|
@ -1,11 +1,11 @@
|
||||
[package]
|
||||
name = "nu-plugin"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
capnp = "0.14.3"
|
||||
nu-protocol = { path = "../nu-protocol", version = "0.59.1" }
|
||||
nu-engine = { path = "../nu-engine", version = "0.59.1" }
|
||||
nu-protocol = { path = "../nu-protocol", version = "0.60.0" }
|
||||
nu-engine = { path = "../nu-engine", version = "0.60.0" }
|
||||
serde = {version = "1.0.130", features = ["derive"]}
|
||||
serde_json = { version = "1.0"}
|
||||
|
@ -1,9 +1,9 @@
|
||||
@0xb299d30dc02d72bc;
|
||||
# Schema representing all the structs that are used to comunicate with
|
||||
# Schema representing all the structs that are used to communicate with
|
||||
# the plugins.
|
||||
# This schema, together with the command capnp proto is used to generate
|
||||
# the rust file that defines the serialization/deserialization objects
|
||||
# required to comunicate with the plugins created for nushell
|
||||
# required to communicate with the plugins created for nushell
|
||||
#
|
||||
# If you modify the schema remember to compile it to generate the corresponding
|
||||
# rust file and place that file into the main nu-plugin folder.
|
||||
|
@ -4,7 +4,7 @@ description = "Pretty hex dump of bytes slice in the common style."
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
name = "nu-pretty-hex"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "nu-protocol"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
@ -15,7 +15,7 @@ chrono-humanize = "0.2.1"
|
||||
byte-unit = "4.0.9"
|
||||
im = "15.0.0"
|
||||
serde_json = { version = "1.0", optional = true }
|
||||
nu-json = { path = "../nu-json", version = "0.59.1" }
|
||||
nu-json = { path = "../nu-json", version = "0.60.0" }
|
||||
typetag = "0.1.8"
|
||||
num-format = "0.4.0"
|
||||
sys-locale = "0.1.0"
|
||||
|
2
crates/nu-system/Cargo.lock
generated
2
crates/nu-system/Cargo.lock
generated
@ -148,7 +148,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nu-system"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
dependencies = [
|
||||
"errno",
|
||||
"libproc",
|
||||
|
@ -2,7 +2,7 @@
|
||||
authors = ["The Nushell Project Developers", "procs creators"]
|
||||
description = "Nushell system querying"
|
||||
name = "nu-system"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
@ -4,7 +4,7 @@ description = "Nushell table printing"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
name = "nu-table"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[[bin]]
|
||||
@ -13,7 +13,7 @@ path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
nu-ansi-term = "0.45.0"
|
||||
nu-protocol = { path = "../nu-protocol", version = "0.59.1" }
|
||||
nu-protocol = { path = "../nu-protocol", version = "0.60.0" }
|
||||
regex = "1.4"
|
||||
unicode-width = "0.1.8"
|
||||
strip-ansi-escapes = "0.1.1"
|
||||
|
@ -4,7 +4,7 @@ description = "Nushell grid printing"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
name = "nu-term-grid"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[[bin]]
|
||||
|
@ -4,15 +4,15 @@ description = "Support for writing Nushell tests"
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
name = "nu-test-support"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
nu-path = { path="../nu-path", version = "0.59.1" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.59.1" }
|
||||
nu-glob = { path = "../nu-glob", version = "0.59.1" }
|
||||
nu-path = { path="../nu-path", version = "0.60.0" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.60.0" }
|
||||
nu-glob = { path = "../nu-glob", version = "0.60.0" }
|
||||
|
||||
bigdecimal = { package = "bigdecimal", version = "0.3.0", features = ["serde"] }
|
||||
chrono = "0.4.19"
|
||||
|
@ -4,7 +4,7 @@ description = "Nushell utility functions"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
name = "nu-utils"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[[bin]]
|
||||
|
@ -4,8 +4,8 @@ description = "A version incrementer plugin for Nushell"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
name = "nu_plugin_example"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
|
||||
[dependencies]
|
||||
nu-plugin = { path="../nu-plugin", version = "0.59.1" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.59.1", features = ["plugin"]}
|
||||
nu-plugin = { path="../nu-plugin", version = "0.60.0" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.60.0", features = ["plugin"]}
|
||||
|
@ -4,14 +4,14 @@ description = "A git status plugin for Nushell"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
name = "nu_plugin_gstat"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
nu-plugin = { path="../nu-plugin", version = "0.59.1" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.59.1" }
|
||||
nu-engine = { path="../nu-engine", version = "0.59.1" }
|
||||
nu-plugin = { path="../nu-plugin", version = "0.60.0" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.60.0" }
|
||||
nu-engine = { path="../nu-engine", version = "0.60.0" }
|
||||
|
||||
git2 = "0.13.24"
|
||||
|
13
crates/nu_plugin_gstat/README.md
Normal file
13
crates/nu_plugin_gstat/README.md
Normal file
@ -0,0 +1,13 @@
|
||||
# Git stat plugin for Nushell
|
||||
|
||||
Note: this requires Nushell 0.60 or later
|
||||
|
||||
To install:
|
||||
|
||||
```
|
||||
> cargo install --path .
|
||||
```
|
||||
|
||||
To register (from inside Nushell):
|
||||
```
|
||||
> register <path to installed plugin> --encoding capnp
|
@ -1,6 +1,6 @@
|
||||
use nu_plugin::{serve_plugin, CapnpSerializer};
|
||||
use nu_plugin::{serve_plugin, JsonSerializer};
|
||||
use nu_plugin_gstat::GStat;
|
||||
|
||||
fn main() {
|
||||
serve_plugin(&mut GStat::new(), CapnpSerializer {})
|
||||
serve_plugin(&mut GStat::new(), JsonSerializer {})
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ impl Plugin for GStat {
|
||||
fn signature(&self) -> Vec<Signature> {
|
||||
vec![Signature::build("gstat")
|
||||
.desc("Get the git status of a repo")
|
||||
.optional("path", SyntaxShape::String, "path to repo")
|
||||
.optional("path", SyntaxShape::Filepath, "path to repo")
|
||||
.category(Category::Custom("Prompt".to_string()))]
|
||||
}
|
||||
|
||||
|
@ -4,13 +4,13 @@ description = "A version incrementer plugin for Nushell"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
name = "nu_plugin_inc"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
nu-plugin = { path="../nu-plugin", version = "0.59.1" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.59.1", features = ["plugin"]}
|
||||
nu-plugin = { path="../nu-plugin", version = "0.60.0" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.60.0", features = ["plugin"]}
|
||||
|
||||
semver = "0.11.0"
|
||||
|
13
crates/nu_plugin_inc/README.md
Normal file
13
crates/nu_plugin_inc/README.md
Normal file
@ -0,0 +1,13 @@
|
||||
# Incrementor plugin for Nushell
|
||||
|
||||
Note: this requires Nushell 0.60 or later
|
||||
|
||||
To install:
|
||||
|
||||
```
|
||||
> cargo install --path .
|
||||
```
|
||||
|
||||
To register (from inside Nushell):
|
||||
```
|
||||
> register <path to installed plugin> --encoding json
|
@ -1,5 +1,5 @@
|
||||
use nu_plugin::LabeledError;
|
||||
use nu_protocol::{Span, Value};
|
||||
use nu_protocol::{ast::CellPath, Span, Value};
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub enum Action {
|
||||
@ -17,6 +17,7 @@ pub enum SemVerAction {
|
||||
#[derive(Default)]
|
||||
pub struct Inc {
|
||||
pub error: Option<String>,
|
||||
pub cell_path: Option<CellPath>,
|
||||
pub action: Option<Action>,
|
||||
}
|
||||
|
||||
@ -83,6 +84,26 @@ impl Inc {
|
||||
}
|
||||
|
||||
pub fn inc(&self, head: Span, value: &Value) -> Result<Value, LabeledError> {
|
||||
if let Some(cell_path) = &self.cell_path {
|
||||
let working_value = value.clone();
|
||||
let cell_value = working_value.follow_cell_path(&cell_path.members)?;
|
||||
|
||||
let cell_value = self.inc_value(head, &cell_value)?;
|
||||
|
||||
let mut value = value.clone();
|
||||
value
|
||||
.update_data_at_cell_path(&cell_path.members, cell_value)
|
||||
.map_err(|x| {
|
||||
let error: LabeledError = x.into();
|
||||
error
|
||||
})?;
|
||||
Ok(value)
|
||||
} else {
|
||||
self.inc_value(head, value)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn inc_value(&self, head: Span, value: &Value) -> Result<Value, LabeledError> {
|
||||
match value {
|
||||
Value::Int { val, span } => Ok(Value::Int {
|
||||
val: val + 1,
|
||||
|
@ -1,6 +1,6 @@
|
||||
use nu_plugin::{serve_plugin, CapnpSerializer};
|
||||
use nu_plugin::{serve_plugin, JsonSerializer};
|
||||
use nu_plugin_inc::Inc;
|
||||
|
||||
fn main() {
|
||||
serve_plugin(&mut Inc::new(), CapnpSerializer {})
|
||||
serve_plugin(&mut Inc::new(), JsonSerializer {})
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
use crate::inc::SemVerAction;
|
||||
use crate::Inc;
|
||||
use nu_plugin::{EvaluatedCall, LabeledError, Plugin};
|
||||
use nu_protocol::{Signature, Value};
|
||||
use nu_protocol::{ast::CellPath, Signature, SyntaxShape, Value};
|
||||
|
||||
impl Plugin for Inc {
|
||||
fn signature(&self) -> Vec<Signature> {
|
||||
vec![Signature::build("inc")
|
||||
.desc("Increment a value or version. Optionally use the column of a table.")
|
||||
.optional("cell_path", SyntaxShape::CellPath, "cell path to update")
|
||||
.switch(
|
||||
"major",
|
||||
"increment the major version (eg 1.2.1 -> 2.0.0)",
|
||||
@ -34,6 +35,10 @@ impl Plugin for Inc {
|
||||
return Ok(Value::Nothing { span: call.head });
|
||||
}
|
||||
|
||||
let cell_path: Option<CellPath> = call.opt(0)?;
|
||||
|
||||
self.cell_path = cell_path;
|
||||
|
||||
if call.has_flag("major") {
|
||||
self.for_semver(SemVerAction::Major);
|
||||
}
|
||||
|
@ -4,15 +4,15 @@ description = "A set of query commands for Nushell"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
name = "nu_plugin_query"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
nu-plugin = { path="../nu-plugin", version = "0.59.1" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.59.1" }
|
||||
nu-engine = { path="../nu-engine", version = "0.59.1" }
|
||||
nu-plugin = { path="../nu-plugin", version = "0.60.0" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.60.0" }
|
||||
nu-engine = { path="../nu-engine", version = "0.60.0" }
|
||||
gjson = "0.8.0"
|
||||
scraper = "0.12.0"
|
||||
sxd-document = "0.3.2"
|
||||
|
13
crates/nu_plugin_query/README.md
Normal file
13
crates/nu_plugin_query/README.md
Normal file
@ -0,0 +1,13 @@
|
||||
# Query plugin for Nushell
|
||||
|
||||
Note: this requires Nushell 0.60 or later
|
||||
|
||||
To install:
|
||||
|
||||
```
|
||||
> cargo install --path .
|
||||
```
|
||||
|
||||
To register (from inside Nushell):
|
||||
```
|
||||
> register <path to installed plugin> --encoding capnp
|
@ -1,6 +1,6 @@
|
||||
use nu_plugin::{serve_plugin, CapnpSerializer};
|
||||
use nu_plugin::{serve_plugin, JsonSerializer};
|
||||
use nu_plugin_query::Query;
|
||||
|
||||
fn main() {
|
||||
serve_plugin(&mut Query {}, CapnpSerializer {})
|
||||
serve_plugin(&mut Query {}, JsonSerializer {})
|
||||
}
|
||||
|
@ -4,18 +4,18 @@ description = "A plugin to display charts"
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
name = "nu_plugin_chart"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
nu-data = { path="../nu-data", version = "0.59.1" }
|
||||
nu-errors = { path="../nu-errors", version = "0.59.1" }
|
||||
nu-plugin = { path="../nu-plugin", version = "0.59.1" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.59.1" }
|
||||
nu-source = { path="../nu-source", version = "0.59.1" }
|
||||
nu-value-ext = { path="../nu-value-ext", version = "0.59.1" }
|
||||
nu-data = { path="../nu-data", version = "0.60.0" }
|
||||
nu-errors = { path="../nu-errors", version = "0.60.0" }
|
||||
nu-plugin = { path="../nu-plugin", version = "0.60.0" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.60.0" }
|
||||
nu-source = { path="../nu-source", version = "0.60.0" }
|
||||
nu-value-ext = { path="../nu-value-ext", version = "0.60.0" }
|
||||
|
||||
crossterm = "0.19.0"
|
||||
tui = { version="0.15.0", default-features=false, features=["crossterm"] }
|
||||
|
@ -4,7 +4,7 @@ description = "A converter plugin to the bson format for Nushell"
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
name = "nu_plugin_from_bson"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
@ -12,9 +12,9 @@ doctest = false
|
||||
[dependencies]
|
||||
bigdecimal = { package = "bigdecimal", version = "0.3.0", features = ["serde"] }
|
||||
bson = { version = "2.0.1", features = [ "chrono-0_4" ] }
|
||||
nu-errors = { path="../nu-errors", version = "0.59.1" }
|
||||
nu-plugin = { path="../nu-plugin", version = "0.59.1" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.59.1" }
|
||||
nu-source = { path="../nu-source", version = "0.59.1" }
|
||||
nu-errors = { path="../nu-errors", version = "0.60.0" }
|
||||
nu-plugin = { path="../nu-plugin", version = "0.60.0" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.60.0" }
|
||||
nu-source = { path="../nu-source", version = "0.60.0" }
|
||||
|
||||
[build-dependencies]
|
||||
|
@ -4,16 +4,16 @@ description = "A converter plugin to the mp4 format for Nushell"
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
name = "nu_plugin_from_mp4"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
nu-errors = { path="../nu-errors", version = "0.59.1" }
|
||||
nu-plugin = { path="../nu-plugin", version = "0.59.1" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.59.1" }
|
||||
nu-source = { path="../nu-source", version = "0.59.1" }
|
||||
nu-errors = { path="../nu-errors", version = "0.60.0" }
|
||||
nu-plugin = { path="../nu-plugin", version = "0.60.0" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.60.0" }
|
||||
nu-source = { path="../nu-source", version = "0.60.0" }
|
||||
tempfile = "3.2.0"
|
||||
mp4 = "0.9.0"
|
||||
|
||||
|
@ -4,17 +4,17 @@ description = "A converter plugin to the bson format for Nushell"
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
name = "nu_plugin_from_sqlite"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
bigdecimal = { package = "bigdecimal", version = "0.3.0", features = ["serde"] }
|
||||
nu-errors = { path="../nu-errors", version = "0.59.1" }
|
||||
nu-plugin = { path="../nu-plugin", version = "0.59.1" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.59.1" }
|
||||
nu-source = { path="../nu-source", version = "0.59.1" }
|
||||
nu-errors = { path="../nu-errors", version = "0.60.0" }
|
||||
nu-plugin = { path="../nu-plugin", version = "0.60.0" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.60.0" }
|
||||
nu-source = { path="../nu-source", version = "0.60.0" }
|
||||
tempfile = "3.2.0"
|
||||
|
||||
[dependencies.rusqlite]
|
||||
|
@ -4,17 +4,17 @@ description = "An S3 plugin for Nushell"
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
name = "nu_plugin_s3"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
futures = { version="0.3.12", features=["compat", "io-compat"] }
|
||||
nu-errors = { path="../nu-errors", version = "0.59.1" }
|
||||
nu-plugin = { path="../nu-plugin", version = "0.59.1" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.59.1" }
|
||||
nu-source = { path="../nu-source", version = "0.59.1" }
|
||||
nu-errors = { path="../nu-errors", version = "0.60.0" }
|
||||
nu-plugin = { path="../nu-plugin", version = "0.60.0" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.60.0" }
|
||||
nu-source = { path="../nu-source", version = "0.60.0" }
|
||||
s3handler = "0.7.5"
|
||||
|
||||
[build-dependencies]
|
||||
|
@ -4,17 +4,17 @@ description = "A plugin to open files/URLs directly from Nushell"
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
name = "nu_plugin_start"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
glob = "0.3.0"
|
||||
nu-errors = { path="../nu-errors", version = "0.59.1" }
|
||||
nu-plugin = { path="../nu-plugin", version = "0.59.1" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.59.1" }
|
||||
nu-source = { path="../nu-source", version = "0.59.1" }
|
||||
nu-errors = { path="../nu-errors", version = "0.60.0" }
|
||||
nu-plugin = { path="../nu-plugin", version = "0.60.0" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.60.0" }
|
||||
nu-source = { path="../nu-source", version = "0.60.0" }
|
||||
url = "2.2.0"
|
||||
webbrowser = "0.5.5"
|
||||
|
||||
@ -22,5 +22,5 @@ webbrowser = "0.5.5"
|
||||
open = "1.4.0"
|
||||
|
||||
[build-dependencies]
|
||||
nu-errors = { version = "0.59.1", path="../nu-errors" }
|
||||
nu-source = { version = "0.59.1", path="../nu-source" }
|
||||
nu-errors = { version = "0.60.0", path="../nu-errors" }
|
||||
nu-source = { version = "0.60.0", path="../nu-source" }
|
||||
|
@ -4,17 +4,17 @@ description = "A converter plugin to the bson format for Nushell"
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
name = "nu_plugin_to_bson"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
bson = { version = "2.0.1", features = [ "chrono-0_4" ] }
|
||||
nu-errors = { path="../nu-errors", version = "0.59.1" }
|
||||
nu-plugin = { path="../nu-plugin", version = "0.59.1" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.59.1" }
|
||||
nu-source = { path="../nu-source", version = "0.59.1" }
|
||||
nu-errors = { path="../nu-errors", version = "0.60.0" }
|
||||
nu-plugin = { path="../nu-plugin", version = "0.60.0" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.60.0" }
|
||||
nu-source = { path="../nu-source", version = "0.60.0" }
|
||||
num-traits = "0.2.14"
|
||||
|
||||
[features]
|
||||
|
@ -4,17 +4,17 @@ description = "A converter plugin to the SQLite format for Nushell"
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
name = "nu_plugin_to_sqlite"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
hex = "0.4.2"
|
||||
nu-errors = { path="../nu-errors", version = "0.59.1" }
|
||||
nu-plugin = { path="../nu-plugin", version = "0.59.1" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.59.1" }
|
||||
nu-source = { path="../nu-source", version = "0.59.1" }
|
||||
nu-errors = { path="../nu-errors", version = "0.60.0" }
|
||||
nu-plugin = { path="../nu-plugin", version = "0.60.0" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.60.0" }
|
||||
nu-source = { path="../nu-source", version = "0.60.0" }
|
||||
tempfile = "3.2.0"
|
||||
|
||||
[dependencies.rusqlite]
|
||||
|
@ -4,16 +4,16 @@ description = "Tree viewer plugin for Nushell"
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
name = "nu_plugin_tree"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
derive-new = "0.5.8"
|
||||
nu-errors = { path="../nu-errors", version = "0.59.1" }
|
||||
nu-plugin = { path="../nu-plugin", version = "0.59.1" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.59.1" }
|
||||
nu-errors = { path="../nu-errors", version = "0.60.0" }
|
||||
nu-plugin = { path="../nu-plugin", version = "0.60.0" }
|
||||
nu-protocol = { path="../nu-protocol", version = "0.60.0" }
|
||||
ptree = { version = "0.4.0", default-features = false }
|
||||
|
||||
|
||||
|
@ -1,103 +0,0 @@
|
||||
# Environment Variables (addition explaining the Values part)
|
||||
|
||||
(this is supposed to go to the Environment book chapter)
|
||||
|
||||
## Environment Variables Are Values
|
||||
|
||||
Since Nushell extends the idea of classic shells "Everything is a text" into "Everything is a structured data", it feels natural to apply this philosophy to environment variables as well.
|
||||
In Nushell, environment variables can hold any value, not just a string.
|
||||
|
||||
Since the host environment (i.e., the OS Nushell is running in) treats environment variables as strings, we need a way to convert them between strings and arbitrary values seamlessly.
|
||||
In general, there are two places when Nushell needs to interact with the host environment:
|
||||
1. On startup, Nushell inherits the host environment variables.
|
||||
2. When running an external program that is not part of Nushell's commands, the program expects environment variables to be strings.
|
||||
3. When an environment variable is passed to an extenal library in the Nushell's codebase (this includes plugins as well). These variables are listed later in this section.
|
||||
|
||||
## Configuration
|
||||
|
||||
By default, if you do not configure anything, all environment variables are imported as strings on startup and then directly passed to any external program we might be spawning.
|
||||
However, you can configure selected any environment variable to be converted to/from any value:
|
||||
|
||||
```
|
||||
# config.nu
|
||||
|
||||
let config = {
|
||||
... other config ...
|
||||
env_conversions: {
|
||||
FOO: {
|
||||
from_string: {|s| $s | split row ':' }
|
||||
to_string: {|v| $v | str collect ':' }
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The above snippet will configure Nushell to run the `from_string` block with the `FOO` environment variable value as an argument on startup.
|
||||
Whenever we run some external tool, the `to_string` block will be called with `FOO` as the argument and the result passed to the tool.
|
||||
You can test the conversions by manually calling them:
|
||||
|
||||
```
|
||||
> let-env FOO = "a:b:c"
|
||||
|
||||
> let list = (do $config.env_conversions.from_string $env.FOO)
|
||||
|
||||
> $list
|
||||
╭───┬───╮
|
||||
│ 0 │ a │
|
||||
│ 1 │ b │
|
||||
│ 2 │ c │
|
||||
╰───┴───╯
|
||||
|
||||
> do $config.env_conversions.to_string $list
|
||||
a:b:c
|
||||
```
|
||||
|
||||
To verify the conversion works on startup, you can first set up `FOO`, then launch a new instance of Nushell (denoted as `>>`):
|
||||
```
|
||||
> let-env FOO = "a:b:c"
|
||||
|
||||
> nu
|
||||
|
||||
>> $env.FOO
|
||||
╭───┬───╮
|
||||
│ 0 │ a │
|
||||
│ 1 │ b │
|
||||
│ 2 │ c │
|
||||
╰───┴───╯
|
||||
```
|
||||
|
||||
To verify we're sending the correct value to an external tool, we would need to make a small program or script that prints its environment variables.
|
||||
This is not hard, but we have a built-in command `env` to help.
|
||||
Let's continue the previous session:
|
||||
|
||||
```
|
||||
>> env
|
||||
╭────┬───────────────────┬───────────────┬───────────────────┬───────────────────╮
|
||||
│ # │ name │ type │ value │ raw │
|
||||
├────┼───────────────────┼───────────────┼───────────────────┼───────────────────┤
|
||||
│ 0 │ ... │ ... │ ... │ ... │
|
||||
│ X │ FOO │ list<unknown> │ [list 3 items] │ a:b:c │
|
||||
│ Y │ ... │ ... │ ... │ ... │
|
||||
╰────┴───────────────────┴───────────────┴───────────────────┴───────────────────╯
|
||||
```
|
||||
|
||||
The `env` command will print every environment variable, its value and a type and also the translated value as a string under the `raw` column.
|
||||
The `raw` values is the values external tools will see when spawned from Nushell.
|
||||
|
||||
## Special Variables
|
||||
|
||||
Out of the box, Nushell ships with several environment variables serving a special purpose:
|
||||
* `PROMPT_COMMAND` (block): To set the prompt. Every time Nushell REPL enters a new line, it will run the block stored as its value and set the result as the prompt.
|
||||
* `PATH`/`Path`: Not yet used except passthrough to externals but is planned to support both its string and list forms.
|
||||
* `LS_COLORS`: Sets up file coloring rules when running `ls` or `grid`. Supports `env_conversions` settings.
|
||||
|
||||
|
||||
## Breaking Changes
|
||||
|
||||
* Setting environment variable to `$nothing` will no longer remove it -- it will be `$nothing`. Instead, you can use `hide $env.FOO`.
|
||||
* `$env.PROMPT_COMMAND` is a block instead of a string containing the source of the command to run. You can put this into your `config.nu`, for example: `let-env PROMPT_COMMAND = { echo "foo" }`.
|
||||
|
||||
## Future Directions
|
||||
|
||||
* We might add default conversion of PATH/Path environment variables between a list and a string.
|
||||
* We can make Nushell recognize both PATH and Path (and throw an error if they are both set and have different values?).
|
@ -1,356 +0,0 @@
|
||||
# Modules and Overlays
|
||||
|
||||
Similar to many other programming languages, Nushell also has modules that let you import custom commands into a current scope.
|
||||
However, since Nushell is also a shell, modules allow you to import environment variables which can be used to conveniently activate/deactivate various environments.
|
||||
|
||||
## Basics
|
||||
|
||||
A simple module can be defined like this:
|
||||
```
|
||||
> module greetings {
|
||||
export def hello [name: string] {
|
||||
$"hello ($name)!"
|
||||
}
|
||||
|
||||
export def hi [where: string] {
|
||||
$"hi ($where)!"
|
||||
}
|
||||
}
|
||||
```
|
||||
We defined `hello` and `hi` custom commands inside a `greetings` module.
|
||||
The `export` keyword makes it possible to later import the commands from the module.
|
||||
The collection of exported symbols from a module is called an **overlay**.
|
||||
You can say that the module `greetings` exports an overlay which consists of two custom commands "hello" and "hi".
|
||||
|
||||
By itself, the module does not do anything.
|
||||
We can verify its existence by printing all available overlays:
|
||||
```
|
||||
> $nu.scope.overlays
|
||||
╭───┬───────────╮
|
||||
│ 0 │ greetings │
|
||||
╰───┴───────────╯
|
||||
```
|
||||
|
||||
To actually use its custom commands, we can call `use`:
|
||||
```
|
||||
> use greetings
|
||||
|
||||
> greetings hello "world"
|
||||
hello world!
|
||||
|
||||
> greetings hi "there"
|
||||
hi there!
|
||||
```
|
||||
The `hello` and `hi` commands are now available with the `greetings` prefix.
|
||||
|
||||
In general, anything after the `use` keyword forms an **import pattern** which controls how the symbols are imported.
|
||||
The import pattern can be one of the following
|
||||
* Module name (just `greetings`):
|
||||
* Imports all symbols with the module name as a prefix
|
||||
* Module name + command name (`greetings hello`):
|
||||
* Import only the selected command into the current scope
|
||||
* Module name + list of names (`greetings [ hello, hi ]`):
|
||||
* Import only the listed commands into the current scope
|
||||
* Module name + everything (`greetings *`):
|
||||
* Imports all names directly into the current scope
|
||||
|
||||
We saw the first one already. Let's try the other ones:
|
||||
```
|
||||
> use greetings hello
|
||||
|
||||
> hello "world"
|
||||
hello world!
|
||||
|
||||
> hi "there" # fails because we brought only 'hello'
|
||||
```
|
||||
```
|
||||
> use greetings [ hello hi ]
|
||||
|
||||
> hello "world"
|
||||
hello world!
|
||||
|
||||
> hi "there"
|
||||
hi there:
|
||||
```
|
||||
```
|
||||
> use greetings *
|
||||
|
||||
> hello "world"
|
||||
hello world!
|
||||
|
||||
> hi "there"
|
||||
hi there!
|
||||
```
|
||||
|
||||
## File as a Module
|
||||
|
||||
Typing the module definition to the command line can be tedious.
|
||||
You could save the module code into a script and `source` it.
|
||||
However, there is another way that lets Nushell implicitly treat a source file as a module.
|
||||
Let's start by saving the body of the module definition into a file:
|
||||
```
|
||||
# greetings.nu
|
||||
|
||||
export def hello [name: string] {
|
||||
$"hello ($name)!"
|
||||
}
|
||||
|
||||
export def hi [where: string] {
|
||||
$"hi ($where)!"
|
||||
}
|
||||
```
|
||||
|
||||
Now, you can use `use` directly on the file:
|
||||
```
|
||||
> use greetings.nu
|
||||
|
||||
> greetings hello "world"
|
||||
hello world!
|
||||
|
||||
> greetings hi "there"
|
||||
hi there!
|
||||
```
|
||||
|
||||
Nushell automatically infers the module's name from the base name of the file ("greetings" without the ".nu" extension).
|
||||
You can use any import patterns as described above with the file name instead of the module name.
|
||||
|
||||
## Local Custom Commands
|
||||
|
||||
Any custom commands defined in a module without the `export` keyword will work only in the module's scope:
|
||||
```
|
||||
# greetings.nu
|
||||
|
||||
export def hello [name: string] {
|
||||
greetings-helper "hello" "world"
|
||||
}
|
||||
|
||||
export def hi [where: string] {
|
||||
greetings-helper "hi" "there"
|
||||
}
|
||||
|
||||
def greetings-helper [greeting: string, subject: string] {
|
||||
$"($greeting) ($subject)!"
|
||||
}
|
||||
```
|
||||
Then, in Nushell we import all definitions from the "greetings.nu":
|
||||
```
|
||||
> use greetings.nu *
|
||||
|
||||
> hello "world"
|
||||
hello world!
|
||||
|
||||
> hi "there"
|
||||
hi there!
|
||||
|
||||
> greetings-helper "foo" "bar" # fails because 'greetings-helper' is not exported
|
||||
```
|
||||
|
||||
## Environment Variables
|
||||
|
||||
So far we used modules just to import custom commands.
|
||||
It is possible to export environment variables the same way.
|
||||
The syntax is slightly different than what you might be used to from commands like `let-env` or `load-env`:
|
||||
```
|
||||
# greetings.nu
|
||||
|
||||
export env MYNAME { "Arthur, King of the Britons" }
|
||||
|
||||
export def hello [name: string] {
|
||||
$"hello ($name)"
|
||||
}
|
||||
```
|
||||
`use` works the same way as with custom commands:
|
||||
```
|
||||
> use greetings.nu
|
||||
|
||||
> $env."greetings MYNAME"
|
||||
Arthur, King of the Britons
|
||||
|
||||
> greetings hello $env."greetings MYNAME"
|
||||
hello Arthur, King of the Britons!
|
||||
```
|
||||
|
||||
You can notice we do not assign the value to `MYNAME` directly.
|
||||
Instead, we give it a block of code (`{ ...}`) that gets evaluated every time we call `use`.
|
||||
We can demonstrate this property for example with the `random` command:
|
||||
```
|
||||
> module roll { export env ROLL { random dice | into string } }
|
||||
|
||||
> use roll ROLL
|
||||
|
||||
> $env.ROLL
|
||||
4
|
||||
|
||||
> $env.ROLL
|
||||
4
|
||||
|
||||
> use roll ROLL
|
||||
|
||||
> $env.ROLL
|
||||
6
|
||||
|
||||
> $env.ROLL
|
||||
6
|
||||
```
|
||||
|
||||
## Hiding
|
||||
|
||||
Any custom command or environment variable, imported from a module or not, can be "hidden", restoring the previous definition.
|
||||
We do this with the `hide` command:
|
||||
```
|
||||
> def foo [] { "foo" }
|
||||
|
||||
> foo
|
||||
foo
|
||||
|
||||
> hide foo
|
||||
|
||||
> foo # error! command not found!
|
||||
```
|
||||
|
||||
The `hide` command also accepts import patterns, just like `use`.
|
||||
The import pattern is interpreted slightly differently, though.
|
||||
It can be one of the following:
|
||||
* Module, custom command, or environment variable name (just `foo` or `greetings`):
|
||||
* If the name is a custom command or an environment variable, hides it directly. Otherwise:
|
||||
* If the name is a module name, hides all of its overlay prefixed with the module name
|
||||
* Module name + name (`greetings hello`):
|
||||
* Hides only the prefixed command / environment variable
|
||||
* Module name + list of names (`greetings [ hello, hi ]`):
|
||||
* Hides only the prefixed commands / environment variables
|
||||
* Module name + everything (`greetings *`):
|
||||
* Hides the whole module's overlay, without the prefix
|
||||
|
||||
Let's show these with examples.
|
||||
We saw direct hiding of a custom command already.
|
||||
Let's try environment variables:
|
||||
```
|
||||
> let-env FOO = "FOO"
|
||||
|
||||
> $env.FOO
|
||||
FOO
|
||||
|
||||
> hide FOO
|
||||
|
||||
> $env.FOO # error! environment variable not found!
|
||||
```
|
||||
The first case also applies to commands / environment variables brought from a module (using the "greetings.nu" file defined above):
|
||||
```
|
||||
> use greetings.nu *
|
||||
|
||||
> $env.MYNAME
|
||||
Arthur, King of the Britons
|
||||
|
||||
> hello "world"
|
||||
hello world!
|
||||
|
||||
> hide MYNAME
|
||||
|
||||
> $env.MYNAME # error! environment variable not found!
|
||||
|
||||
> hide hello
|
||||
|
||||
> hello "world" # error! command not found!
|
||||
```
|
||||
And finally, when the name is the module name (assuming the previous `greetings` module):
|
||||
```
|
||||
> use greetings.nu
|
||||
|
||||
> $env."greetings MYNAME"
|
||||
Arthur, King of the Britons
|
||||
|
||||
> greetings hello "world"
|
||||
hello world!
|
||||
|
||||
> hide greetings
|
||||
|
||||
> $env."greetings MYNAME" # error! environment variable not found!
|
||||
|
||||
> greetings hello "world" # error! command not found!
|
||||
```
|
||||
|
||||
To demonstrate the other cases (again, assuming the same `greetings` module):
|
||||
```
|
||||
> use greetings.nu
|
||||
|
||||
> hide greetings hello
|
||||
|
||||
> $env."greetings MYNAME"
|
||||
Arthur, King of the Britons
|
||||
|
||||
> greetings hello "world" # error! command not found!
|
||||
```
|
||||
```
|
||||
> use greetings.nu
|
||||
|
||||
> hide greetings [ hello MYNAME ]
|
||||
|
||||
> $env."greetings MYNAME" # error! environment variable not found!
|
||||
|
||||
> greetings hello "world" # error! command not found!
|
||||
```
|
||||
```
|
||||
> use greetings.nu
|
||||
|
||||
> hide greetings *
|
||||
|
||||
> $env."greetings MYNAME" # error! environment variable not found!
|
||||
|
||||
> greetings hello "world" # error! command not found!
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
You can find an example config setup at https://github.com/nushell/nu_scripts/tree/main/engine-q/example-config.
|
||||
It creates the `$config` variable using the module system.
|
||||
|
||||
## Known Issues
|
||||
|
||||
* It might be more appropriate to use `$nu.scope.modules` instead of `$nu.scope.overlays`
|
||||
|
||||
## Future Design Ideas
|
||||
|
||||
The future paragraphs describe some ideas
|
||||
|
||||
### Exporting aliases
|
||||
|
||||
We should allow exporting aliases as it is a common tool for creating shell environments alongside environment variables.
|
||||
We need to decide a proper syntax.
|
||||
|
||||
### Recursive modules
|
||||
|
||||
We should allow using modules within modules.
|
||||
That is, allowing to use `use` (and `hide`?) within the `module name { ... }` block or a module file.
|
||||
This leads to a more generic question of having some standard project layout.
|
||||
|
||||
### Renaming imports
|
||||
|
||||
To avoid name clashing.
|
||||
For example: `use dataframe as df`.
|
||||
|
||||
### Dynamic names for environment variables
|
||||
|
||||
The `load-env` command exists because we needed to define the environment variable name at runtime.
|
||||
Currently, both `let-env` and `export env` require static environment variable names.
|
||||
Could we allow them to accept an expression in place of the name?
|
||||
For example `export env (whoami | str screaming-snake-case).0 { "foo" }` or `let-env (whoami | str screaming-snake-case).0 = "foo"`
|
||||
|
||||
### To Source or Not To Source
|
||||
|
||||
Currently, there are two ways to define a module in a file:
|
||||
Write the literal `module name { ... }` into a file, use `source` run the file, then `use` to import from the module.
|
||||
The second way is to use the `use name.nu` directly, which does not require the `module name { ... }` wrapper.
|
||||
We can keep it as it is, or push into one of the following directions:
|
||||
|
||||
1. Rename `source` to `run` and modify it so that it runs in its own scope. Any modifications would be lost, it would be more like running a custom command. This would make it impossible for a random script to modify your environment since the only way to do that would be with the module files and the `use` command. The disadvantage is that it makes it impossible to have "startup scripts" and places some roadblocks to the user experience.
|
||||
2. Remove `use` and rely on `source` and `module name { ... }` only. This resembles, e.g., Julia's `include(file.jl)` style and makes it quite intuitive. It is not very "pure" or "secure" as dedicated module files with `use`.
|
||||
|
||||
We might explore these as we start creating bigger programs and get a feel how a Nushell project structure could look like (and whether or not we should try to enforce one).
|
||||
|
||||
## Unlikely Design Ideas
|
||||
|
||||
### Exporting variables
|
||||
|
||||
`export var name { ... }` which would export a variable the same way you export environment variable.
|
||||
This would allow for defining global constants in a module (think `math PI`) but can lead to bugs overwriting existing variables.
|
||||
Use custom commands instead: `export def PI [] { 3.14159 }`.
|
@ -1,141 +0,0 @@
|
||||
# Docker Guide
|
||||
|
||||
| tag | base image | plugins | package manager | libs & bins | size |
|
||||
| ------------------ | -------------------- | ------- | --------------- | ---------------------------------------------------------------- | ----------- |
|
||||
| `latest`, `debian` | `debian:latest` | yes | apt | **a lot**, including _glibc_ | ~(48+62) MB |
|
||||
| `slim` | `debian:stable-slim` | yes | apt | all `nu:debian` image but exclude [this list][.slimify-excludes] | ~(26+62) MB |
|
||||
| `alpine` | `alpine:latest` | yes | apk | all `nu:musl-busybox` image + libcrypto, libssl, libtls, libz | ~(3+61) MB |
|
||||
| `musl-busybox` | `busybox:musl` | no | — | GNU utils + _musl_ | ~(1+16) MB |
|
||||
| `glibc-busybox` | `busybox:glibc` | no | — | GNU utils + _glibc_ | ~(3+17) MB |
|
||||
| `musl-distroless` | `distroless/static` | no | — | see [here][distroless/base] | ~(2+16) MB |
|
||||
| `glibc-distroless` | `distroless/cc` | no | — | `distroless/static` with _glibc_ | ~(17+17) MB |
|
||||
| `glibc` | `scratch` | no | — | **only `nu` binary-executable** which depend on glibc runtime | ~17 MB |
|
||||
| `musl` | `scratch` | no | — | **only `nu` binary-executable** statically linked to musl | ~16 MB |
|
||||
|
||||
[.slimify-excludes]: https://github.com/debuerreotype/debuerreotype/blob/master/scripts/.slimify-excludes
|
||||
[distroless/base]: https://github.com/GoogleContainerTools/distroless/blob/master/base/README.md
|
||||
|
||||
## Image Variants
|
||||
|
||||
### `nu:<version>`
|
||||
|
||||
This is the defacto image. If you are unsure about what your needs are, you probably want to use this one. It is designed to be used both as a throw away container (mount your source code and start the container to start your app), as well as the base to build other images off of.
|
||||
|
||||
<details><summary>example</summary>
|
||||
|
||||
Let say you create a plugin in Rust.
|
||||
|
||||
- create a Dockerfile in your root project
|
||||
|
||||
```dockerfile
|
||||
FROM nu:0.2
|
||||
|
||||
COPY /target/debug/nu_plugin_cowsay /bin/
|
||||
ENTRYPOINT ["nu"]
|
||||
```
|
||||
|
||||
- build your project first then run it via docker
|
||||
|
||||
```bash
|
||||
cargo build
|
||||
docker run -it .
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### `nu:<version>-slim`
|
||||
|
||||
This image does not contain the common packages contained in the default tag and only contains the minimal packages needed to run `nu`. Unless you are working in an environment where only the `nu` image will be deployed and you have space constraints, it's highly recommended to use the alpine image if you aim for small image size. Only use this image if you really need **both** `glibc` and small image size.
|
||||
|
||||
### `nu:<version>-alpine`
|
||||
|
||||
This image is based on the popular [Alpine Linux project](https://alpinelinux.org/), available in [the alpine official image][alpine]. Alpine Linux is much smaller than most distribution base images (~5MB), and thus leads to much slimmer images in general.
|
||||
|
||||
This variant is highly recommended when final image size being as small as possible is desired. The main caveat to note is that it does use `musl` libc instead of `glibc` and friends, so certain software might run into issues depending on the depth of their libc requirements. However, most software doesn't have an issue with this, so this variant is usually a very safe choice. See [this Hacker News comment thread](https://news.ycombinator.com/item?id=10782897) for more discussion of the issues that might arise and some pro/con comparisons of using Alpine-based images.
|
||||
|
||||
To minimize image size, it's uncommon for additional related tools (such as `git` or `bash`) to be included in Alpine-based images. Using this image as a base, add the things you need in your own Dockerfile (see the [alpine image description][alpine] for examples of how to install packages if you are unfamiliar).
|
||||
|
||||
### `nu:<version>-<libc-variant>`
|
||||
|
||||
This image is based on [`scratch`](https://hub.docker.com/_/scratch) which doesn't create an extra layer. This variants can be handy in a project that uses multiple programming language as you need a lot of tools. By using this in [multi-stage build][], you can slim down the docker image that need to be pulled.
|
||||
|
||||
[multi-stage build]: https://docs.docker.com/develop/develop-images/multistage-build/
|
||||
|
||||
<details><summary>example</summary>
|
||||
|
||||
- using `glibc` variant
|
||||
|
||||
```dockerfile
|
||||
FROM nu:0.2-glibc as shell
|
||||
FROM node:slim
|
||||
|
||||
# Build your plugins
|
||||
|
||||
COPY --from=shell /bin/nu /bin/
|
||||
# Something else
|
||||
ENTRYPOINT ["nu"]
|
||||
```
|
||||
|
||||
- using `musl` variant
|
||||
|
||||
```dockerfile
|
||||
FROM nu:musl as shell
|
||||
FROM go:alpine
|
||||
|
||||
# Build your plugins
|
||||
|
||||
COPY --from=shell /bin/nu /bin/
|
||||
# Something else
|
||||
ENTRYPOINT ["nu"]
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### `nu:<version>-<libc-variant>-distroless`
|
||||
|
||||
This image is base on [Distroless](https://github.com/GoogleContainerTools/distroless) which usually to contain only your application and its runtime dependencies. This image do not contain package managers, shells or any other programs you would expect to find in a standard Linux distribution except for nushell itself. All distroless variant always contains:
|
||||
|
||||
- ca-certificates
|
||||
- A /etc/passwd entry for a root user
|
||||
- A /tmp directory
|
||||
- tzdata
|
||||
|
||||
As for `glibc-distroless` variant, it **adds**:
|
||||
- glibc
|
||||
- libssl
|
||||
- openssl
|
||||
|
||||
> Most likely you want to use this in CI/CD environment for plugins that can be statically compiled.
|
||||
|
||||
<details><summary>example</summary>
|
||||
|
||||
```dockerfile
|
||||
FROM nu:musl-distroless
|
||||
|
||||
COPY target/x86_64-unknown-linux-musl/release/nu_plugin_* /bin/
|
||||
ENTRYPOINT ["nu"]
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### `nu:<version>-<libc-variant>-busybox`
|
||||
|
||||
This image is based on [Busybox](https://www.busybox.net/) which is a very good ingredient to craft space-efficient distributions. It combines tiny versions of many common UNIX utilities into a single small executable. It also provides replacements for most of the utilities you usually find in GNU fileutils, shellutils, etc. The utilities in BusyBox generally have fewer options than their full-featured GNU cousins; however, the options that are included provide the expected functionality and behave very much like their GNU counterparts. Basically, this image provides a fairly complete environment for any small or embedded system.
|
||||
|
||||
> Use this only if you need common utilities like `tar`, `awk`, and many more but don't want extra blob like nushell plugins and others.
|
||||
|
||||
<details><summary>example</summary>
|
||||
|
||||
```dockerfile
|
||||
FROM nu:0.2-glibc-busybox
|
||||
|
||||
ADD https://github.com/user/repo/releases/download/latest/nu_plugin_cowsay.tar.gz /tmp/
|
||||
RUN tar xzfv nu_plugin_cowsay.tar.gz -C /bin --strip=1 nu_plugin_cowsay
|
||||
|
||||
ENTRYPOINT ["nu"]
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
[musl]: https://www.musl-libc.org/
|
||||
[alpine]: https://hub.docker.com/_/alpine/
|
@ -1,9 +0,0 @@
|
||||
# how to compile without OpenSSL
|
||||
|
||||
You may find it desirable to compile nu shell without requiring an OpenSSL installation on your system.
|
||||
|
||||
You can do this by running:
|
||||
```sh
|
||||
cargo build --no-default-features --features=rustyline-support
|
||||
```
|
||||
|
@ -1,39 +0,0 @@
|
||||
# How To Port Old Engine Syntax to the Latest and Greatest
|
||||
|
||||
## engine-p
|
||||
|
||||
Even in the new codebase of nu things change and we have some old code to clean up.
|
||||
This guide walks you through how to port old engine syntax to engine-p.
|
||||
|
||||
1. change into the commands source directory
|
||||
|
||||
```sh
|
||||
cd crates/nu-command/src/
|
||||
```
|
||||
|
||||
2. search for old syntax using ripgrep (`rg`)
|
||||
|
||||
```sh
|
||||
rg --type rust --files-with-matches 'ActionStream|run_with_actions'
|
||||
```
|
||||
|
||||
3. update the old syntax engine-p syntax
|
||||
- For a smaller example PR see [#3794](https://github.com/nushell/nushell/pull/3794/files)
|
||||
- For a more involved example PR see [#3649](https://github.com/nushell/nushell/pull/3649/files)
|
||||
|
||||
In many cases this is changing the function name and signature.
|
||||
The function name goes from `run_with_actions` to `run`.
|
||||
The signature goes from `Result<ActionStream, ShellError>`
|
||||
to `Result<OutputStream, ShellError>`.
|
||||
|
||||
Sometimes you cannot alter the signature because the command
|
||||
still requires working with `ActionStream`.
|
||||
[open](https://github.com/nushell/nushell/blob/28db8022fef7c1f7f44f6e50d07d3f42773deddf/crates/nu-command/src/commands/filesystem/open.rs) is one example.
|
||||
|
||||
4. commit changes, run the tests, filtered by the command package and section name:
|
||||
|
||||
```sh
|
||||
cargo test --features=extra -p nu-command string
|
||||
```
|
||||
|
||||
5. PR and bask in the glory of the nu-and-improved codebase.
|
@ -1,270 +0,0 @@
|
||||
# Implementing a Command
|
||||
|
||||
We will be learning how to write a command and see what's required to do so in small steps. For this example we are interested writing a command named `take-two` that takes two lucky values coming in.
|
||||
|
||||
Let's generate a table with row literal syntax first, like so:
|
||||
|
||||
```
|
||||
> echo [[repository, LOC]; [nushell, 11161984] [scripts, 500] [nushell_book, 200]]
|
||||
──────────────┬──────────
|
||||
repository │ LOC
|
||||
──────────────┼──────────
|
||||
nushell │ 11161984
|
||||
scripts │ 500
|
||||
nushell_book │ 200
|
||||
──────────────┴──────────
|
||||
```
|
||||
|
||||
_Note: values are passed around in the stream. A generated table like the example above is three row values. See the [values chapter](https://www.nushell.sh/contributor-book/values.html) to learn more about row value types._
|
||||
|
||||
We want to `take-two` rows from the generated table. Here is what we would like to do:
|
||||
|
||||
```
|
||||
> echo [[repository, LOC]; [nushell, 11161984] [scripts, 500] [nushell_book, 200]] | take-two
|
||||
──────────────┬──────────
|
||||
repository │ LOC
|
||||
──────────────┼──────────
|
||||
nushell │ 11161984
|
||||
scripts │ 500
|
||||
──────────────┴──────────
|
||||
```
|
||||
|
||||
See the `take-two` command in the pipeline above? That's what we want.
|
||||
|
||||
Before starting writing the command it's important to understand that everything in the stream are values. Sometimes you will see a table with no columns and the reason is that none of the values coming in are row value types. For this case we call it simply a _list_, like so:
|
||||
|
||||
```
|
||||
> echo [[repository, LOC]; [nushell, 11161984] [scripts, 500] [nushell_book, 200]] | get repository
|
||||
──────────────
|
||||
nushell
|
||||
scripts
|
||||
nushell_book
|
||||
──────────────
|
||||
```
|
||||
|
||||
The example above Nu sees three values of type String (the call `get repository` returns them).
|
||||
|
||||
What happens if the stream has row value types and other value types? Let's find out:
|
||||
|
||||
```
|
||||
> echo [[repository, LOC]; [nushell, 11161984] [scripts, 500] [nushell_book, 200]] | append 10
|
||||
──────────────┬──────────
|
||||
repository │ LOC
|
||||
──────────────┼──────────
|
||||
nushell │ 11161984
|
||||
scripts │ 500
|
||||
nushell_book │ 200
|
||||
──────────────┴──────────
|
||||
────
|
||||
10
|
||||
────
|
||||
```
|
||||
|
||||
When the pipeline finishes, as soon as Nu sees a value that is of type row it will try to display it as a table with columns. The reason is that a value of type row represents rows having column cell headers and cell values.
|
||||
|
||||
We appended the value 10 using `append`. Nu sees **four** values in the stream, **three** of them being row types and **one** being an int value type. Therefore we see a table printed (the three row values) and a list (one int value) from the **stream**. This matters because some commands expect and assume all values coming in are row types and some do not.
|
||||
|
||||
For the command `take-two` we are about to implement we don't care what kind of values are coming in since we just want to **take two** values.
|
||||
|
||||
## Command implementation steps
|
||||
|
||||
To guide us in our command implementation journey we will start registering the command, as we do so we will be driving out the command.
|
||||
|
||||
### Register the command
|
||||
|
||||
All the internal commands reside in `crates/nu-command`. For our command named `take-two` we can create the source file `take_two.rs` and place it in `src/commands/take_two.rs`. Go ahead and create it:
|
||||
|
||||
```
|
||||
> touch crates/nu-command/src/commands/take_two.rs
|
||||
```
|
||||
|
||||
Edit the source file and add the following:
|
||||
|
||||
```rust
|
||||
pub struct Command;
|
||||
```
|
||||
|
||||
Before registering it to the context you need to make it available by declaring the module and re-export it in `crates/nu-command/src/commands.rs`. The commands we write are modules already (`take_two.rs` is the `take_two` module). In case you are not familiar with rust modules [read this refresher](https://doc.rust-lang.org/book/ch07-02-defining-modules-to-control-scope-and-privacy.html). Let's go ahead and declare it and then re-export the command's `Command` struct as `TakeTwo`, like so:
|
||||
|
||||
_nu-command/src/mod.rs_
|
||||
```rust
|
||||
# ...
|
||||
pub(crate) mod take_two;
|
||||
# ...
|
||||
|
||||
# ...
|
||||
pub(crate) use take_two::Command as TakeTwo;
|
||||
# ...
|
||||
```
|
||||
|
||||
We should be ready now to register it. You need to add the command (in this case the struct will be in scope named as `TakeTwo` from the previous snippet) where they are added one by one to the context.
|
||||
|
||||
_src/commands/default_context.rs_
|
||||
```rust
|
||||
context.add_commands(vec![
|
||||
# ...
|
||||
whole_stream_command(TakeTwo),
|
||||
# ...
|
||||
);
|
||||
```
|
||||
|
||||
We will now resort to the rust compiler to make sure things are wired up correctly. Under `crates/nu-command` run:
|
||||
|
||||
```
|
||||
> cargo build
|
||||
Compiling nu-command v0.29.2 (/Users/nu/nushell/crates/nu-command)
|
||||
error[E0277]: the trait bound `take_two::Command: nu_engine::WholeStreamCommand` is not satisfied
|
||||
--> crates/nu-command/src/commands/default_context.rs:13:34
|
||||
|
|
||||
13 | whole_stream_command(TakeTwo),
|
||||
| ^^^^^^^ the trait `nu_engine::WholeStreamCommand` is not implemented for `take_two::Command`
|
||||
|
|
||||
::: /Users/nu/nushell/crates/nu-engine/src/whole_stream_command.rs:273:43
|
||||
|
|
||||
273 | pub fn whole_stream_command(command: impl WholeStreamCommand + 'static) -> Command {
|
||||
| ------------------ required by this bound in `whole_stream_command`
|
||||
|
||||
error[E0277]: the trait bound `take_two::Command: nu_engine::WholeStreamCommand` is not satisfied
|
||||
--> crates/nu-command/src/commands/default_context.rs:13:34
|
||||
|
|
||||
13 | whole_stream_command(TakeTwo),
|
||||
| ^^^^^^^ the trait `nu_engine::WholeStreamCommand` is not implemented for `take_two::Command`
|
||||
|
|
||||
::: /Users/nu/nushell/crates/nu-engine/src/whole_stream_command.rs:273:43
|
||||
|
|
||||
273 | pub fn whole_stream_command(command: impl WholeStreamCommand + 'static) -> Command {
|
||||
| ------------------ required by this bound in `whole_stream_command`
|
||||
|
||||
error: aborting due to previous error
|
||||
```
|
||||
|
||||
That's not certainly what we expected.
|
||||
|
||||
It happens that Nu needs to know more about the command, including it's name and signature. We didn't do any of that and the compiler is telling us so. We seem to be missing implementing the `WholeStreamCommand` trait. This is the trait that, when implemented, allows us to state it's name, signature, and the like.
|
||||
|
||||
## WholeStreamCommand
|
||||
|
||||
Every internal command must implement the `WholeStreamCommand` trait. Let's take a look at the required functions:
|
||||
|
||||
```rust
|
||||
pub trait WholeStreamCommand: Send + Sync {
|
||||
fn name(&self) -> &str;
|
||||
fn signature(&self) -> Signature;
|
||||
fn usage(&self) -> &str;
|
||||
}
|
||||
```
|
||||
|
||||
_Note: For simplicity, we've removed the default implementations of the trait. If you want to read more about the trait you [can read the code here](https://github.com/nushell/nushell/blob/e09e3b01d6523309b901fb396b416146b53c2b7f/crates/nu-engine/src/whole_stream_command.rs)_
|
||||
|
||||
We will need to implement the required functions `name` for telling Nu the name of the command, `signature` to tell the command's signature, and `usage`. Before we start, we will also write an example of the usage implementing `examples` (not shown above).
|
||||
|
||||
Ready? Go ahead and edit `crates/nu-command/src/commands/take_two.rs`:
|
||||
|
||||
```rust
|
||||
use crate::prelude::*;
|
||||
use nu_engine::WholeStreamCommand;
|
||||
use nu_protocol::Signature;
|
||||
|
||||
pub struct Command;
|
||||
|
||||
impl WholeStreamCommand for Command {
|
||||
fn name(&self) -> &str {
|
||||
"take-two"
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"takes two values"
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("take-two")
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![
|
||||
Example {
|
||||
description: "Takes two values",
|
||||
example: "echo [11161984 500 200] | take-two",
|
||||
result: None,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Let's try again by running `cargo build`:
|
||||
|
||||
```
|
||||
cargo build
|
||||
Compiling nu-command v0.29.2 (/Users/nu/nushell/crates/nu-command)
|
||||
Finished dev [unoptimized + debuginfo] target(s) in 10.56s
|
||||
```
|
||||
|
||||
Great!
|
||||
|
||||
Since we have been working in `crates/nu-command` and building there to shorten the build time as we work on the command, you may want to run a full build now by doing `cargo build --all --features=extra`:
|
||||
|
||||
Let's try entering `help take-two`:
|
||||
|
||||
```
|
||||
> help take-two
|
||||
takes two values
|
||||
|
||||
Usage:
|
||||
> take-two {flags}
|
||||
|
||||
Flags:
|
||||
-h, --help: Display this help message
|
||||
|
||||
Examples:
|
||||
Takes two values
|
||||
> echo [11161984 500 200] | take-two
|
||||
```
|
||||
|
||||
We get a help description of our newly implemented `take-two` command for free. This works because we implemented `examples`. It's good practice to do so for documentation (and as we will soon see, unit testing) purposes.
|
||||
|
||||
Now let's run `echo [11161984 500 200] | take-two`
|
||||
|
||||
```
|
||||
> echo [11161984 500 200] | take-two
|
||||
error: Error: Unimplemented: take-two does not implement run or run_with_actions
|
||||
```
|
||||
|
||||
That was unexpected. What happened?
|
||||
|
||||
We did not implement `take-two`'s logic anywhere. Nu is telling us the command does not implement `run` or `run_with_actions`. These functions are in the `WholeStreamCommand` trait and the default implementation gives the error. Since our command won't be doing any actions we can go ahead and implement `run` for the logic, let's do that:
|
||||
|
||||
```rust
|
||||
use nu_errors::ShellError;
|
||||
# ...
|
||||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
Ok(args.input.take(2).into_output_stream())
|
||||
}
|
||||
|
||||
# ...
|
||||
```
|
||||
|
||||
Compile and try one more time:
|
||||
|
||||
```
|
||||
> echo [11161984 500 200] | take-two
|
||||
───┬──────────
|
||||
0 │ 11161984
|
||||
1 │ 500
|
||||
───┴──────────
|
||||
```
|
||||
|
||||
Not bad. We created first a list of int values and took two of them. Let's create row type values and take two of them now:
|
||||
|
||||
```
|
||||
> echo [[LOC]; [11161984] [500] [200]] | take-two
|
||||
───┬──────────
|
||||
# │ LOC
|
||||
───┼──────────
|
||||
0 │ 11161984
|
||||
1 │ 500
|
||||
───┴──────────
|
||||
```
|
||||
|
||||
The command is ready.
|
@ -1,32 +0,0 @@
|
||||
# Philosophy
|
||||
|
||||
> This document contains philosophical notes about nu.
|
||||
|
||||
## Bare Words
|
||||
|
||||
In Nu, bare words work the same way they do in most shells.
|
||||
|
||||
In most shells, bare words serve two purposes:
|
||||
|
||||
```bash
|
||||
$ ls
|
||||
# ^^ the name of a command
|
||||
$ cat Cargo.toml
|
||||
# ^^^^^^^^^^ a string
|
||||
```
|
||||
|
||||
Nu adopts this shell idiom.
|
||||
|
||||
Consequences:
|
||||
|
||||
- Bare words cannot also refer to variables. Variable names are prefixed with `$`.
|
||||
- Bare words, in almost all contexts, cannot be keywords.
|
||||
- Numbers and operators aren't bare words.
|
||||
|
||||
## One Screen
|
||||
|
||||
The utility of a command's output drops off extremely rapidly after a full screen of content.
|
||||
|
||||
By default, Nu prefers to present output that can fit into a screen rather than more complete output that spans many screens.
|
||||
|
||||
For example, this is the rationale for `ls` returning a flat table containing the files in the current directory, rather than presenting a tree of data by default.
|
@ -2,7 +2,7 @@
|
||||
authors = ["Nu authors"]
|
||||
edition = "2018"
|
||||
name = "wasm"
|
||||
version = "0.59.1"
|
||||
version = "0.60.0"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
Loading…
Reference in New Issue
Block a user