Skip to content

Commit

Permalink
fix: Output JSON on dry-run
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Jerphanion <[email protected]>
  • Loading branch information
jjerphan committed Nov 22, 2024
1 parent 0ca3312 commit dd00512
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions libmamba/src/api/create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//
// The full license is in the file LICENSE, distributed with this software.

#include <iostream>

#include "mamba/api/configuration.hpp"
#include "mamba/api/create.hpp"
#include "mamba/api/install.hpp"
Expand All @@ -29,6 +31,7 @@ namespace mamba

auto& create_specs = config.at("specs").value<std::vector<std::string>>();
auto& use_explicit = config.at("explicit_install").value<bool>();
auto& json_format = config.at("json").get_cli_config<bool>();

auto channel_context = ChannelContext::make_conda_compatible(ctx);

Expand Down Expand Up @@ -78,6 +81,21 @@ namespace mamba
);
}
}
else
{
if (create_specs.empty() && json_format)
{
// Just print the JSON
nlohmann::json output;
output["actions"]["FETCH"] = nlohmann::json::array();
output["actions"]["PREFIX"] = ctx.prefix_params.target_prefix;
output["dry_run"] = true;
output["prefix"] = ctx.prefix_params.target_prefix;
output["success"] = true;
std::cout << output.dump(2) << std::endl;
}
return;
}

if (ctx.env_lockfile)
{
Expand Down

0 comments on commit dd00512

Please sign in to comment.