Skip to content

Commit

Permalink
add backends and frontends list to usage/help output
Browse files Browse the repository at this point in the history
  • Loading branch information
schachmat committed May 5, 2016
1 parent 3269e60 commit 6e0b48a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,36 @@ package main

import (
"flag"
"fmt"
"log"
"os"
"sort"
"strconv"
"strings"

"github.com/schachmat/ingo"
_ "github.com/schachmat/wego/backends"
_ "github.com/schachmat/wego/frontends"
"github.com/schachmat/wego/iface"
)

func pluginLists() {
bEnds := make([]string, 0, len(iface.AllBackends))
for name := range iface.AllBackends {
bEnds = append(bEnds, name)
}
sort.Strings(bEnds)

fEnds := make([]string, 0, len(iface.AllFrontends))
for name := range iface.AllFrontends {
fEnds = append(fEnds, name)
}
sort.Strings(fEnds)

fmt.Fprintln(os.Stderr, "Available backends:", strings.Join(bEnds, ", "))
fmt.Fprintln(os.Stderr, "Available frontends:", strings.Join(fEnds, ", "))
}

func main() {
// initialize backends and frontends (flags and default config)
for _, be := range iface.AllBackends {
Expand All @@ -32,6 +53,13 @@ func main() {
selectedFrontend := flag.String("frontend", "ascii-art-table", "`FRONTEND` to be used")
flag.StringVar(selectedFrontend, "f", "ascii-art-table", "`FRONTEND` to be used (shorthand)")

// print out a list of all backends and frontends in the usage
tmpUsage := flag.Usage
flag.Usage = func() {
tmpUsage()
pluginLists()
}

// read/write config and parse flags
if err := ingo.Parse("wego"); err != nil {
log.Fatalf("Error parsing config: %v", err)
Expand Down

0 comments on commit 6e0b48a

Please sign in to comment.