Repository: reubeno/brush (rust)

Issue:
Implement builtin `readarray` as wrapper over `mapfile`
Per documentation, `readarray` basically seems to be an alias for `mapfile`, which we already have a partial implementation of.

For the scope of this issue, we should: (1) do some research to see if there *is* a difference in functionality, and (2) wire up `readarray` to call into shared code with `mapfile`. This can be done similar to how we've handled `readonly` being a thin wrapper on `declare`.

We can separately track filling out missing functionality in `mapfile`.

Pull request description:
feat(mapfile): Register also as readarray
Closes #474

Patch:
diff --git a/brush-core/src/builtins/factory.rs b/brush-core/src/builtins/factory.rs
index ee16151..3a401f9 100644
--- a/brush-core/src/builtins/factory.rs
+++ b/brush-core/src/builtins/factory.rs
@@ -283,6 +283,7 @@ pub(crate) fn get_default_builtins(
         m.insert("enable".into(), builtin::<enable::EnableCommand>());
         m.insert("let".into(), builtin::<let_::LetCommand>());
         m.insert("mapfile".into(), builtin::<mapfile::MapFileCommand>());
+        m.insert("readarray".into(), builtin::<mapfile::MapFileCommand>());
         m.insert("printf".into(), builtin::<printf::PrintfCommand>());
         m.insert("shopt".into(), builtin::<shopt::ShoptCommand>());
         m.insert("source".into(), builtin::<dot::DotCommand>().special());
@@ -316,9 +317,6 @@ pub(crate) fn get_default_builtins(
 
         // TODO: implement logout builtin
         m.insert("logout".into(), builtin::<unimp::UnimplementedCommand>());
-
-        // TODO(#474): implement readarray builtin
-        m.insert("readarray".into(), builtin::<unimp::UnimplementedCommand>());
     }
 
     //


Test patch:
diff --git a/brush-shell/tests/cases/builtins/mapfile.yaml b/brush-shell/tests/cases/builtins/mapfile.yaml
index f85e7c2..60e9b18 100644
--- a/brush-shell/tests/cases/builtins/mapfile.yaml
+++ b/brush-shell/tests/cases/builtins/mapfile.yaml
@@ -4,3 +4,7 @@ cases:
     stdin: |
       mapfile -t myarray < /dev/null
       (echo "hello"; echo "there") | (mapfile -t myarray && declare -p myarray)
+  - name: "readarray -t"
+    stdin: |
+      readarray -t myarray < /dev/null
+      (echo "hello"; echo "there") | (readarray -t myarray && declare -p myarray)