aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlunaphied <lunaphied@lunaphied.me>2024-03-25 14:13:44 +0000
committerGerrit Code Review <gerrit@lix>2024-03-25 14:13:44 +0000
commitd3d7489571baeb651d3843dba3b638621694c174 (patch)
tree2c480e6aae1704384ad66f1b5bd8dd644e7e1e08
parent5a1c35f90756508617b4d694d49c4ac3defff1c5 (diff)
parent185ecf1f45e6bf2198fe9ca3bb7ad175f412a014 (diff)
Merge "Improve new CLI UX by supporting short `-E` flag for `--expr`" into main
-rw-r--r--doc/manual/rl-next/short-expr-flag.md14
-rw-r--r--src/libcmd/installables.cc1
-rw-r--r--src/nix/eval.md4
-rw-r--r--tests/functional/eval.sh1
4 files changed, 18 insertions, 2 deletions
diff --git a/doc/manual/rl-next/short-expr-flag.md b/doc/manual/rl-next/short-expr-flag.md
new file mode 100644
index 000000000..a02c944bd
--- /dev/null
+++ b/doc/manual/rl-next/short-expr-flag.md
@@ -0,0 +1,14 @@
+---
+synopsis: reintroduce shortened `-E` form for `--expr` to new CLI
+# prs: cl 605
+---
+
+In the past, it was possible to supply a shorter `-E` flag instead of fully
+specifying `--expr` every time you wished to provide an expression that would
+be evaluated to produce the given command's input. This was retained for the
+`--file` flag when the new CLI utilities were written with `-f`, but `-E` was
+dropped.
+
+We now restore the `-E` short form for better UX. This is most useful for
+`nix eval` but most any command that takes an Installable argument should benefit
+from it as well.
diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc
index 973db62b0..b40632887 100644
--- a/src/libcmd/installables.cc
+++ b/src/libcmd/installables.cc
@@ -187,6 +187,7 @@ SourceExprCommand::SourceExprCommand()
addFlag({
.longName = "expr",
+ .shortName = 'E',
.description = "Interpret [*installables*](@docroot@/command-ref/new-cli/nix.md#installables) as attribute paths relative to the Nix expression *expr*.",
.category = installablesCategory,
.labels = {"expr"},
diff --git a/src/nix/eval.md b/src/nix/eval.md
index 48d5aa597..d1daaf755 100644
--- a/src/nix/eval.md
+++ b/src/nix/eval.md
@@ -8,10 +8,10 @@ R""(
# nix eval --expr '1 + 2'
```
-* Evaluate a Nix expression to JSON:
+* Evaluate a Nix expression to JSON using the short-form expression flag:
```console
- # nix eval --json --expr '{ x = 1; }'
+ # nix eval --json -E '{ x = 1; }'
{"x":1}
```
diff --git a/tests/functional/eval.sh b/tests/functional/eval.sh
index b81bb1e2c..0e789cc47 100644
--- a/tests/functional/eval.sh
+++ b/tests/functional/eval.sh
@@ -12,6 +12,7 @@ EOF
[[ $testStdinHeredoc == '{ bar = 4; foo = 4; }' ]]
nix eval --expr 'assert 1 + 2 == 3; true'
+nix eval -E 'assert 1 + 2 == 3; true'
[[ $(nix eval int -f "./eval.nix") == 123 ]]
[[ $(nix eval str -f "./eval.nix") == '"foo"' ]]