GeezerVison is showing github.com — feat(spec): expose package metadata by jdx · Pull Request #1116 · jdx/usage
feat(spec): expose package metadata
#1116
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
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter
Filter by extension
.1
(1)
.md
(1)
.rs
(3)
All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
fix(spec): accept package metadata expressions
Loading branch information
Uh oh!
There was an error while loading. Please reload this page.
jdx
committed
Aug 20, 2026
commit 3b8e1b570fd81327a3772a90de6e3e4f88e30f77
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -518,3 +518,5 @@ Arguments to pass to script
Anything `usage` does not recognise is a value rather than a mistake, which is what
lets a shebang script take flags of its own.
.SH SOURCE
https://github.com/jdx/usage
Original file line number
Diff line number
Diff line change
Expand Up
@@ -198,9 +198,9 @@ pub fn emit(cli: &Cli) -> TokenStream {
Some(tokens) => quote!(::core::option::Option::Some(#tokens)),
None => quote!(::core::option::Option::None),
};
let author = option_str (cli.author.as_deref ());
let license = option_str (cli.license.as_deref ());
let repository = option_str (cli.repository.as_deref ());
let author = option_expr (cli.author.as_ref ());
let license = option_expr (cli.license.as_ref ());
let repository = option_expr (cli.repository.as_ref ());
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
Uh oh!
There was an error while loading. Please reload this page.
let about = cli
.about_attr
.as_ref()
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -91,9 +91,13 @@ pub struct Cli {
/// From the struct's doc comment: first paragraph, and the whole thing.
pub about: Option<String>,
pub long_about: Option<String>,
pub author: Option<String>,
pub license: Option<String>,
pub repository: Option<String>,
/// Package metadata expressions whose results must be usable as `&'static str`.
///
/// Keeping their tokens lets the Cargo-provided `env!("CARGO_PKG_…")` values remain the
/// source of truth instead of making adopters repeat those strings in the derive attribute.
pub author: Option<proc_macro2::TokenStream>,
pub license: Option<proc_macro2::TokenStream>,
pub repository: Option<proc_macro2::TokenStream>,
/// Whether a flag-like token that names no flag is a value or an error. Unset
/// means the spec's default, which is `value`.
pub unknown_flags: Option<String>,
Expand Down
Expand Up
@@ -693,9 +697,9 @@ impl Cli {
// declared.
"about" => cli.about_attr = Some(metadata_expr(&meta)?),
"long_about" => cli.long_about_attr = Some(metadata_expr(&meta)?),
"author" => cli.author = Some(string_value (&meta)?),
"license" => cli.license = Some(string_value (&meta)?),
"repository" => cli.repository = Some(string_value (&meta)?),
"author" => cli.author = Some(metadata_expr (&meta)?),
"license" => cli.license = Some(metadata_expr (&meta)?),
"repository" => cli.repository = Some(metadata_expr (&meta)?),
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
Uh oh!
There was an error while loading. Please reload this page.
"before_help" => cli.before_help = Some(metadata_expr(&meta)?),
"next_help_heading" => cli.next_help_heading = Some(string_value(&meta)?),
"before_long_help" => cli.before_long_help = Some(metadata_expr(&meta)?),
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -6,6 +6,8 @@
**Version**: 5.1.0
**Repository**: https://github.com/jdx/usage
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
Uh oh!
There was an error while loading. Please reload this page.
- **Usage**: `usage [--completions <COMPLETIONS>] [--usage-spec] <SUBCOMMAND>`
## Flags
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -26,26 +26,29 @@ enum Command {
#[derive(Cli)]
#[usage(
bin = "metadata",
author = "Example Maintainers" ,
license = "MIT OR Apache-2.0" ,
repository = "https://example.com/tool"
author = env!("CARGO_PKG_AUTHORS") ,
license = env!("CARGO_PKG_LICENSE") ,
repository = env!("CARGO_PKG_REPOSITORY")
)]
struct PackageMetadata;
#[test]
fn package_metadata_survives_spec_emission() {
let kdl = PackageMetadata::to_kdl();
assert!(kdl.contains("author \"Example Maintainers \""), "{kdl}");
assert!(kdl.contains("license \" MIT OR Apache-2.0\" "), "{kdl}");
assert!(kdl.contains("author \"Jeff Dickey @jdx \""), "{kdl}");
assert!(kdl.contains("license MIT"), "{kdl}");
assert!(
kdl.contains("repository \"https://example .com/tool \""),
kdl.contains("repository \"https://github .com/jdx/usage \""),
"{kdl}"
);
let spec: usage_parser::Spec = kdl.parse().expect("usage-lib should read derive output");
assert_eq!(spec.author.as_deref(), Some("Example Maintainers"));
assert_eq!(spec.license.as_deref(), Some("MIT OR Apache-2.0"));
assert_eq!(spec.repository.as_deref(), Some("https://example.com/tool"));
assert_eq!(spec.author.as_deref(), Some("Jeff Dickey @jdx"));
assert_eq!(spec.license.as_deref(), Some("MIT"));
assert_eq!(
spec.repository.as_deref(),
Some("https://github.com/jdx/usage")
);
}
#[test]
Expand Down
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.