Skip to content

Instantly share code, notes, and snippets.

@edewit
Created June 21, 2019 15:23
Show Gist options
  • Save edewit/d90c40b9f48633dc957893e300b35823 to your computer and use it in GitHub Desktop.
Save edewit/d90c40b9f48633dc957893e300b35823 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"github.com/urfave/cli"
"gopkg.in/yaml.v2"
)
// Note: struct fields must be public in order for unmarshal to
// correctly populate the data.
type Glue struct {
Command string
}
func main() {
app := cli.NewApp()
b, err := ioutil.ReadFile("glue.yml") // just pass the file name
if err != nil {
fmt.Print(err)
}
m := make(map[interface{}]interface{})
err = yaml.Unmarshal(b, &m)
if err != nil {
log.Fatalf("error: %v", err)
}
commands := make([]cli.Command, 0)
for k, v := range m {
commands = append(commands, cli.Command{
Name: k.(string),
Action: func(c *cli.Context) error {
fmt.Print(v)
return nil
},
})
}
app.Commands = commands
err = app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment