nushell/crates/nu-command/tests/commands
Andrés N. Robalino 9d8845d7ad
Allow custom lib dir path for sourcing nu script libraries. (#3940)
Given we can write nu scripts. As the codebase grows, splitting into many smaller nu scripts is necessary.

In general, when we work with paths and files we seem to face quite a few difficulties. Here we just tackle one of them and it involves sourcing
files that also source other nu files and so forth. The current working directory becomes important here and being on a different directory
when sourcing scripts will not work. Mostly because we expand the path on the current working directory and parse the files when a source command
call is done.

For the moment, we introduce a `lib_dirs` configuration value and, unfortunately, introduce a new dependency in `nu-parser` (`nu-data`) to get
a handle of the configuration file to retrieve it. This should give clues and ideas as the new parser engine continues (introduce a way to also know paths)

With this PR we can do the following:

Let's assume we want to write a nu library called `my_library`. We will have the code in a directory called `project`: The file structure will looks like this:

```
project/my_library.nu
project/my_library/hello.nu
project/my_library/name.nu
```

This "pattern" works well, that is, when creating a library have a directory named `my_library` and next to it a `my_library.nu` file. Filling them like this:

```

source my_library/hello.nu
source my_library/name.nu
```

```

def hello [] {
  "hello world"
}
```

```

def name [] {
  "Nu"
end
```

Assuming this `project` directory is stored at `/path/to/lib/project`, we can do:

```
config set lib_dirs ['path/to/lib/project']
```

Given we have this `lib_dirs` configuration value, we can be anywhere while using Nu and do the following:

```
source my_library.nu

echo (hello) (name)

```
2021-08-26 02:04:04 -05:00
..
hash_ Improve md5 and sha256 code (#3841) 2021-07-29 10:22:16 -05:00
keep nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
math Fixed panic on math with large durations (#3669) 2021-06-23 15:44:14 +12:00
move_ nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
path Move path handling to nu-path (#3653) 2021-06-20 11:07:26 +12:00
pathvar Fix clippy lint and disable broken lint (#3865) 2021-07-30 08:11:47 +12:00
random Rename count to length (#3166) 2021-03-14 10:46:40 +13:00
skip nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
str_ remove str from (#3500) 2021-05-27 12:18:02 -05:00
all.rs Add named positionals to all (#3863) 2021-07-30 09:12:24 +12:00
any.rs Fix issue in external subexpression paths (#3642) 2021-06-18 07:59:58 +12:00
append.rs Fix issue in external subexpression paths (#3642) 2021-06-18 07:59:58 +12:00
cal.rs Rename count to length (#3166) 2021-03-14 10:46:40 +13:00
cd.rs Remove dir-s/ectories/ectories-support features (#3647) 2021-06-19 11:29:29 +12:00
compact.rs Rename count to length (#3166) 2021-03-14 10:46:40 +13:00
config.rs Relax groups and blocks to output at pipeline level (#3643) 2021-06-18 13:04:51 +12:00
cp.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
def.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
default.rs Rename count to length (#3166) 2021-03-14 10:46:40 +13:00
drop.rs Rename count to length (#3166) 2021-03-14 10:46:40 +13:00
each.rs Simplify expressions (#3389) 2021-05-12 13:01:48 +12:00
echo.rs RangeIterator can also go down (#2913) 2021-01-13 08:27:54 +13:00
empty.rs Fix #3582 (#3583) 2021-06-09 18:07:54 +12:00
enter.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
every.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
first.rs Rename count to length (#3166) 2021-03-14 10:46:40 +13:00
flatten.rs Simplify expressions (#3389) 2021-05-12 13:01:48 +12:00
format.rs standardize on how to get file size (#2992) 2021-02-03 07:19:38 -06:00
get.rs Fix warnings for Rust 1.51 (#3214) 2021-03-26 21:26:57 +13:00
group_by.rs Rename count to length (#3166) 2021-03-14 10:46:40 +13:00
headers.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
help.rs Rename count to length (#3166) 2021-03-14 10:46:40 +13:00
histogram.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
insert.rs Rename the use of invocation to subexpression (#3568) 2021-06-07 20:08:35 +12:00
into_int.rs Simplify expressions (#3389) 2021-05-12 13:01:48 +12:00
last.rs Rename count to length (#3166) 2021-03-14 10:46:40 +13:00
length.rs Rename count to length (#3166) 2021-03-14 10:46:40 +13:00
lines.rs Rename count to length (#3166) 2021-03-14 10:46:40 +13:00
ls.rs Output error when ls into a file without permission (#3218) 2021-03-31 19:52:39 +13:00
merge.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
mkdir.rs Rename count to length (#3166) 2021-03-14 10:46:40 +13:00
mod.rs Allow source to accept paths with emojis (#3939) 2021-08-19 19:06:18 +12:00
nth.rs Rename count to length (#3166) 2021-03-14 10:46:40 +13:00
open.rs imp: bump rustyline to 8.0.0 (#3167) 2021-03-14 15:13:31 +13:00
parse.rs Commands to engine (#3448) 2021-05-22 10:52:04 -05:00
prepend.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
range.rs Negative indexing for range (#3427) 2021-05-17 15:08:47 +12:00
reduce.rs remove str from (#3500) 2021-05-27 12:18:02 -05:00
rename.rs Fix warnings for Rust 1.51 (#3214) 2021-03-26 21:26:57 +13:00
reverse.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
rm.rs Resolve issues with rm * globbing (#3516) 2021-05-30 15:36:36 +12:00
roll.rs Simplify expressions (#3389) 2021-05-12 13:01:48 +12:00
rotate.rs 90 degree table rotations (clockwise and counter-clockwise) (#3086) 2021-02-22 06:56:34 -05:00
save.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
select.rs Rename count to length (#3166) 2021-03-14 10:46:40 +13:00
semicolon.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
sort_by.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
source.rs Allow custom lib dir path for sourcing nu script libraries. (#3940) 2021-08-26 02:04:04 -05:00
split_by.rs Rename count to length (#3166) 2021-03-14 10:46:40 +13:00
split_column.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
split_row.rs Rename count to length (#3166) 2021-03-14 10:46:40 +13:00
touch.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
uniq.rs #3385: Add unique option for uniq command (#3754) 2021-07-10 07:27:35 +12:00
update.rs Rename the use of invocation to subexpression (#3568) 2021-06-07 20:08:35 +12:00
where_.rs Rename count to length (#3166) 2021-03-14 10:46:40 +13:00
which.rs Rename count to length (#3166) 2021-03-14 10:46:40 +13:00
with_env.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
wrap.rs nu-cli refactor moving commands into their own crate nu-command (#2910) 2021-01-12 17:59:53 +13:00
zip.rs The zip command. (#3919) 2021-08-14 23:36:08 -05:00