Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add canonical flag to list command #3777

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

SandrineP
Copy link
Collaborator

@SandrineP SandrineP commented Jan 28, 2025

Adds one of the missing sub-command #3535

@SandrineP SandrineP marked this pull request as ready for review January 28, 2025 16:18
@jjerphan jjerphan added the release::enhancements For enhancements PRs or implementing features label Jan 28, 2025
@@ -27,11 +27,12 @@ namespace mamba
bool reverse;
bool explicit_;
bool md5;
bool canonical;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a default value ( = false;) to every member of this struct? I'm not convinced that it's always initialized correctly at usage point. If something prevents you to do so, nevermind.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done !

std::cout << p.name << "-" << p.version << "-" << p.build_string << std::endl;
}
}
else if (options.explicit_)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should happen if we ask for --explicit and --canonical?
Here, it would consider it as --canonical only (because it's the first condition), but if we want it lead to an additional behavior and print both lines (build_string and url) we should use an if instead of else if.
Same for remaining cases (should the else be exclusive etc).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had this question in mind for --canonical and --export (the next one I started working on), but missed it for --canonical and --explicit. Do we want to have the same behavior as conda? If so I would have to check what appends in these cases. If not, we would have to decide on the format of the output.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the descriptions, I think this should be exclusive indeed (I think conda does the same but gives precedence to --explicit). The question is, should we error out when multiple exclusive flags are given by the user or just ignore that and have some kind of priority that we decide on (for now it's --canonical)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested with conda. I will reproduce its behavior (explicit > canonical > export) and print a warning when two options are used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's done !

@Hind-M
Copy link
Member

Hind-M commented Jan 28, 2025

A more general question, are these recently added flags supposed to be supported only with a regular output (not json)?

@SandrineP
Copy link
Collaborator Author

When the --json flag is used, we return a json with everything, no matter which other flag appears (discussed with @JohanMabille). If I add md5, all the information needed to create the outputs of the other flags would be in the json.

@Hind-M
Copy link
Member

Hind-M commented Jan 29, 2025

When the --json flag is used, we return a json with everything, no matter which other flag appears (discussed with @JohanMabille). If I add md5, all the information needed to create the outputs of the other flags would be in the json.

So these specific flags are ignored with json and the output never changes? (just confirming that I got it right).

@SandrineP
Copy link
Collaborator Author

Yes, you're right.

.group("cli")
.description("Output canonical names of packages only. Ignored if --explicit.")
);
subcom->add_flag("-c,--canonical", canonical.get_cli_config<bool>(), canonical.description());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I just remembered that we can use excludes option in CLI11 to have the behavior we want:

Suggested change
subcom->add_flag("-c,--canonical", canonical.get_cli_config<bool>(), canonical.description());
subcom->add_flag("-c,--canonical", canonical.get_cli_config<bool>(), canonical.description())->excludes(explicit_flag);

explicit_flag being something like:
auto* explicit_flag = subcom->add_flag("--explicit", explicit_.get_cli_config<bool>(), explicit_.description());
This way, no need to add Ignored if --explicit. in the description.

Copy link
Collaborator Author

@SandrineP SandrineP Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to let the user know the behavior of the commands, so not sure about removing the message.
Should I use excludes but leave Ignored if --explicit. in the description ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think excludes automatically adds a note after the flag description in the --help text (saying that it's excluding some flag/option). But yes you can try it out and do whatever you think is user friendly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it and I don´t think that it is the behavior we want as the command doesn´t run when using excludes. I will keep the initial version.

Comment on lines 221 to 222
std::cout << "Warning: Option --canonical ignored because of --explicit \n"
<< std::endl;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In these cases, using LOG_log_level is recommended:

Suggested change
std::cout << "Warning: Option --canonical ignored because of --explicit \n"
<< std::endl;
LOG_WARNING << "Option --canonical ignored because of --explicit";

But that's just a remark for the future, if we use excludes option, this won't be necessary anymore.

assert all(i in output for i in items)
assert " " not in output


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can maybe combine with explicit tests (if it doesn't complicate things too much) and test the case where it should warn/abort (with excludes option)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release::enhancements For enhancements PRs or implementing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants