-
Notifications
You must be signed in to change notification settings - Fork 3
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
Type built-in #350
Type built-in #350
Conversation
WalkthroughThe recent updates to the yash shell enhance its functionality by introducing a built-in Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 2
Configuration used: CodeRabbit UI
Files selected for processing (4)
- yash-builtin/src/command.rs (1 hunks)
- yash-builtin/src/command/syntax.rs (3 hunks)
- yash-builtin/src/lib.rs (2 hunks)
- yash-builtin/src/type.rs (1 hunks)
Additional comments: 8
yash-builtin/src/type.rs (3)
- 17-60: The documentation for the
type
built-in command is comprehensive and well-structured, covering synopsis, description, options, operands, standard output, errors, exit status, and portability. It's good practice to include such detailed documentation, as it aids in understanding the command's purpose and usage. However, the options section mentions that non-standard options are not supported yet, which could be expanded upon in the future to enhance the command's functionality.- 64-74: The imports are well-organized and relevant to the functionality of the
type
built-in command. It's good to see that only necessary modules and types are imported, which helps in maintaining clarity and reducing potential for unnecessary dependencies.- 94-100: The
main
function serves as the entry point for thetype
built-in command. It correctly handles parsing the arguments and either executing the command or reporting an error. The use of asynchronous execution and error handling is consistent with the rest of the codebase, ensuring that the built-in command integrates well with the shell's architecture.yash-builtin/src/command/syntax.rs (2)
- 25-25: The introduction of the
OptionOccurrence
type fromcommon::syntax
is a significant change that enhances the representation of options within the shell's syntax parsing framework. This change likely improves the modularity and readability of the code by providing a more structured way to handle options.- 56-68: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [59-101]
The refactoring of the
interpret
andparse
functions to separate parsing and interpretation of command line arguments is a positive change that improves the separation of concerns within the code. By delegating the conversion of parsed arguments into aCommand
to theinterpret
function, the code becomes more modular and easier to maintain. Additionally, the handling of options within theinterpret
function is clear and straightforward, contributing to the overall readability of the code.yash-builtin/src/command.rs (1)
- 109-113: The addition of documentation to clarify the equivalence of the
type
built-in to thecommand
built-in with the-V
option is a valuable update. It helps users understand the relationship between these two built-ins and sets clear expectations regarding their functionality. This kind of documentation is crucial for user-facing features and contributes to a better user experience.yash-builtin/src/lib.rs (2)
- 79-80: The conditional compilation of the new
r#type
module under theyash-semantics
feature flag is a good practice that ensures the modularity and optional nature of thetype
built-in command. This approach allows for flexibility in the shell's configuration and feature set, aligning with the overall design goals of making certain functionalities optional.- 275-282: The addition of the
type
built-in command to theBUILTINS
array, also conditionally compiled under theyash-semantics
feature, is correctly implemented. This change formally integrates thetype
built-in into the shell's repertoire of built-in commands. The categorization of thetype
built-in asMandatory
is appropriate given its fundamental role in identifying command types. This integration is consistent with the PR's objectives and enhances the shell's capabilities.
yash-builtin/src/type.rs
Outdated
fn parse(env: &mut Env, args: Vec<Field>) -> Result<Command, crate::command::syntax::Error> { | ||
let (mut options, operands) = parse_arguments(OPTION_SPECS, Mode::with_env(env), args)?; | ||
let spec = OptionSpec::new().short('V').long("verbose-identify"); | ||
let location = env.stack.current_builtin().map_or_else( | ||
|| Location::dummy(""), | ||
|builtin| builtin.name.origin.clone(), | ||
); | ||
options.push(OptionOccurrence { | ||
spec: &spec, | ||
location, | ||
argument: None, | ||
}); | ||
interpret(options, operands) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parse
function is responsible for parsing the arguments passed to the type
built-in command. It introduces a new OptionSpec
for verbose identification but does not utilize it directly within the parse
function, instead adding it to the options list for interpretation. This approach is somewhat unconventional, as the type
command does not inherently support the -V
option according to the provided documentation. Consider clarifying the intent behind this implementation or adjusting the documentation to reflect the supported options accurately.
- let spec = OptionSpec::new().short('V').long("verbose-identify");
- options.push(OptionOccurrence {
- spec: &spec,
- location,
- argument: None,
- });
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
fn parse(env: &mut Env, args: Vec<Field>) -> Result<Command, crate::command::syntax::Error> { | |
let (mut options, operands) = parse_arguments(OPTION_SPECS, Mode::with_env(env), args)?; | |
let spec = OptionSpec::new().short('V').long("verbose-identify"); | |
let location = env.stack.current_builtin().map_or_else( | |
|| Location::dummy(""), | |
|builtin| builtin.name.origin.clone(), | |
); | |
options.push(OptionOccurrence { | |
spec: &spec, | |
location, | |
argument: None, | |
}); | |
interpret(options, operands) | |
fn parse(env: &mut Env, args: Vec<Field>) -> Result<Command, crate::command::syntax::Error> { | |
let (mut options, operands) = parse_arguments(OPTION_SPECS, Mode::with_env(env), args)?; | |
let location = env.stack.current_builtin().map_or_else( | |
|| Location::dummy(""), | |
|builtin| builtin.name.origin.clone(), | |
); | |
interpret(options, operands) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, added a comment in 72e1f07.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@magicant, I've reviewed the changes made in commit 72e1f07. The added comment clarifies the intent behind adding the -V
option to the type
built-in command, explaining that it's meant to make type
equivalent to command -V
, thereby delegating to the command
built-in. This addresses the initial concern by providing the necessary context for the implementation choice. Thank you for the update.
Analysis chain
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Fetch the changes made in commit 72e1f07, focusing on the comment added in yash-builtin/src/type.rs
git show 72e1f07 -- yash-builtin/src/type.rs
Length of output: 1076
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- yash-builtin/src/type.rs (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- yash-builtin/src/type.rs
Implements the
type
built-in.The scripted test is omitted because the original yash does not have one.
Summary by CodeRabbit
New Features
type
built-in command in the yash shell for identifying command types and descriptions, enhancing command line utility.Refactor
Documentation
type
andcommand
built-ins, providing clearer guidance for users.