bind 'ctrl+f' to 'loadRequest' command, document it and -f/--file option

pull/102/head
Colin T.A. Gray 7 years ago
parent b289c84958
commit 3bd6a0ff4e

@ -39,6 +39,8 @@ Keybinding | Description
<kbd>Ctrl+R</kbd> | Send request
<kbd>Ret</kbd> | Send request (only from URL view)
<kbd>Ctrl+S</kbd> | Save response
<kbd>Ctrl+E</kbd> | Save request
<kbd>Ctrl+F</kbd> | Load request
<kbd>Ctrl+C</kbd> | Quit
<kbd>Ctrl+K</kbd>, <kbd>Shift+Tab</kbd> | Previous view
<kbd>Ctlr+J</kbd>, <kbd>Tab</kbd> | Next view

@ -46,6 +46,28 @@ var COMMANDS map[string]func(string, *App) CommandFunc = map[string]func(string,
})
}
},
"loadRequest": func(_ string, a *App) CommandFunc {
return func(g *gocui.Gui, _ *gocui.View) error {
return a.OpenSaveDialog(VIEW_TITLES[LOAD_REQUEST_DIALOG_VIEW], g,
func(g *gocui.Gui, _ *gocui.View) error {
defer a.closePopup(g, SAVE_DIALOG_VIEW)
loadLocation := getViewValue(g, SAVE_DIALOG_VIEW)
requestJson, ioErr := ioutil.ReadFile(loadLocation)
if ioErr != nil {
return ioErr
}
var requestMap map[string]string
jsonErr := json.Unmarshal(requestJson, &requestMap)
if jsonErr != nil {
return jsonErr
}
return a.LoadRequest(g, requestMap)
})
}
},
"saveRequest": func(_ string, a *App) CommandFunc {
return func(g *gocui.Gui, _ *gocui.View) error {
return a.OpenSaveDialog(VIEW_TITLES[SAVE_REQUEST_DIALOG_VIEW], g,

@ -55,6 +55,7 @@ var DefaultKeys = map[string]map[string]string{
"CtrlR": "submit",
"CtrlC": "quit",
"CtrlS": "saveResponse",
"CtrlF": "loadRequest",
"CtrlE": "saveRequest",
"CtrlD": "deleteLine",
"CtrlW": "deleteWord",

@ -15,6 +15,7 @@ CtrlC = "quit"
CtrlS = "saveResponse"
CtrlD = "deleteLine"
CtrlW = "deleteWord"
CtrlF = "loadRequest"
CtrlE = "saveRequest"
CtrlT = "toggleContextSpecificSearch"
CtrlX = "clearHistory"

@ -58,6 +58,7 @@ const (
HISTORY_VIEW = "history"
SAVE_DIALOG_VIEW = "save-dialog"
SAVE_RESPONSE_DIALOG_VIEW = "save-response-dialog"
LOAD_REQUEST_DIALOG_VIEW = "load-request-dialog"
SAVE_REQUEST_DIALOG_VIEW = "save-request-dialog"
SAVE_RESULT_VIEW = "save-result"
METHOD_LIST_VIEW = "method-list"
@ -69,6 +70,7 @@ var VIEW_TITLES = map[string]string{
ERROR_VIEW: "Error",
HISTORY_VIEW: "History",
SAVE_RESPONSE_DIALOG_VIEW: "Save Response (enter to submit, ctrl+q to cancel)",
LOAD_REQUEST_DIALOG_VIEW: "Load Request (enter to submit, ctrl+q to cancel)",
SAVE_REQUEST_DIALOG_VIEW: "Save Request (enter to submit, ctrl+q to cancel)",
SAVE_RESULT_VIEW: "Save Result (press enter to close)",
METHOD_LIST_VIEW: "Methods",
@ -1169,6 +1171,40 @@ func (a *App) CreatePopupView(name string, width, height int, g *gocui.Gui) (v *
return
}
func (a *App) LoadRequest(g *gocui.Gui, requestMap map[string]string) (err error) {
var v *gocui.View
url, exists := requestMap[URL_VIEW]
if exists {
v, _ = g.View(URL_VIEW)
setViewTextAndCursor(v, url)
}
method, exists := requestMap[REQUEST_METHOD_VIEW]
if exists {
v, _ = g.View(REQUEST_METHOD_VIEW)
setViewTextAndCursor(v, method)
}
params, exists := requestMap[URL_PARAMS_VIEW]
if exists {
v, _ = g.View(URL_PARAMS_VIEW)
setViewTextAndCursor(v, params)
}
data, exists := requestMap[REQUEST_DATA_VIEW]
if exists {
v, _ = g.View(REQUEST_DATA_VIEW)
setViewTextAndCursor(v, data)
}
headers, exists := requestMap[REQUEST_HEADERS_VIEW]
if exists {
v, _ = g.View(REQUEST_HEADERS_VIEW)
setViewTextAndCursor(v, headers)
}
return nil
}
func (a *App) ToggleHistory(g *gocui.Gui, _ *gocui.View) (err error) {
// Destroy if present
if a.currentPopup == HISTORY_VIEW {
@ -1521,36 +1557,7 @@ func (a *App) ParseArgs(g *gocui.Gui, args []string) error {
return jsonErr
}
var v *gocui.View
url, exists := requestMap[URL_VIEW]
if exists {
v, _ = g.View(URL_VIEW)
setViewTextAndCursor(v, url)
}
method, exists := requestMap[REQUEST_METHOD_VIEW]
if exists {
v, _ = g.View(REQUEST_METHOD_VIEW)
setViewTextAndCursor(v, method)
}
params, exists := requestMap[URL_PARAMS_VIEW]
if exists {
v, _ = g.View(URL_PARAMS_VIEW)
setViewTextAndCursor(v, params)
}
data, exists := requestMap[REQUEST_DATA_VIEW]
if exists {
v, _ = g.View(REQUEST_DATA_VIEW)
setViewTextAndCursor(v, data)
}
headers, exists := requestMap[REQUEST_HEADERS_VIEW]
if exists {
v, _ = g.View(REQUEST_HEADERS_VIEW)
setViewTextAndCursor(v, headers)
}
a.LoadRequest(g, requestMap)
default:
u := args[arg_index]
if strings.Index(u, "http://") != 0 && strings.Index(u, "https://") != 0 {
@ -1665,6 +1672,7 @@ Usage: wuzz [-H|--header HEADER]... [-d|--data|--data-binary DATA] [-X|--request
Other command line options:
-c, --config PATH Specify custom configuration file
-e, --editor EDITOR Specify external editor command
-f, --file REQUEST Load a previous request
-F, --form DATA Add multipart form request data and set related request headers
If the value starts with @ it will be handled as a file path for upload
-h, --help Show this
@ -1684,6 +1692,8 @@ Other command line options:
Key bindings:
ctrl+r Send request
ctrl+s Save response
ctrl+e Save request
ctrl+f Load request
tab, ctrl+j Next window
shift+tab, ctrl+k Previous window
alt+h Show history

Loading…
Cancel
Save