Skip to content
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

Merged
merged 3 commits into from
Mar 7, 2024
Merged

Type built-in #350

merged 3 commits into from
Mar 7, 2024

Conversation

magicant
Copy link
Owner

@magicant magicant commented Mar 7, 2024

Implements the type built-in.

The scripted test is omitted because the original yash does not have one.

Summary by CodeRabbit

  • New Features

    • Introduced the type built-in command in the yash shell for identifying command types and descriptions, enhancing command line utility.
  • Refactor

    • Improved parsing and interpretation of command line arguments for better performance and maintainability.
  • Documentation

    • Updated information to clarify the equivalence of the type and command built-ins, providing clearer guidance for users.

@magicant magicant added the enhancement New feature or request label Mar 7, 2024
@magicant magicant self-assigned this Mar 7, 2024
@magicant magicant added this to the POSIX 2018 scripting milestone Mar 7, 2024
Copy link

coderabbitai bot commented Mar 7, 2024

Walkthrough

The recent updates to the yash shell enhance its functionality by introducing a built-in type command, aligning it with the capabilities of the command built-in when using the -V option. These changes involve refactoring for clearer argument parsing and interpretation, along with the integration of a new OptionOccurrence type. This development not only adds a new feature but also streamlines the codebase through modular enhancements and conditional compilation.

Changes

File Path Change Summary
.../src/command.rs Added info on type and command -V equivalence.
.../src/command/syntax.rs | .../src/type.rs Refactored argument parsing; introduced type built-in functionality.
.../src/lib.rs Added r#type module and entry in BUILTINS array, conditional on yash-semantics feature.

🐇✨
In the realm of code, where changes abound,
A rabbit hopped in, improvements found.
With a flick and a hop, type was born,
Amongst the lines of code, no longer torn.
So here's to yash, ever so bright,
With every commit, it reaches new height.
🌟🐾

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?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 4f44149 and df592e6.
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 the type 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 from common::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 and parse 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 a Command to the interpret function, the code becomes more modular and easier to maintain. Additionally, the handling of options within the interpret 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 the command 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 the yash-semantics feature flag is a good practice that ensures the modularity and optional nature of the type 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 the BUILTINS array, also conditionally compiled under the yash-semantics feature, is correctly implemented. This change formally integrates the type built-in into the shell's repertoire of built-in commands. The categorization of the type built-in as Mandatory 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 Show resolved Hide resolved
Comment on lines 79 to 91
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)
Copy link

@coderabbitai coderabbitai bot Mar 7, 2024

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.

Suggested change
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)

Copy link
Owner Author

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.

Copy link

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

Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between df592e6 and 72e1f07.
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

@magicant magicant merged commit 5d57650 into master Mar 7, 2024
5 checks passed
@magicant magicant deleted the type-builtin branch March 7, 2024 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant