-
-
Notifications
You must be signed in to change notification settings - Fork 264
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
debugger: add long versions of the commands as well as all of their prefixes #1062
Conversation
WalkthroughThe pull request introduces modifications to the command handling functionality of the Changes
Poem
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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration 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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
debugger/src/main.rs (2)
131-132
: Partial command matching logic is reversed but valid.Using
"help".starts_with(help)
is unusual but still works because"help".starts_with("h" | "he" | "hel" | "help")
will evaluate correctly. Nonetheless, consider reversing the logic (help.starts_with("help")
), which generally reads more naturally.- help if "help".starts_with(help) => Cli::help(), + help if help.starts_with("help") => Cli::help(),
137-151
: Repeated code blocks for extracting filenames and rules can be DRYed up.Repeated usage of
.find(" ")
and.and_then(...)
to extract the argument after a space could be refactored into a small helper function. This would make your command parsing more consistent and maintainable. Additionally, consider if you need to handle filenames containing spaces.fn extract_arg(cmd: &str) -> Option<&str> { cmd.find(' ').map(|pos| &cmd[pos + 1..]) } // Then each usage: if let Some(arg) = extract_arg(grammar) { self.grammar(PathBuf::from(arg))?; } else { println!("expected filename, usage: g(grammar) <filename>"); }Also applies to: 157-165, 167-173, 175-180
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
debugger/src/main.rs
(2 hunks)
🔇 Additional comments (1)
debugger/src/main.rs (1)
109-119
: Great improvement in the help text clarity.
Labeling the command parameters (e.g. “g(grammar)”) is an effective way to guide new users.
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!
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.
Head branch was pushed to by a user without write access
Head branch was pushed to by a user without write access
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
debugger/src/main.rs (3)
109-119
: Consider aligning command descriptions for better readability.While the help text is more descriptive with parameter names in parentheses, the descriptions could be better aligned for improved readability.
- g(grammar) <grammar filename> - load .pest grammar\n\ - i(input) <input filename> - load input from a file\n\ + g(grammar) <grammar filename> - load .pest grammar\n\ + i(input) <input filename> - load input from a file\n\
135-137
: Consider using constants for command names.Commands like "help", "list", and "continue" could be defined as constants to avoid string literals and ensure consistency.
+const CMD_HELP: &str = "help"; +const CMD_LIST: &str = "list"; +const CMD_CONTINUE: &str = "continue"; + fn execute_command(&mut self, command: &str) -> Result<(), DebuggerError> { match command { "" => (), - help if "help".starts_with(help) => Cli::help(), - list if "list".starts_with(list) => self.list(), - cont if "continue".starts_with(cont) => self.cont()?, + help if CMD_HELP.starts_with(help) => Cli::help(), + list if CMD_LIST.starts_with(list) => self.list(), + cont if CMD_CONTINUE.starts_with(cont) => self.cont()?,
140-182
: Consider extracting common argument validation pattern.The pattern of extracting and validating arguments is repeated across multiple commands. Consider extracting this into a helper method to reduce duplication.
fn validate_arg<F>(&mut self, cmd: &str, usage: &str, f: F) -> Result<(), DebuggerError> where F: FnOnce(&mut Self, &str) -> Result<(), DebuggerError>, { if let Some(arg) = Self::extract_arg(cmd) { f(self, arg) } else { println!("expected argument, usage: {}", usage); Ok(()) } }Usage example:
- grammar if "grammar".starts_with(grammar) => { - let grammar_file = Self::extract_arg(grammar); - if let Some(grammar_file) = grammar_file { - self.grammar(PathBuf::from(grammar_file))?; - } else { - println!("expected filename, usage: g(grammar) <filename>"); - } - } + grammar if "grammar".starts_with(grammar) => { + self.validate_arg(grammar, "g(grammar) <filename>", |s, arg| { + s.grammar(PathBuf::from(arg)) + })? + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
debugger/src/main.rs
(2 hunks)
🔇 Additional comments (2)
debugger/src/main.rs (2)
128-130
: Implementation looks good!The
extract_arg
helper method is well-implemented and follows the suggested approach from the previous review.
140-182
: Verify command prefix matching behavior.The current implementation allows any prefix of a command to match. Let's verify that this doesn't lead to ambiguous matches.
✅ Verification successful
Let me analyze the command strings from the match arms to check for any prefix conflicts.
From the output, these are the main commands:
- help
- list
- continue
- grammar
- input
- breakpoint
- delete
- run
No ambiguous command prefix matches found
Looking at the first letter of each command, they are all unique:
- h(elp)
- l(ist)
- c(ontinue)
- g(rammar)
- i(nput)
- b(reakpoint)
- d(elete)
- r(un)
Since each command starts with a unique letter, and the code uses
starts_with()
for matching, there's no possibility of ambiguous matches. Each command can be uniquely identified by its first letter, and longer prefixes will continue to match only their respective commands.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for potential command prefix conflicts # For example, "r" could match both "run" and a hypothetical "reset" command # Get all command strings from the match arms rg --no-filename '^\s+\w+ if "(\w+)"\.starts_with' -or '$1' # Get all command strings from the help text rg --no-filename '^\s+\w+\((\w+)\)' -or '$1'Length of output: 1265
Summary by CodeRabbit
Documentation
Bug Fixes
help
,list
, andcontinue
for clearer user feedback.