2012-10-21 14:52:34 +02:00
|
|
|
/*
|
2022-11-16 22:26:29 +01:00
|
|
|
** Copyright (C) 2012-2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
2012-10-21 14:52:34 +02:00
|
|
|
**
|
|
|
|
** This program is free software; you can redistribute it and/or modify it
|
|
|
|
** under the terms of the GNU General Public License as published by the
|
|
|
|
** Free Software Foundation; either version 3, or (at your option) any
|
|
|
|
** later version.
|
|
|
|
**
|
|
|
|
** This program is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with this program; if not, write to the Free Software Foundation,
|
|
|
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2020-06-08 22:04:05 +02:00
|
|
|
#include "mu-cmd.hh"
|
2020-11-07 13:06:23 +01:00
|
|
|
#include "mu-script.hh"
|
2022-11-16 22:26:29 +01:00
|
|
|
#include "utils/mu-utils.hh"
|
2012-10-24 10:23:52 +02:00
|
|
|
|
2020-11-28 09:16:43 +01:00
|
|
|
using namespace Mu;
|
|
|
|
|
2022-11-16 22:26:29 +01:00
|
|
|
Result<void>
|
|
|
|
Mu::mu_cmd_script(const Options& opts)
|
2012-10-21 14:52:34 +02:00
|
|
|
{
|
2022-11-16 22:26:29 +01:00
|
|
|
ScriptPaths paths = { MU_SCRIPTS_DIR };
|
|
|
|
const auto&& scriptinfos{script_infos(paths)};
|
|
|
|
auto script_it = Mu::seq_find_if(scriptinfos, [&](auto&& item) {
|
|
|
|
return item.name == opts.script.name;
|
|
|
|
});
|
2012-10-21 14:52:34 +02:00
|
|
|
|
2022-11-16 22:26:29 +01:00
|
|
|
if (script_it == scriptinfos.cend())
|
2022-05-12 07:48:28 +02:00
|
|
|
return Err(Error::Code::InvalidArgument,
|
2022-11-19 10:16:45 +01:00
|
|
|
"cannot find script '%s'", opts.script.name.c_str());
|
2012-10-21 17:51:14 +02:00
|
|
|
|
2022-11-16 22:26:29 +01:00
|
|
|
std::vector<std::string> params{opts.script.params};
|
|
|
|
if (!opts.muhome.empty()) {
|
|
|
|
params.emplace_back("--muhome");
|
|
|
|
params.emplace_back(opts.muhome);
|
2012-10-21 17:51:14 +02:00
|
|
|
}
|
2012-10-21 14:52:34 +02:00
|
|
|
|
2022-11-16 22:26:29 +01:00
|
|
|
// won't return unless there's an error.
|
|
|
|
return run_script(script_it->path, opts.script.params);
|
2012-10-21 14:52:34 +02:00
|
|
|
}
|