-
Notifications
You must be signed in to change notification settings - Fork 4
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
Getopts built-in #326
Getopts built-in #326
Conversation
WalkthroughThe Changes
TipsChat with CodeRabbit Bot (
|
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 ignored due to filter (2)
- Cargo.lock
- yash-builtin/Cargo.toml
Files selected for processing (10)
- yash-builtin/src/getopts.rs (1 hunks)
- yash-builtin/src/getopts/model.rs (1 hunks)
- yash-builtin/src/getopts/report.rs (1 hunks)
- yash-builtin/src/getopts/verify.rs (1 hunks)
- yash-builtin/src/lib.rs (2 hunks)
- yash-env/src/builtin.rs (1 hunks)
- yash-env/src/builtin/getopts.rs (1 hunks)
- yash-env/src/lib.rs (5 hunks)
- yash/tests/scripted_test.rs (1 hunks)
- yash/tests/scripted_test/getopts-p.sh (1 hunks)
Files skipped from review due to trivial changes (2)
- yash-env/src/builtin.rs
- yash/tests/scripted_test/getopts-p.sh
Additional comments: 29
yash-builtin/src/getopts.rs (4)
199-201: The addition of new modules (
model
,report
,verify
) aligns with the PR objectives and the AI-generated summaries. These modules are expected to handle parsing, reporting, and state verification of command-line options.203-220: The helper functions
indexes_from_optind
andindexes_to_optind
are implemented to manage the$OPTIND
value. Ensure that these functions are thoroughly tested, especially for edge cases and abnormal values.223-294: The
main
function has been refactored to use asynchronous programming patterns and includes logic for parsing command-line options and reporting results. It is crucial to ensure that the asynchronous behavior is consistent with the rest of the shell's environment handling and that it does not introduce any race conditions or unexpected behavior.296-338: New test cases have been added to validate the functionality of the
indexes_from_optind
andindexes_to_optind
functions. It is important to verify that these tests cover a wide range of inputs, including normal and abnormal values, to ensure the robustness of thegetopts
functionality.yash-builtin/src/getopts/model.rs (5)
19-20: The use of
thiserror
crate for error handling is a good practice as it provides a convenient way to define and manage errors in Rust.22-31: The
OptionType
enum is well-defined and covers all possible types of options (NoArgument
,TakesArgument
, andUnknown
), which is essential for the correct parsing of command-line options.33-37: The
OptionSpec
struct is minimal and focused, holding only the raw string representation of the option specification. This is a good example of keeping data structures simple and focused on their purpose.136-211: The
next
function's logic is complex but seems to be correct. It handles parsing options from command-line arguments, including edge cases like double hyphens and options with or without arguments. The use of pattern matching and options is idiomatic in Rust and enhances readability and maintainability.213-574: The tests are comprehensive and cover a wide range of scenarios. This thorough testing is crucial for ensuring the reliability of the
getopts
parsing logic.yash-builtin/src/getopts/report.rs (3)
33-57: The
Error
enum in thereport.rs
file provides detailed error handling for reporting results to the environment, which is a crucial aspect of thegetopts
functionality. This implementation is not explicitly mentioned in the summary, which could be considered an oversight given the importance of error handling in command-line option parsing.129-211: The
report
function within thereport.rs
file is a key component of the newgetopts
implementation, as it updates environment variables based on the parsing results. This function's implementation details are not mentioned in the summary, which is a significant omission given its role in the newgetopts
functionality.213-641: The test module within the
report.rs
file includes a comprehensive set of test cases that validate various aspects of thegetopts
functionality. The presence and importance of these tests are not mentioned in the summary, which is an oversight given their role in ensuring the correctness and reliability of thegetopts
built-in.yash-builtin/src/getopts/verify.rs (7)
17-22: The documentation provides a clear explanation of the purpose of the state verification for the
getopts
built-in. This is important for maintainability and understanding the intent of the code.28-37: The
Error
enum is correctly defined and uses thethiserror
crate for error handling, which is a good practice in Rust for creating and managing custom error types.39-45: The
GetoptsStateRef
struct is well-defined and its fields are appropriate for the intended purpose of state verification.47-54: The implementation of the
From
trait forGetoptsStateRef
is idiomatic and correctly converts a reference toGetoptsState
into aGetoptsStateRef
.57-70: The
into_state
method is correctly implemented, allowing for the conversion of aGetoptsStateRef
back into aGetoptsState
by cloning the referenced data.72-103: The
verify
method's logic is correct. It ensures that thegetopts
built-in receives consistent arguments and$OPTIND
values across calls, with special handling when$OPTIND
is1
.107-192: The tests are comprehensive and cover various scenarios, ensuring that the state verification logic works as expected.
yash-builtin/src/lib.rs (3)
59-59: The addition of the
getopts
module is consistent with the PR objectives and the summary provided.161-164: The addition of the
getopts
entry to theBUILTINS
constant with typeMandatory
and execution functiongetopts::main
is correct and aligns with the PR objectives and the summary.157-167: The test to ensure that the
BUILTINS
array is sorted alphabetically is a good practice for maintainability.yash-env/src/builtin/getopts.rs (2)
17-44: The summary mentions the addition of an
Error
enum, but it is not present in the provided hunk. Please verify if theError
enum is defined elsewhere in the code or if the summary is incorrect.43-43: The
optind
field in theGetoptsState
struct is of typeString
, which is unconventional asOPTIND
is typically an integer. Please verify if this is intentional and consider using an integer type if appropriate.yash-env/src/lib.rs (4)
34-37: The addition of the
GetoptsState
import and its use in theEnv
struct aligns with the PR's objective to enhance thegetopts
functionality.84-127: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [84-138]
The
Env
struct has been successfully updated to include thegetopts_state
field, which is necessary for the newgetopts
functionality.
151-157: The default constructor for the
Env
struct now initializes thegetopts_state
field, which is necessary for the newgetopts
functionality.183-189: The
clone_with_system
method of theEnv
struct has been updated to include thegetopts_state
field, ensuring that the state is preserved when cloning the environment with a new system.yash/tests/scripted_test.rs (1)
- 134-137: The addition of the
getopts_builtin
test function is consistent with the PR's objective to enhance thegetopts
functionality and the summary provided. This new test will help ensure the robustness of thegetopts
built-in.
Summary by CodeRabbit
New Features
getopts
built-in for enhanced option parsing in shell scripts.getopts
.Bug Fixes
next
function for more accurate command-line option parsing.Documentation
getopts
.Tests
getopts
functionality.getopts-p.sh
for comprehensive testing ofgetopts
behavior.Chores
getopts
module into theEnv
struct for state management.