Skip to content

Ability to clear metadata fields #2216

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

Merged
merged 4 commits into from
Jun 5, 2025

Conversation

vigoo
Copy link
Contributor

@vigoo vigoo commented Jun 3, 2025

Resolves #2211

@vigoo vigoo requested a review from a team as a code owner June 3, 2025 16:07
@vigoo vigoo requested review from pchickey and removed request for a team June 3, 2025 16:07
}

#[cfg(feature = "clap")]
pub const KEEP: &str = "::keep";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This (and the Display instance below) is quite ugly, but that's the best I could come up with if we want to keep AddMetadata both the API and the clap interface because of clap-rs/clap#4558

Alternatively we could have a separate struct for clap with option fields that can default to None without going through the value parser. Let me know if you prefer that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree the behavior here was hard to parse for me, and I don't understand how it would be rendered in the help text either. I don't love the ::keep sigil on the cli. Without knowing clap's facilities for this very well: is there some way to get --<name>=value to have the current set behavior, and expose an additional --clear-<name> as an additional flag?

Copy link
Contributor

@pchickey pchickey left a comment

Choose a reason for hiding this comment

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

Thanks for working on this, this is useful functionality to add but I want to understand some alternatives for the cli interface.

}

#[cfg(feature = "clap")]
pub const KEEP: &str = "::keep";
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree the behavior here was hard to parse for me, and I don't understand how it would be rendered in the help text either. I don't love the ::keep sigil on the cli. Without knowing clap's facilities for this very well: is there some way to get --<name>=value to have the current set behavior, and expose an additional --clear-<name> as an additional flag?

@vigoo
Copy link
Contributor Author

vigoo commented Jun 3, 2025

is there some way to get --=value to have the current set behavior, and expose an additional --clear- as an additional flag?

I would prefer that command line interface too! (Currently the rendered help is the worst part as it shows these ::keep (or whatever we choose) values which should not ever be actually used. Otherwise --name value sets the attribute and --name "" clears it; definitely not something I'm happy with)

Unfortunately (?) I think it is only possible if we give up that the AddMetadata struct is both used in the Rust API and for clap. Then we can define whatever fields and attributes are needed for clap to make the desired user experience.

Are you OK with that?
Personally I think it's not a big loss compared to the much better user interface it could provide

@pchickey
Copy link
Contributor

pchickey commented Jun 3, 2025

Yes, please write whatever datastructures Clap requires to provide the ideal cli interface, and then translate the output of clap's parsing to the AddMetadata enums used by the Rust API. You can sequester all of the clap-specific intermediate representations into either a private mod, or a #[cfg(feature = "clap")] #[doc(hidden)] pub mod __clap {...} as needed.

Copy link
Contributor

@pchickey pchickey left a comment

Choose a reason for hiding this comment

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

Looks great. Could you please add a quick cli test to cover the clap portion of this as well? for example https://github.com/bytecodealliance/wasm-tools/blob/main/tests/cli/add-metadata-merge-sections.wat

@vigoo
Copy link
Contributor Author

vigoo commented Jun 5, 2025

Added one

@pchickey pchickey added this pull request to the merge queue Jun 5, 2025
@pchickey
Copy link
Contributor

pchickey commented Jun 5, 2025

Thanks very much!

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 5, 2025
@pchickey pchickey added this pull request to the merge queue Jun 5, 2025
Merged via the queue into bytecodealliance:main with commit c76a5c9 Jun 5, 2025
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AddMetadata should be able to clear existing fields
2 participants