-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell.go
36 lines (32 loc) · 851 Bytes
/
shell.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
package main
import (
"os/exec"
"strconv"
"strings"
)
// Shell : A struct that contains all the shell parameters and fuzz terms.
type Shell struct {
Shell string
Args []string
Cmd string
FuzzTerm string
Values []string
}
// Command : Parses stored values and returns an executable command.
func (s Shell) Command() exec.Cmd {
cmd := s.Cmd
for i, v := range s.Values {
needle := s.Term(i)
cmd = strings.ReplaceAll(cmd, needle, v)
}
args := append(s.Args, cmd)
command := exec.Command(s.Shell, args...)
return *command
}
// Term : Generates a fuzz term given an index. The curly braces are replaced by '', '2', '3', etc.
func (s Shell) Term(index int) string {
if index == 0 {
return strings.ReplaceAll(s.FuzzTerm, "{}", "")
}
return strings.ReplaceAll(s.FuzzTerm, "{}", strconv.FormatInt(int64(index+1), 10))
}