-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split run function into separate files for OS builds.
- Loading branch information
1 parent
66c2575
commit 6467d36
Showing
3 changed files
with
53 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//go:build (darwin && cgo) || linux | ||
|
||
package cmd | ||
|
||
import ( | ||
"io" | ||
"os" | ||
"os/exec" | ||
|
||
"github.com/knqyf263/pet/config" | ||
) | ||
|
||
func run(command string, r io.Reader, w io.Writer) error { | ||
var cmd *exec.Cmd | ||
if len(config.Conf.General.Cmd) > 0 { | ||
line := append(config.Conf.General.Cmd, command) | ||
cmd = exec.Command(line[0], line[1:]...) | ||
} else { | ||
cmd = exec.Command("sh", "-c", command) | ||
} | ||
cmd.Stderr = os.Stderr | ||
cmd.Stdout = w | ||
cmd.Stdin = r | ||
return cmd.Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//go:build windows | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"os/exec" | ||
"syscall" | ||
|
||
"github.com/knqyf263/pet/config" | ||
) | ||
|
||
func run(command string, r io.Reader, w io.Writer) error { | ||
var cmd *exec.Cmd | ||
if len(config.Conf.General.Cmd) > 0 { | ||
line := append(config.Conf.General.Cmd, command) | ||
cmd = exec.Command(line[0], line[1:]...) | ||
} else { | ||
cmd = exec.Command("cmd.exe") | ||
cmd.SysProcAttr = &syscall.SysProcAttr{CmdLine: fmt.Sprintf("/c \"%s\"", command)} | ||
} | ||
cmd.Stderr = os.Stderr | ||
cmd.Stdout = w | ||
cmd.Stdin = r | ||
return cmd.Run() | ||
} |