-
Notifications
You must be signed in to change notification settings - Fork 10
/
list_directory.go
58 lines (46 loc) · 1.32 KB
/
list_directory.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
53
54
55
56
57
58
package commands
import (
"fmt"
"path/filepath"
"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 listDirectory(api models.GoQueryAPI, config *config.Config, cmdline string) error {
host, err := hosts.GetCurrentHost()
if err != nil {
return fmt.Errorf("No host is currently connected: %s", err)
}
args := strings.Split(cmdline, " ") // Separate command and arguments
lsDir := "."
if len(args) >= 2 {
lsDir = cmdline[len(args[0])+1:]
if len(lsDir) == 0 {
return fmt.Errorf("Invalid Directory")
}
}
if lsDir[0] != '/' {
lsDir = host.CurrentDirectory + lsDir
}
lsDir = filepath.Clean(lsDir)
// All directory changes must end with a forward slash
if lsDir[len(lsDir)-1] != '/' {
lsDir += "/"
}
listQuery := fmt.Sprintf("select * from file where directory = '%s'", lsDir)
results, err := utils.ScheduleQueryAndWait(api, host.UUID, listQuery)
if err != nil {
return err
}
utils.PrettyPrintQueryResults(results, config.PrintMode)
return nil
}
func listDirectoryHelp() string {
return "List the files in the current directory on the remote host"
}
func listDirectorySuggest(cmdline string) []prompt.Suggest {
return []prompt.Suggest{}
}