Skip to content
Permalink
Browse files

Added the ability to list statuses

  • Loading branch information...
kiriappeee committed Mar 27, 2018
1 parent 8ea2b41 commit dd51ca0da64cab764757d842c987e35ad9861483
Showing with 25 additions and 1 deletion.
  1. +25 −1 cli.go
26 cli.go
@@ -5,16 +5,18 @@ import (
"fmt"
"log"
"strings"
"text/tabwriter"

"github.com/urfave/cli"
"github.com/kiriappeee/slack-status-updater-core"
)


func main(){
app := cli.NewApp()
app.Name = "Slack Status Updater"
app.Usage = "Painless status updating via your Terminal"
app.Version = "0.0.2alpha"
app.Version = "0.1.0"
app.Flags = []cli.Flag {
cli.StringFlag{
Name: "token",
@@ -35,6 +37,11 @@ func main(){
},
Action: changeStatus,
},
{
Name: "list",
Usage: "Lists available statuses and their information",
Action: listStatuses,
},
}
app.Action = changeStatus
err := app.Run(os.Args)
@@ -43,6 +50,23 @@ func main(){
}
}

func listStatuses(c *cli.Context) error {
w := new(tabwriter.Writer)
fileToReadStatusesFrom := os.Getenv("HOME") + "/.config/ssucli/statuses.yaml"
w.Init(os.Stdout, 0, 8, 0, '\t', 0)
statusList, err := getStatusesFromFile(fileToReadStatusesFrom)
if err != nil {
fmt.Printf("There was an error while trying to read the status list: %s\n", err.Error())
}
fmt.Fprintln(w, "NAME", "\t", "EMOJI", "\t", "STATUS TEXT", "\t")

for i := 0; i < len(statusList); i++ {
fmt.Fprintln(w, statusList[i].StatusName, "\t", statusList[i].Emoji, "\t", statusList[i].StatusText, "\t")
}
w.Flush()
return nil
}

func changeStatus(c *cli.Context) error{
fileToReadStatusesFrom := os.Getenv("HOME") + "/.config/ssucli/statuses.yaml"
slackToken := strings.TrimSpace(c.String("token"))

0 comments on commit dd51ca0

Please sign in to comment.
You can’t perform that action at this time.