Skip to content

Commit

Permalink
refactors helper func
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Hausenblas <[email protected]>
  • Loading branch information
mhausenblas committed Feb 23, 2020
1 parent 8ab7b29 commit f01a5a7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
18 changes: 18 additions & 0 deletions cmdshandle.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,24 @@ func killfail(line, reason string) {
fmt.Printf("\nFailed to kill %s due to:\n%s\n\n", strconv.Quote(line), reason)
}

func extractsrc(line string) string {
debug("input line: " + line)
line = strings.TrimSuffix(line, "&")
line = strings.TrimSpace(line)
debug("sanitized line: " + line)
// a binary is standalone:
if !strings.ContainsAny(line, " ") {
_, binfile := filepath.Split(line)
debug("binfile extracted: " + binfile)
return binfile
}
// … otherwise it's a script:
script := strings.Split(line, " ")[1]
_, scriptfile := filepath.Split(script)
debug("scriptfile extracted: " + scriptfile)
return scriptfile
}

func hlaunch(line string) {
// If a line doesn't start with one of the
// known environments, assume user wants to
Expand Down
18 changes: 1 addition & 17 deletions launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,7 @@ func genDPID() string {
return fmt.Sprintf("%s-%v", base, now.UnixNano())
}

func extractsrc(line string) string {
debug("input line: " + line)
line = strings.TrimSuffix(line, "&")
line = strings.TrimSpace(line)
debug("sanitized line: " + line)
// a binary is standalone:
if !strings.ContainsAny(line, " ") {
_, binfile := filepath.Split(line)
debug("binfile extracted: " + binfile)
return binfile
}
// … otherwise it's a script:
script := strings.Split(line, " ")[1]
_, scriptfile := filepath.Split(script)
debug("scriptfile extracted: " + scriptfile)
return scriptfile
}


func verify(file string) (string, error) {
fileloc, err := filepath.Abs(file)
Expand Down

0 comments on commit f01a5a7

Please sign in to comment.