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.
This commit is contained in:
Dirk-Jan C. Binnema
2023-08-02 21:17:45 +03:00
parent 111e48efa3
commit ade62fc67c
2 changed files with 16 additions and 0 deletions

View File

@ -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
*/