mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
ExecuteCommand() moved into the utils dumping ground
This commit is contained in:
parent
de7480b221
commit
0b8a063487
@ -59,7 +59,6 @@ func (widget *Widget) contentFrom(items []Item) string {
|
||||
}
|
||||
|
||||
str := ""
|
||||
|
||||
for _, item := range items {
|
||||
str = str + widget.display(item)
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
//"fmt"
|
||||
"io/ioutil"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/senorprogrammer/wtf/wtf"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
@ -26,7 +26,7 @@ func NewClient() *Client {
|
||||
func (client *Client) CurrentBranch() string {
|
||||
arg := []string{"rev-parse", "--abbrev-ref", "HEAD"}
|
||||
cmd := exec.Command("git", arg...)
|
||||
str := executeCommand(cmd)
|
||||
str := wtf.ExecuteCommand(cmd)
|
||||
|
||||
return str
|
||||
}
|
||||
@ -34,7 +34,7 @@ func (client *Client) CurrentBranch() string {
|
||||
func (client *Client) ChangedFiles() []string {
|
||||
arg := []string{"status", "--porcelain"}
|
||||
cmd := exec.Command("git", arg...)
|
||||
str := executeCommand(cmd)
|
||||
str := wtf.ExecuteCommand(cmd)
|
||||
|
||||
data := strings.Split(str, "\n")
|
||||
|
||||
@ -44,29 +44,9 @@ func (client *Client) ChangedFiles() []string {
|
||||
func (client *Client) Commits() []string {
|
||||
arg := []string{"log", "--date=format:\"%b %d, %Y\"", "-n 10", "--pretty=format:\"[forestgreen]%h [white]%s [grey]%an on %cd[white]\""}
|
||||
cmd := exec.Command("git", arg...)
|
||||
str := executeCommand(cmd)
|
||||
str := wtf.ExecuteCommand(cmd)
|
||||
|
||||
data := strings.Split(str, "\n")
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
func executeCommand(cmd *exec.Cmd) string {
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
return "err"
|
||||
}
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
return "err"
|
||||
}
|
||||
|
||||
var str string
|
||||
if b, err := ioutil.ReadAll(stdout); err == nil {
|
||||
str += string(b)
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
package security
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/senorprogrammer/wtf/wtf"
|
||||
)
|
||||
|
||||
const osxFirewallCmd = "/usr/libexec/ApplicationFirewall/socketfilterfw"
|
||||
@ -12,39 +13,21 @@ const osxFirewallCmd = "/usr/libexec/ApplicationFirewall/socketfilterfw"
|
||||
|
||||
func FirewallState() string {
|
||||
cmd := exec.Command(osxFirewallCmd, "--getglobalstate")
|
||||
str := executeCommand(cmd)
|
||||
str := wtf.ExecuteCommand(cmd)
|
||||
|
||||
return str
|
||||
return status(str)
|
||||
}
|
||||
|
||||
func FirewallStealthState() string {
|
||||
cmd := exec.Command(osxFirewallCmd, "--getstealthmode")
|
||||
str := executeCommand(cmd)
|
||||
str := wtf.ExecuteCommand(cmd)
|
||||
|
||||
return str
|
||||
return status(str)
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
func executeCommand(cmd *exec.Cmd) string {
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
return firewallStr("err")
|
||||
}
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
return firewallStr("err")
|
||||
}
|
||||
|
||||
var str string
|
||||
if b, err := ioutil.ReadAll(stdout); err == nil {
|
||||
str += string(b)
|
||||
}
|
||||
|
||||
return firewallStr(str)
|
||||
}
|
||||
|
||||
func firewallStr(str string) string {
|
||||
func status(str string) string {
|
||||
icon := "[red]off[white]"
|
||||
|
||||
if strings.Contains(str, "enabled") {
|
||||
|
Loading…
x
Reference in New Issue
Block a user