refactor: remove parse_command round-trip from type builtin#59
Open
refactor: remove parse_command round-trip from type builtin#59
Conversation
Adds resolve_command_type() in executor.rs that checks BuiltInName directly then searches PATH, without constructing a full Command. Removes From<&Arg> for Command from arg.rs as it was only used by execute_type(). Resolves the TODO in execute_type(). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Refactors the type builtin execution path to avoid converting an Arg back into a full Command via parse_command(), aiming to decouple type from parser internals.
Changes:
- Added a
resolve_command_type()helper to classify names as builtin / executable / not found. - Updated
execute_type()to use direct lookup rather thanCommand::from(&Arg). - Removed
impl From<&Arg> for Commandfromsrc/arg.rsto eliminate the parse round-trip dependency.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/executor.rs |
Adds direct command-kind resolution and updates type builtin execution to use it. |
src/arg.rs |
Removes the Arg -> Command conversion that previously invoked parse_command(). |
…e test - Replace get_path_files() scan with targeted dir.join(name) lookup in resolve_command_type(), avoiding construction of ExecutableCommand for every file in PATH - Expose get_path_dirs() as pub(crate) to support the above - Add test_execute_type_executable unit test covering the executable branch Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Closes #12.
Replaces the
parse_command()round-trip inexecute_type()with a direct lookup that checks builtin names then searches PATH, without constructing a fullCommand. Resolves the TODO at the relevant line insrc/executor.rs.Type of change
Test checklist
cargo testpassescargo clippy --all-targets --all-features -- -D warningspasses