Skip to content

implement head and tail commands in command line shell#215

Merged
AlixANNERAUD merged 3 commits intomainfrom
196-implement-head-and-tail-in-command-line-shell
Apr 7, 2026
Merged

implement head and tail commands in command line shell#215
AlixANNERAUD merged 3 commits intomainfrom
196-implement-head-and-tail-in-command-line-shell

Conversation

@AlixANNERAUD
Copy link
Copy Markdown
Contributor

@AlixANNERAUD AlixANNERAUD commented Apr 7, 2026

This pull request adds support for the head and tail commands to the shell, allowing users to view the first or last N lines of a file, similar to their Unix counterparts. It introduces new command implementations, integrates them into the command resolution and dispatch system, and provides comprehensive tests for both commands. Additionally, there is a small fix in the argument parsing macro to improve positional argument handling.

New command implementations:

  • Added HeadCommand and TailCommand in head.rs and tail.rs, with logic to read the first or last N lines of a file, including robust handling of edge cases (e.g., files without trailing newlines, zero lines requested). Both commands support -n/--lines option for specifying the number of lines. [1] [2]

Command system integration:

  • Registered the new commands in the command module, updated the UserCommandKind enum, and extended the command resolution and dispatch logic to support head and tail. [1] [2] [3] [4] [5]
  • Added tests to verify command resolution for head and tail by name.

Testing and robustness:

  • Included comprehensive unit tests for both head and tail logic, covering various cases such as files with/without trailing newlines, zero lines requested, and argument parsing. [1] [2]
  • Added a new test for graphical shell argument parsing to ensure the --show-keyboard flag is handled correctly.

Macro improvement:

  • Improved the executable macro's argument parsing: replaced .next_positional() with .value() for better error handling and correctness when extracting positional arguments.

@AlixANNERAUD AlixANNERAUD linked an issue Apr 7, 2026 that may be closed by this pull request
@AlixANNERAUD AlixANNERAUD force-pushed the 196-implement-head-and-tail-in-command-line-shell branch from 438057b to 471dd56 Compare April 7, 2026 12:04
@AlixANNERAUD AlixANNERAUD enabled auto-merge (squash) April 7, 2026 12:05
@AlixANNERAUD AlixANNERAUD merged commit d7ec072 into main Apr 7, 2026
3 checks passed
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 7, 2026

Codecov Report

❌ Patch coverage is 42.12766% with 136 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...xecutables/shell/command_line/src/commands/head.rs 37.50% 70 Missing ⚠️
...xecutables/shell/command_line/src/commands/tail.rs 40.74% 64 Missing ⚠️
executables/shell/command_line/src/commands/mod.rs 75.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@AlixANNERAUD AlixANNERAUD deleted the 196-implement-head-and-tail-in-command-line-shell branch April 8, 2026 11:25
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.

Implement head and tail in command line shell

1 participant