-
Notifications
You must be signed in to change notification settings - Fork 10
/
resume.go
52 lines (41 loc) · 1.23 KB
/
resume.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package commands
import (
"fmt"
"strings"
"github.com/AbGuthrie/goquery/v2/config"
"github.com/AbGuthrie/goquery/v2/hosts"
"github.com/AbGuthrie/goquery/v2/models"
"github.com/AbGuthrie/goquery/v2/utils"
prompt "github.com/c-bata/go-prompt"
)
func resume(api models.GoQueryAPI, config *config.Config, cmdline string) error {
args := strings.Split(cmdline, " ") // Separate command and arguments
if len(args) == 1 {
return fmt.Errorf("A query name to resume must be provided")
}
// TODO This needs to support Unicode/Runes
commandStripped := cmdline[strings.Index(cmdline, " ")+1:]
results, status, err := api.FetchResults(commandStripped)
if err != nil {
return err
}
if status == "Pending" {
return fmt.Errorf("Query does not have results available yet")
}
utils.PrettyPrintQueryResults(results, config.PrintMode)
return nil
}
func resumeHelp() string {
return "Try to fetch results for a query but don't block if unavailable"
}
func resumeSuggest(cmdline string) []prompt.Suggest {
host, err := hosts.GetCurrentHost()
prompts := []prompt.Suggest{}
if err != nil {
return prompts
}
for _, query := range host.QueryHistory {
prompts = append(prompts, prompt.Suggest{query.Name, query.SQL})
}
return prompts
}