From ade62fc67c5d182bfbc7dd431c6700d5309c58d1 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Wed, 2 Aug 2023 21:17:45 +0300 Subject: [PATCH] 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. --- meson.build | 2 ++ mu/mu-options.cc | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/meson.build b/meson.build index fd6d51c5..3b555cc3 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 a9f3a05a..f96487a6 100644 --- a/mu/mu-options.cc +++ b/mu/mu-options.cc @@ -43,6 +43,7 @@ #include #include +#include #include #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 */