Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub enum Builtin {
Headers,
Vars,
Requests,
Clear,
}

pub enum ControlFlow {
Expand Down Expand Up @@ -96,6 +97,11 @@ pub fn handle(
}
}

Builtin::Clear => {
ctx.clear();
println!("Session state cleared");
}

Builtin::Rerun(index) => {
if index == 0 {
return Err("history indices start at 1".into());
Expand Down
1 change: 1 addition & 0 deletions src/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub fn help_text() -> String {
headers
history
rerun <id>
clear
help
exit
{}
Expand Down
2 changes: 1 addition & 1 deletion src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustyline::{Context, Helper, Result};

const BUILTINS: &[&str] = &[
"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS", "base", "header", "exit", "help",
"history", "rerun", "set", "unset", "save", "run", "vars", "headers", "requests",
"history", "rerun", "set", "unset", "save", "run", "vars", "headers", "requests", "clear",
];

pub struct ShellHelper;
Expand Down
3 changes: 2 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn parse(input: String) -> Result<Parsed, String> {
}

"base" | "set" | "unset" | "header" | "headers" | "vars" | "requests" | "save" | "run"
| "help" | "history" | "rerun" => {
| "help" | "history" | "rerun" | "clear" => {
let result = parse_builtin(input)?;
Ok(Parsed::Builtin(result))
}
Expand Down Expand Up @@ -174,6 +174,7 @@ fn parse_builtin(line: String) -> Result<Builtin, String> {
}
}
"help" => Ok(Builtin::Help),
"clear" => Ok(Builtin::Clear),
"history" => Ok(Builtin::History),
"rerun" => {
if tokens.len() != 2 {
Expand Down
8 changes: 8 additions & 0 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ impl ShellState {
pub fn remove_variable(&mut self, name: &str) {
self.variables.remove(name);
}

pub fn clear(&mut self) {
self.base_url = None;
self.headers.clear();
self.variables.clear();
self.last_request = None;
self.saved_requests.clear();
}
}

#[cfg(test)]
Expand Down
Loading