Skip to content

Commit

Permalink
fix: Environment removal confirmation (#3450)
Browse files Browse the repository at this point in the history
* fix: Environment removal confirmation

Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>

* Handle empty environment deletion

Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>

* Handle 'n'

Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>

* Reoder logic

Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>

* Use enum class for `RemoveResult`

Co-authored-by: Hind-M <70631848+Hind-M@users.noreply.github.com>

---------

Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
Co-authored-by: Hind-M <70631848+Hind-M@users.noreply.github.com>
  • Loading branch information
jjerphan and Hind-M authored Sep 17, 2024
1 parent af81975 commit 81c099c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
11 changes: 9 additions & 2 deletions libmamba/include/mamba/api/remove.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ namespace mamba
class ChannelContext;
class Configuration;

void remove(Configuration& config, int flags = MAMBA_REMOVE_PRUNE);
enum class RemoveResult : int
{
YES = 0,
NO = 1,
EMPTY = 2,
};

RemoveResult remove(Configuration& config, int flags = MAMBA_REMOVE_PRUNE);

namespace detail
{
void remove_specs(
bool remove_specs(
Context& ctx,
ChannelContext& channel_context,
const std::vector<std::string>& specs,
Expand Down
17 changes: 11 additions & 6 deletions libmamba/src/api/remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace mamba
{
void remove(Configuration& config, int flags)
RemoveResult remove(Configuration& config, int flags)
{
auto& ctx = config.context();

Expand Down Expand Up @@ -56,11 +56,14 @@ namespace mamba

if (!remove_specs.empty())
{
detail::remove_specs(ctx, channel_context, remove_specs, prune, force);
return detail::remove_specs(ctx, channel_context, remove_specs, prune, force)
? RemoveResult::YES
: RemoveResult::NO;
}
else
{
Console::instance().print("Nothing to do.");
return RemoveResult::EMPTY;
}
}

Expand Down Expand Up @@ -108,7 +111,7 @@ namespace mamba

namespace detail
{
void remove_specs(
bool remove_specs(
Context& ctx,
ChannelContext& channel_context,
const std::vector<std::string>& raw_specs,
Expand Down Expand Up @@ -144,10 +147,12 @@ namespace mamba
transaction.log_json();
}

if (transaction.prompt(ctx, channel_context))
auto prompt_entry = transaction.prompt(ctx, channel_context);
if (prompt_entry)
{
transaction.execute(ctx, channel_context, prefix_data);
}
return prompt_entry;
};

if (force)
Expand All @@ -168,7 +173,7 @@ namespace mamba
}
}
auto transaction = MTransaction(ctx, pool, pkgs_to_remove, {}, package_caches);
execute_transaction(transaction);
return execute_transaction(transaction);
}
else
{
Expand Down Expand Up @@ -206,7 +211,7 @@ namespace mamba
package_caches
);

execute_transaction(transaction);
return execute_transaction(transaction);
}
}
}
Expand Down
20 changes: 19 additions & 1 deletion micromamba/src/env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,25 @@ set_env_command(CLI::App* com, Configuration& config)
[&config]
{
// Remove specs if exist
remove(config, MAMBA_REMOVE_ALL);
RemoveResult remove_env_result = remove(config, MAMBA_REMOVE_ALL);

if (remove_env_result == RemoveResult::NO)
{
Console::stream() << "The environment was not removed.";
return;
}

if (remove_env_result == RemoveResult::EMPTY)
{
Console::stream() << "No packages to remove from environment.";

auto res = Console::prompt("Do you want to remove the environment?", 'Y');
if (!res)
{
Console::stream() << "The environment was not removed.";
return;
}
}

const auto& ctx = config.context();
if (!ctx.dry_run)
Expand Down

0 comments on commit 81c099c

Please sign in to comment.