Skip to content

Commit

Permalink
change options priority
Browse files Browse the repository at this point in the history
  • Loading branch information
SandrineP committed Jan 29, 2025
1 parent 7ed2b6e commit 7f0708a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
34 changes: 21 additions & 13 deletions libmamba/src/api/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ namespace mamba
{
struct list_options
{
bool full_name;
bool no_pip;
bool reverse;
bool explicit_;
bool md5;
bool canonical;
bool full_name = false;
bool no_pip = false;
bool reverse = false;
bool explicit_ = false;
bool md5 = false;
bool canonical = false;
};

struct formatted_pkg
{
std::string name, version, build, channel, url, md5, build_string;
std::string name, version, build, channel, url, md5, build_string, platform;
};

bool compare_alphabetically(const formatted_pkg& a, const formatted_pkg& b)
Expand Down Expand Up @@ -169,6 +169,7 @@ namespace mamba
obj["channel"] = get_formatted_channel(pkg_info, channels.front());
obj["base_url"] = get_base_url(pkg_info, channels.front());
obj["url"] = pkg_info.package_url;
obj["md5"] = pkg_info.md5;
obj["build_number"] = pkg_info.build_number;
obj["build_string"] = pkg_info.build_string;
obj["dist_name"] = pkg_info.str();
Expand Down Expand Up @@ -203,6 +204,7 @@ namespace mamba
formatted_pkgs.url = package.second.package_url;
formatted_pkgs.md5 = package.second.md5;
formatted_pkgs.build_string = package.second.build_string;
formatted_pkgs.platform = package.second.platform;
packages.push_back(formatted_pkgs);
}
}
Expand All @@ -212,15 +214,13 @@ namespace mamba
std::sort(packages.begin(), packages.end(), comparator);

// format and print output
if (options.canonical)
if (options.explicit_)
{
for (auto p : packages)
if (options.canonical)
{
std::cout << p.name << "-" << p.version << "-" << p.build_string << std::endl;
std::cout << "Warning: Option --canonical ignored because of --explicit \n"
<< std::endl;
}
}
else if (options.explicit_)
{
for (auto p : packages)
{
if (options.md5)
Expand All @@ -233,6 +233,14 @@ namespace mamba
}
}
}
else if (options.canonical)
{
for (auto p : packages)
{
std::cout << p.channel << "/" << p.platform << "::" << p.name << "-"
<< p.version << "-" << p.build_string << std::endl;
}
}
else
{
auto requested_specs = prefix_data.history().get_requested_specs_map();
Expand Down
8 changes: 5 additions & 3 deletions micromamba/src/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ init_list_parser(CLI::App* subcom, Configuration& config)
);
subcom->add_flag("--md5", md5.get_cli_config<bool>(), md5.description());

auto& canonical = config.insert(Configurable("canonical", false)
.group("cli")
.description("Output canonical names of packages only."));
auto& canonical = config.insert(
Configurable("canonical", false)
.group("cli")
.description("Output canonical names of packages only. Ignored if --explicit.")
);
subcom->add_flag("-c,--canonical", canonical.get_cli_config<bool>(), canonical.description());
}

Expand Down
5 changes: 3 additions & 2 deletions micromamba/tests/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ def test_list_canonical(

outputs_list = res.strip().split("\n")[2:]
if canonical_flag == "--canonical":
items = ["conda-forge", "/", " "]
items = ["conda-forge/", "::"]
for output in outputs_list:
assert all(i not in output for i in items)
assert all(i in output for i in items)
assert " " not in output


@pytest.mark.parametrize("quiet_flag", ["", "-q", "--quiet"])
Expand Down

0 comments on commit 7f0708a

Please sign in to comment.