Skip to content

Commit

Permalink
Merge pull request #1406 from wolfv/prefix_command
Browse files Browse the repository at this point in the history
add live stream and use prefix_command to get all remaining args
  • Loading branch information
wolfv authored Jan 27, 2022
2 parents 8a1acef + 3a86778 commit 2143dcf
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions micromamba/src/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,43 @@ set_run_command(CLI::App* subcom)
{
init_prefix_options(subcom);

static std::vector<std::string> command;
static bool live_stream = true;
subcom->add_flag("--live-stream", live_stream, "Display output live");

subcom->add_option(
"executable_call",
command,
"Executable name, with additional arguments to be passed to the executable on invocation");
static std::vector<std::string> command;
subcom->prefix_command();

subcom->callback([]() {
subcom->callback([subcom]() {
auto& config = Configuration::instance();
config.load();

std::vector<std::string> command = subcom->remaining();

auto [wrapped_command, script_file]
= prepare_wrapped_call(Context::instance().target_prefix, command);

LOG_DEBUG << "Running wrapped script " << join(" ", command);
std::string out, err;
auto [_, ec] = reproc::run(wrapped_command,
reproc::options(),
reproc::sink::string(out),
reproc::sink::string(err));

if (ec)
std::string out, err;
if (!live_stream)
{
auto [_, ec] = reproc::run(wrapped_command,
reproc::options(),
reproc::sink::string(out),
reproc::sink::string(err));
if (ec)
{
std::cerr << ec.message() << std::endl;
}
}
else
{
std::cerr << ec.message() << std::endl;
auto [_, ec] = reproc::run(wrapped_command, reproc::options());

if (ec)
{
std::cerr << ec.message() << std::endl;
}
}
});
}

0 comments on commit 2143dcf

Please sign in to comment.