summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2023-08-02 21:17:45 +0300
committerDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2023-08-02 21:17:45 +0300
commitc36d30bec25936dd3a6d595d53d6d77c0f1037a8 (patch)
tree4c927446ff20976a61e0b2790bda2d0ef090944d
parentd25d4b0b3611e14e008fb6aab1472208a3778b94 (diff)
options: implement ExpandPath transformer
For expanding shell options (with expand_path / wordexp) Note that e.g. in zsh: --maildir=~/Maildir is handled (program receives --maildir=/home/user/Maildir) but e.g. bash does not do that, and the program receives the literal '~/Maildir' We expanded this in mu earlier, so let's do that again.
-rw-r--r--mu/mu-options.cc14
1 files changed, 14 insertions, 0 deletions
diff --git a/mu/mu-options.cc b/mu/mu-options.cc
index b9637b3..7c33b07 100644
--- a/mu/mu-options.cc
+++ b/mu/mu-options.cc
@@ -43,6 +43,7 @@
#include <unistd.h>
#include <utils/mu-utils.hh>
+#include <utils/mu-utils-file.hh>
#include <utils/mu-error.hh>
#include "utils/mu-test-utils.hh"
#include "mu-options.hh"
@@ -136,6 +137,19 @@ options_map(const IE& ie)
return map;
}
+
+
+// transformers
+
+
+// Expand the path using wordexp
+static const std::function ExpandPath = [](std::string filepath)->std::string {
+ if (auto&& res{expand_path(filepath)}; !res)
+ throw CLI::ValidationError{res.error().what()};
+ else
+ return filepath = std::move(res.value());
+};
+
/*
* common
*/