Skip to content

fix(ec2-metadata): add -q short option and clarify --quiet help text - #58

Open
phils wants to merge 2 commits into
amazonlinux:mainfrom
phils:ec2-metadata-quiet-short-opt
Open

phils wants to merge 2 commits into
amazonlinux:mainfrom
phils:ec2-metadata-quiet-short-opt

Conversation

@phils

@phils phils commented Nov 2, 2026

Copy link
Copy Markdown

Summary

This PR improves the usability and ergonomics of the --quiet option in ec2-metadata:

  1. Adds -q to shortopts and the option parser, allowing -q to be used alongside flags like -i, -o, and -z.
  2. Clarifies the --help description to reflect that --quiet suppresses keys across all metrics, not just tags.

Motivation

While ec2-metadata supports --quiet to output raw values directly (suppressing prefix labels like instance-id: ), users frequently encounter two stumbling blocks:

  1. Missing short option -q: Attempting ec2-metadata -i -q fails with getopt: invalid option -- 'q'.
  2. Misleading help text: Running ec2-metadata --help describes --quiet as:
    --quiet Suppress tag keys from the output.
    
    This leads users to believe --quiet only applies when querying --tags, even though [ -z "$QUIET" ] in print_normal_metric() suppresses label prefixes across all standard metrics.

Changes

  • Added q to shortopts.
  • Updated the case loop to handle -q|--quiet).
  • Updated print_help() to display -q/--quiet Suppress metric and tag keys from the output (value only).

Testing

Verified against IMDS:

  • ec2-metadata -i --quiet -> i-0123456789abcdef0
  • ec2-metadata -i -q -> i-0123456789abcdef0
  • ec2-metadata -o -q -> 10.0.1.25
  • ec2-metadata -z -q -> ap-southeast-2a
  • ec2-metadata -i (default) -> instance-id: i-0123456789abcdef0 (backwards compatibility preserved)

@ericsu66888

Copy link
Copy Markdown
Contributor

Thanks for this, the -q change works well.

Two small requests before merge:

1. Help text for tags

-g -q still prints each tag's name, because print_tags() has no $QUIET check:

$ ec2-metadata -g -q
	 Name: web-1
	 Env: prod

That looks intentional since 26926f7 (tag values without names would be ambiguous), so the help text should say so rather than claim tag keys are suppressed. Suggested wording:

-q/--quiet                Print values only, without metric names (tag names are kept for -g/--tags).

2. Man page

Please update doc/ec2-metadata.8 to match:

.B \-q/\-\-quiet

@phils

phils commented Nov 3, 2026

Copy link
Copy Markdown
Author

Thanks for the review @ericsu66888! I've updated the help text to clarify the tag behavior and updated doc/ec2-metadata.8 to document -q/--quiet.

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.

2 participants