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

Don't run empty commands (including comments) #6951

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion crates/repl_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,25 @@ pub fn main(has_color: bool, has_header: bool) -> i32 {
loop {
match editor.readline(&strip_colors_if_necessary(PROMPT)) {
Ok(line) => {
let line = line.trim();
let line = line.trim_end();
if line.trim().is_empty() {
// empty lines are ignored
println!();
continue;
}

editor.add_history_entry(line);

if line
.lines()
.map(|ln| ln.trim())
.all(|ln| ln.is_empty() || ln.starts_with('#'))
{
// if there are only whitespaces and comments, don't run it
println!();
continue;
}

let repl_state = &mut editor
.helper_mut()
.expect("Editor helper was not set")
Expand Down
Loading