Skip to content

Commit

Permalink
[cli] Don't remove alias dir on unalias --all.
Browse files Browse the repository at this point in the history
  • Loading branch information
luis4a0 committed Jun 15, 2022
1 parent dc0f4b3 commit 71096c7
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/client/cli/cmd/unalias.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,7 @@ mp::ReturnCode cmd::Unalias::run(mp::ArgParser* parser)
return parser->returnCodeFrom(ret);
}

if (parser->isSet(all_option_name))
{
aliases.clear();

QDir alias_dir = MP_PLATFORM.get_alias_scripts_folder();
alias_dir.removeRecursively();
}
else
if (!parser->isSet(all_option_name))
{
std::vector<std::string> bad_aliases;

Expand All @@ -62,18 +55,18 @@ mp::ReturnCode cmd::Unalias::run(mp::ArgParser* parser)

return ReturnCode::CommandLineError;
}
}

for (const auto& alias_to_remove : aliases_to_remove)
for (const auto& alias_to_remove : aliases_to_remove)
{
aliases.remove_alias(alias_to_remove); // We know removal won't fail because the alias exists.
try
{
aliases.remove_alias(alias_to_remove); // We know removal won't fail because the alias exists.
try
{
MP_PLATFORM.remove_alias_script(alias_to_remove);
}
catch (std::runtime_error& e)
{
cerr << fmt::format("Warning: '{}' when removing alias script for {}\n", e.what(), alias_to_remove);
}
MP_PLATFORM.remove_alias_script(alias_to_remove);
}
catch (std::runtime_error& e)
{
cerr << fmt::format("Warning: '{}' when removing alias script for {}\n", e.what(), alias_to_remove);
}
}

Expand Down Expand Up @@ -110,9 +103,16 @@ mp::ParseCode cmd::Unalias::parse_args(mp::ArgParser* parser)
if (parse_code != ParseCode::Ok)
return parse_code;

if (!parser->isSet(all_option_name))
if (parser->isSet(all_option_name))
{
for (auto definition_it = aliases.cbegin(); definition_it != aliases.cend(); ++definition_it)
aliases_to_remove.push_back(definition_it->first);
}
else
{
for (const auto& arg : parser->positionalArguments())
aliases_to_remove.push_back(arg.toStdString());
}

return ParseCode::Ok;
}

0 comments on commit 71096c7

Please sign in to comment.