mirror of https://github.com/mamba-org/mamba.git
feat: add export flag to list command (#3780)
This commit is contained in:
parent
09f87f1031
commit
b5e197fc14
|
@ -28,6 +28,7 @@ namespace mamba
|
||||||
bool explicit_ = false;
|
bool explicit_ = false;
|
||||||
bool md5 = false;
|
bool md5 = false;
|
||||||
bool canonical = false;
|
bool canonical = false;
|
||||||
|
bool export_ = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct formatted_pkg
|
struct formatted_pkg
|
||||||
|
@ -218,7 +219,13 @@ namespace mamba
|
||||||
{
|
{
|
||||||
if (options.canonical)
|
if (options.canonical)
|
||||||
{
|
{
|
||||||
LOG_WARNING << "Option --canonical ignored because of --explicit";
|
LOG_WARNING
|
||||||
|
<< "Option --canonical ignored because --explicit was also provided.";
|
||||||
|
}
|
||||||
|
if (options.export_)
|
||||||
|
{
|
||||||
|
LOG_WARNING
|
||||||
|
<< "Option --export ignored because --explicit was also provided.";
|
||||||
}
|
}
|
||||||
for (auto p : packages)
|
for (auto p : packages)
|
||||||
{
|
{
|
||||||
|
@ -234,12 +241,24 @@ namespace mamba
|
||||||
}
|
}
|
||||||
else if (options.canonical)
|
else if (options.canonical)
|
||||||
{
|
{
|
||||||
|
if (options.export_)
|
||||||
|
{
|
||||||
|
LOG_WARNING
|
||||||
|
<< "Option --export ignored because --canonical was also provided.";
|
||||||
|
}
|
||||||
for (auto p : packages)
|
for (auto p : packages)
|
||||||
{
|
{
|
||||||
std::cout << p.channel << "/" << p.platform << "::" << p.name << "-"
|
std::cout << p.channel << "/" << p.platform << "::" << p.name << "-"
|
||||||
<< p.version << "-" << p.build_string << std::endl;
|
<< p.version << "-" << p.build_string << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (options.export_)
|
||||||
|
{
|
||||||
|
for (auto p : packages)
|
||||||
|
{
|
||||||
|
std::cout << p.name << "=" << p.version << "=" << p.build_string << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto requested_specs = prefix_data.history().get_requested_specs_map();
|
auto requested_specs = prefix_data.history().get_requested_specs_map();
|
||||||
|
@ -285,6 +304,7 @@ namespace mamba
|
||||||
options.explicit_ = config.at("explicit").value<bool>();
|
options.explicit_ = config.at("explicit").value<bool>();
|
||||||
options.md5 = config.at("md5").value<bool>();
|
options.md5 = config.at("md5").value<bool>();
|
||||||
options.canonical = config.at("canonical").value<bool>();
|
options.canonical = config.at("canonical").value<bool>();
|
||||||
|
options.export_ = config.at("export").value<bool>();
|
||||||
|
|
||||||
auto channel_context = ChannelContext::make_conda_compatible(config.context());
|
auto channel_context = ChannelContext::make_conda_compatible(config.context());
|
||||||
detail::list_packages(config.context(), regex, channel_context, std::move(options));
|
detail::list_packages(config.context(), regex, channel_context, std::move(options));
|
||||||
|
|
|
@ -53,9 +53,19 @@ init_list_parser(CLI::App* subcom, Configuration& config)
|
||||||
auto& canonical = config.insert(
|
auto& canonical = config.insert(
|
||||||
Configurable("canonical", false)
|
Configurable("canonical", false)
|
||||||
.group("cli")
|
.group("cli")
|
||||||
.description("Output canonical names of packages only. Ignored if --explicit.")
|
.description("Output canonical names of packages only. Ignored if --explicit is also provided."
|
||||||
|
)
|
||||||
);
|
);
|
||||||
subcom->add_flag("-c,--canonical", canonical.get_cli_config<bool>(), canonical.description());
|
subcom->add_flag("-c,--canonical", canonical.get_cli_config<bool>(), canonical.description());
|
||||||
|
|
||||||
|
auto& export_ = config.insert(
|
||||||
|
Configurable("export", false)
|
||||||
|
.group("cli")
|
||||||
|
.description(
|
||||||
|
"Output explicit, machine-readable requirement strings instead of human-readable lists of packages. Ignored if --explicit or --canonical is also provided."
|
||||||
|
)
|
||||||
|
);
|
||||||
|
subcom->add_flag("-e,--export", export_.get_cli_config<bool>(), export_.description());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -82,6 +82,7 @@ def test_list_no_json(
|
||||||
@pytest.mark.parametrize("explicit_flag", ["", "--explicit"])
|
@pytest.mark.parametrize("explicit_flag", ["", "--explicit"])
|
||||||
@pytest.mark.parametrize("md5_flag", ["", "--md5"])
|
@pytest.mark.parametrize("md5_flag", ["", "--md5"])
|
||||||
@pytest.mark.parametrize("canonical_flag", ["", "-c", "--canonical"])
|
@pytest.mark.parametrize("canonical_flag", ["", "-c", "--canonical"])
|
||||||
|
@pytest.mark.parametrize("export_flag", ["", "-e", "--export"])
|
||||||
@pytest.mark.parametrize("env_selector", ["", "name", "prefix"])
|
@pytest.mark.parametrize("env_selector", ["", "name", "prefix"])
|
||||||
@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True)
|
@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True)
|
||||||
def test_list_subcommands(
|
def test_list_subcommands(
|
||||||
|
@ -93,15 +94,22 @@ def test_list_subcommands(
|
||||||
explicit_flag,
|
explicit_flag,
|
||||||
md5_flag,
|
md5_flag,
|
||||||
canonical_flag,
|
canonical_flag,
|
||||||
|
export_flag,
|
||||||
):
|
):
|
||||||
if env_selector == "prefix":
|
if env_selector == "prefix":
|
||||||
res = helpers.umamba_list("-p", tmp_xtensor_env, explicit_flag, md5_flag, canonical_flag)
|
res = helpers.umamba_list(
|
||||||
|
"-p", tmp_xtensor_env, explicit_flag, md5_flag, canonical_flag, export_flag
|
||||||
|
)
|
||||||
elif env_selector == "name":
|
elif env_selector == "name":
|
||||||
res = helpers.umamba_list("-n", tmp_env_name, explicit_flag, md5_flag, canonical_flag)
|
res = helpers.umamba_list(
|
||||||
|
"-n", tmp_env_name, explicit_flag, md5_flag, canonical_flag, export_flag
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
res = helpers.umamba_list(explicit_flag, md5_flag, canonical_flag)
|
res = helpers.umamba_list(explicit_flag, md5_flag, canonical_flag, export_flag)
|
||||||
|
|
||||||
outputs_list = res.strip().split("\n")[2:]
|
outputs_list = res.strip().split("\n")[2:]
|
||||||
|
outputs_list = [i for i in outputs_list if i != "" and not i.startswith("Warning")]
|
||||||
|
items = ["conda-forge/", "::"]
|
||||||
if explicit_flag == "--explicit":
|
if explicit_flag == "--explicit":
|
||||||
for output in outputs_list:
|
for output in outputs_list:
|
||||||
assert "/conda-forge/" in output
|
assert "/conda-forge/" in output
|
||||||
|
@ -109,12 +117,15 @@ def test_list_subcommands(
|
||||||
assert "#" in output
|
assert "#" in output
|
||||||
else:
|
else:
|
||||||
assert "#" not in output
|
assert "#" not in output
|
||||||
else:
|
elif canonical_flag in ["-c", "--canonical"]:
|
||||||
if canonical_flag == "--canonical":
|
for output in outputs_list:
|
||||||
items = ["conda-forge/", "::"]
|
assert all(i in output for i in items)
|
||||||
for output in outputs_list:
|
assert " " not in output
|
||||||
assert all(i in output for i in items)
|
elif export_flag in ["-e", "--export"]:
|
||||||
assert " " not in output
|
items += [" "]
|
||||||
|
for output in outputs_list:
|
||||||
|
assert all(i not in output for i in items)
|
||||||
|
assert len(output.split("=")) == 3
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("quiet_flag", ["", "-q", "--quiet"])
|
@pytest.mark.parametrize("quiet_flag", ["", "-q", "--quiet"])
|
||||||
|
|
Loading…
Reference in New Issue