-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate the plugin in favour of a radically simpler module implementation.
- Loading branch information
1 parent
e1e410a
commit 87a4ad9
Showing
7 changed files
with
332 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
export def main [ | ||
path?: string | ||
--export: list | ||
--shellvars (-s) | ||
--fn (-f): list | ||
] { | ||
let fn_args = if ($fn | is-not-empty) { | ||
['--shellfns' ($fn | str join ',')] | ||
} else { | ||
[] | ||
} | ||
|
||
let path_args = if $path != null { | ||
[($path | path expand)] | ||
} else { | ||
[] | ||
} | ||
|
||
let raw = ($in | str join "\n") | bash-env-json ...($fn_args ++ $path_args) | from json | ||
|
||
let error = $raw | get -i error | ||
if $error != null { | ||
error make { msg: $error } | ||
} | ||
|
||
if ($export | is-not-empty) { | ||
print "warning: --export is deprecated, use --shellvars(-s) instead" | ||
let exported_shellvars = ($raw.shellvars | select -i ...$export) | ||
$raw.env | merge ($exported_shellvars) | ||
} else if $shellvars or ($fn | is-not-empty) { | ||
$raw | ||
} else { | ||
$raw.env | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use std assert | ||
|
||
# TODO use testing.nu testing module, | ||
# which wasn't working at the time I wrote these tests | ||
|
||
#[test] | ||
def test_shell_variables [] { | ||
let actual = (echo "A=123" | bash-env -s).shellvars | ||
let expected = { A: "123" } | ||
assert equal $actual $expected | ||
} | ||
|
||
#[test] | ||
def test_shell_variables_from_file [] { | ||
let actual = bash-env -s tests/shell-variables.env | ||
let expected = { shellvars: { A: "not exported" } env: { B: "exported" } } | ||
assert equal $actual $expected | ||
} | ||
|
||
#[test] | ||
def test_shell_functions [] { | ||
let actual = bash-env -f [f2 f3] tests/shell-functions.env | ||
let expected = { | ||
"env": { | ||
"B": "1", | ||
"A": "1" | ||
}, | ||
"shellvars": {}, | ||
"fn": { | ||
"f2": { | ||
"env": { | ||
"B": "2", | ||
"A": "2" | ||
}, | ||
"shellvars": { | ||
"C2": "I am shell variable C2" | ||
} | ||
}, | ||
"f3": { | ||
"env": { | ||
"B": "3", | ||
"A": "3" | ||
}, | ||
"shellvars": { | ||
"C3": "I am shell variable C3" | ||
} | ||
} | ||
} | ||
} | ||
assert equal $actual $expected | ||
} | ||
|
||
export def main [] { | ||
test_shell_variables | ||
test_shell_variables_from_file | ||
test_shell_functions | ||
|
||
print "All tests passed" | ||
} |
Oops, something went wrong.