Skip to content

Commit

Permalink
wm-launchd: Simplify CLI flag parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrd committed Jan 18, 2021
1 parent 084f062 commit e4beb64
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions wm-launchd.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,13 @@ func send(s ...interface{}) string {
}

func main() {
var factory string
var id string
var check string
var list bool
factory := flag.String("factory", "", "name of window factory")
id := flag.String("id", "", "ID to add to factory")
check := flag.String("check", "", "name of factory to check")
list := flag.Bool("list", false, "list factory names or IDs")

printList := func(cmd ...interface{}) {
if list {
if *list {
rsp := send(cmd...)
if strings.HasPrefix(rsp, "ERROR") {
os.Exit(1)
Expand All @@ -310,25 +310,20 @@ func main() {
}
}

flag.StringVar(&factory, "factory", "", "name of window factory")
flag.StringVar(&id, "id", "", "ID to add to factory")
flag.StringVar(&check, "check", "", "name of factory to check")
flag.BoolVar(&list, "list", false, "list factory names or IDs")

flag.Parse()

if check != "" {
checkFact(check)
if *check != "" {
checkFact(*check)
}

if factory != "" {
printList("LIST_IDS", factory)
if id != "" {
send("ADD_ID", factory, id)
if *factory != "" {
printList("LIST_IDS", *factory)
if *id != "" {
send("ADD_ID", *factory, *id)
os.Exit(0)
}

checkFact(factory)
checkFact(*factory)
}

printList("LIST_FACTORIES")
Expand Down

0 comments on commit e4beb64

Please sign in to comment.