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-03 22:47:27 +0300
commitade62fc67c5d182bfbc7dd431c6700d5309c58d1 (patch)
treee9cc365af3358b156b198b199e3b74ca51a85a5f
parent111e48efa35a8112311ec3745f4bb5ddbb7731e0 (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--meson.build2
-rw-r--r--mu/mu-options.cc14
2 files changed, 16 insertions, 0 deletions
diff --git a/meson.build b/meson.build
index fd6d51c..3b555cc 100644
--- a/meson.build
+++ b/meson.build
@@ -116,6 +116,8 @@ endforeach
if cc.has_function('wordexp')
config_h_data.set('HAVE_WORDEXP_H',1)
+else
+ message('no wordexp, no command-line option expansion')
endif
testmaildir=join_paths(meson.current_source_dir(), 'lib', 'tests')
diff --git a/mu/mu-options.cc b/mu/mu-options.cc
index a9f3a05..f96487a 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"
@@ -183,6 +184,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
*/