Skip to content

cat: add -A flag (equivalent to GNU cat -A)#357

Merged
laffer1 merged 1 commit into
masterfrom
feature/cat-A-flag
May 16, 2026
Merged

cat: add -A flag (equivalent to GNU cat -A)#357
laffer1 merged 1 commit into
masterfrom
feature/cat-A-flag

Conversation

@laffer1
Copy link
Copy Markdown
Member

@laffer1 laffer1 commented May 16, 2026

Add -A flag to cat(1) utility, which is equivalent to -et (enables vflag, eflag, and tflag). This matches the behavior of GNU cat.

Updated man page and added a new ATF test case to verify equivalence.

AI-Assisted-by: Gemini CLI noreply@google.com

Summary by Sourcery

Add a new -A option to the cat(1) utility and verify its behavior with documentation and tests.

New Features:

  • Introduce a -A flag to cat that combines displaying non-printing characters, marking line ends, and showing tabs as ^I, equivalent to -et.

Documentation:

  • Document the new -A flag in the cat(1) man page and note it as an extension to the specification.

Tests:

  • Add an ATF test to ensure cat -A output matches cat -et, and register it in the test Makefile.

Add -A flag to cat(1) utility, which is equivalent to -et (enables
vflag, eflag, and tflag). This matches the behavior of GNU cat.

Updated man page and added a new ATF test case to verify equivalence.

AI-Assisted-by: Gemini CLI <noreply@google.com>
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 16, 2026

Reviewer's Guide

Adds a new -A flag to cat(1) that behaves like GNU cat -A by enabling the existing -e and -t behaviors (vflag, eflag, tflag), documents it in the man page, and introduces an ATF test to verify equivalence with -et.

Flow diagram for cat -A flag behavior

flowchart LR
    User["User runs: cat -A file"] --> CatMain["main(argc, argv)"]
    CatMain --> Getopt["getopt(SUPPORTED_FLAGS)"]
    Getopt -->|'-A'| SetFlags["eflag = 1\ntflag = 1\nvflag = 1"]
    SetFlags --> Display["display_file() uses eflag, tflag, vflag"]
    Display --> Output["Output with non-printing chars, $ at EOL, ^I for tabs"]
Loading

File-Level Changes

Change Details Files
Introduce -A option to cat(1) that maps to the existing -e and -t behaviors.
  • Extend the supported option string to accept -A in non-bootstrap builds.
  • Handle the -A case in option parsing by setting eflag, tflag, and vflag to 1.
  • Align the synopsis and extension-flags list in the man page to include -A and describe its semantics as equivalent to -et.
bin/cat/cat.c
bin/cat/cat.1
Add an automated test to ensure -A output matches -et output.
  • Register a new shell-based ATF test file in the tests Makefile.
  • Create A_flag_test.sh that generates sample input, captures output from cat -et, and asserts that cat -A produces identical output.
bin/cat/tests/Makefile
bin/cat/tests/A_flag_test.sh

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In bin/cat/tests/Makefile you add A_flag_test to ATF_TESTS_SH while the existing tests use NETBSD_ATF_TESTS_SH, so consider using the same variable to ensure the new test is discovered and run consistently with the rest.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In bin/cat/tests/Makefile you add A_flag_test to ATF_TESTS_SH while the existing tests use NETBSD_ATF_TESTS_SH, so consider using the same variable to ensure the new test is discovered and run consistently with the rest.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@laffer1 laffer1 merged commit 2a74ccd into master May 16, 2026
6 of 12 checks passed
@laffer1 laffer1 deleted the feature/cat-A-flag branch May 16, 2026 21:28
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements the -A flag for the cat utility, which is equivalent to the -et options. The changes include updates to the command-line argument parsing, the manual page, and the addition of a new test case. The review feedback identifies a grammatical regression in the manual page and an omission in the usage() function, which needs to be updated to include the new flag.

Comment thread bin/cat/cat.1
.Op Ar
.Sh DESCRIPTION
The
.Nm
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The word "The" was removed from the start of the DESCRIPTION section. This makes the sentence grammatically incomplete and deviates from the standard man page style for utility descriptions. It should be restored.

The
.Nm

Comment thread bin/cat/cat.c
Comment on lines +179 to +181
case 'A':
eflag = tflag = vflag = 1;
break;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The usage() function should be updated to include the new -A flag in the usage message. It appears this was omitted from the current changes. Please ensure the usage string matches the updated SUPPORTED_FLAGS.

laffer1 added a commit that referenced this pull request May 21, 2026
Add -A flag to cat(1) utility, which is equivalent to -et (enables
vflag, eflag, and tflag). This matches the behavior of GNU cat.

Updated man page and added a new ATF test case to verify equivalence.

AI-Assisted-by: Gemini CLI <noreply@google.com>
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.

1 participant