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

Alias built-in #328

Merged
merged 4 commits into from
Dec 16, 2023
Merged

Alias built-in #328

merged 4 commits into from
Dec 16, 2023

Conversation

magicant
Copy link
Owner

@magicant magicant commented Dec 16, 2023

Summary by CodeRabbit

  • New Features

    • Enhanced the alias command with detailed descriptions and support for global aliases.
    • Improved error handling for non-existent aliases.
  • Bug Fixes

    • Adjusted alias definition process to ensure proper functionality.
  • Refactor

    • Asynchronous execution of the alias command implemented.
    • Introduced a Command struct to encapsulate command line arguments.
    • Added a semantics module to handle alias execution logic.
  • Tests

    • Added a new scripted test to validate alias functionality and POSIX compliance.
  • Documentation

    • Updated documentation to reflect the new features and changes in alias command usage.

@magicant magicant added the enhancement New feature or request label Dec 16, 2023
@magicant magicant added this to the POSIX 2018 scripting milestone Dec 16, 2023
@magicant magicant self-assigned this Dec 16, 2023
Copy link

coderabbitai bot commented Dec 16, 2023

Walkthrough

The updates to the alias built-in command in the Yash shell include a detailed description of functionality, asynchronous execution, refactored parsing and execution logic, and improved error handling. A new Command struct and a semantics module have been added to streamline the command's operation. The adjustments span across the alias command's definition, finding, printing, and execution processes, enhancing its robustness and capabilities.

Changes

File Path Change Summary
yash-builtin/src/alias.rs Updated alias built-in with detailed functionality description and refactored logic to be asynchronous. Introduced Command struct.
yash-builtin/src/alias/semantics.rs Added error handling, adjusted alias definition process, and changed execution flow for the alias built-in command.
yash-builtin/src/.../lib.rs Removed ready function call for alias built-in, altering the control flow of execution.
yash-env/src/builtin.rs Updated Result struct logic for merging results and added #[inline] attributes.
yash/tests/scripted_test.rs Added new alias test function.
yash/tests/scripted_test/alias-p.sh Introduced a test script for POSIX-compliant alias functionality.

Related issues

Poem

In the burrow of code, a rabbit did tweak,
Commands of an alias, now robust, not meek.
With async in place, and errors caught tight,
The shell gleams with logic, a coder's delight. 🌟🐰✨

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 X ?


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can reply to a review comment made by CodeRabbit.
  • You can tag CodeRabbit on specific lines of code or files in the PR by tagging @coderabbitai in a comment.
  • You can tag @coderabbitai in a PR comment and ask one-off questions about the PR and the codebase. Use quoted replies to pass the context for follow-up questions.

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

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: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2b94454 and 324991d.
Files selected for processing (6)
  • yash-builtin/src/alias.rs (4 hunks)
  • yash-builtin/src/alias/semantics.rs (1 hunks)
  • yash-builtin/src/lib.rs (1 hunks)
  • yash-env/src/builtin.rs (1 hunks)
  • yash/tests/scripted_test.rs (1 hunks)
  • yash/tests/scripted_test/alias-p.sh (1 hunks)
Files skipped from review due to trivial changes (1)
  • yash/tests/scripted_test.rs
Additional comments: 14
yash-builtin/src/alias.rs (4)
  • 19-60: The documentation has been expanded to provide a comprehensive description of the alias built-in command, which aligns with the PR objectives. This should enhance the understanding of the command's functionality for both users and developers.

  • 70-76: The introduction of the Command struct for encapsulating parsed command line arguments is a good practice for code clarity and maintainability.

  • 81-96: The refactoring of the main function to be asynchronous is a significant change that should improve performance and allow for better integration with other asynchronous operations within the yash shell.

  • 16-115: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [16-188]

The changes in alias.rs are consistent with the PR objectives and the AI-generated summary. The file now includes comprehensive documentation, an asynchronous main function, a new Command struct, and a semantics module for execution logic.

yash-builtin/src/alias/semantics.rs (2)
  • 124-129: The logic in the execute method for defining an alias or printing its definition seems sound. Ensure that operands are properly sanitized and alias names are validated to avoid any potential issues.

  • 143-286: The tests provided are comprehensive and cover a variety of scenarios, including error cases. This aligns with the user's previous action of adding tests for error cases, ensuring robustness in the functionality of the alias built-in.

yash-builtin/src/lib.rs (1)
  • 106-110: The change from Box::pin(ready(alias::main(env, args))) to Box::pin(alias::main(env, args)) indicates that alias::main is now an asynchronous function. Ensure that the alias::main function is properly refactored to return a Future and that this change is consistent with the asynchronous behavior intended by the PR.
yash-env/src/builtin.rs (1)
  • 224-224: The addition of the #[inline] attribute to the Default and From<ExitStatus> trait implementations for Result is a good practice for small functions that are frequently called, as it can potentially improve performance by reducing function call overhead.

Also applies to: 231-231

yash/tests/scripted_test/alias-p.sh (6)
  • 34-35: The test case for removing a specific alias is marked as a TODO, indicating that the unalias built-in is required but not yet implemented. Ensure that the implementation of unalias is planned or tracked in the project's issues or roadmap to complete these test cases.

  • 137-142: This test case is checking the behavior of using an alias after assignment. It's important to ensure that the environment variables (a and s) are correctly passed to the subshell and that the alias (s) is correctly expanded to sh. This test case helps confirm that aliases are properly resolved in the context of command execution.

  • 475-482: The test case IO_NUMBER cannot be aliased is ensuring that file descriptor numbers are not mistakenly treated as aliases. This is a good test to ensure that the shell correctly distinguishes between aliases and file descriptor numbers, which are a fundamental part of shell redirection syntax.

  • 523-530: The test case aliases cannot substitute reserved words is crucial for ensuring that aliases do not override shell keywords, which could lead to unexpected behavior. This test maintains the integrity of the shell's parsing logic by confirming that reserved words are not affected by alias substitution.

  • 597-605: The test case recursive alias is testing the behavior of an alias that refers to itself indirectly through another alias. This is an advanced scenario that can potentially lead to infinite loops or stack overflows if not handled correctly by the shell.

  • 607-616: The test case alias in command substitution is verifying that an alias defined within a function is used when a command substitution is performed within that function. This test ensures that the scope of alias definitions is respected within command substitutions.

yash-builtin/src/alias.rs Show resolved Hide resolved
yash-builtin/src/alias/semantics.rs Show resolved Hide resolved
yash-builtin/src/alias/semantics.rs Show resolved Hide resolved
yash-builtin/src/alias/semantics.rs Show resolved Hide resolved
yash-env/src/builtin.rs Show resolved Hide resolved
@magicant magicant merged commit 8d1ae8f into master Dec 16, 2023
5 checks passed
@magicant magicant deleted the alias-builtin branch December 16, 2023 14:08
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