diff --git a/bamboohr/widget.go b/bamboohr/widget.go index 302b8cb7..1551c43e 100644 --- a/bamboohr/widget.go +++ b/bamboohr/widget.go @@ -59,7 +59,6 @@ func (widget *Widget) contentFrom(items []Item) string { } str := "" - for _, item := range items { str = str + widget.display(item) } diff --git a/git/client.go b/git/client.go index 876ea0d3..7f678639 100644 --- a/git/client.go +++ b/git/client.go @@ -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 -} diff --git a/security/firewall.go b/security/firewall.go index bcbcdaf7..5d5cb95a 100644 --- a/security/firewall.go +++ b/security/firewall.go @@ -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") {