one binary with subcommands

This commit is contained in:
Stephen McQuay 2015-06-29 23:24:02 -07:00
parent 418e62f332
commit a5f4d80506
4 changed files with 55 additions and 45 deletions

View File

@ -1,33 +1,31 @@
package main package main
import "mcquay.me/yay" import (
"fmt"
"os"
type Yay struct { "mcquay.me/yay"
yay.Sequence )
}
func NewYay() *Yay { const usage = "usage: yay <shrug|dance>"
y := &Yay{
yay.Sequence{
Frames: [][]rune{
[]rune(`.o.`),
[]rune(`.o.`),
[]rune(`.o.`),
[]rune(`.o.`),
[]rune(`.o.`),
[]rune(`.o.`),
[]rune(`-o-`),
[]rune(`\o/`),
[]rune(`\o/`),
[]rune(`\o/`),
[]rune(`-o-`),
},
},
}
return y
}
func main() { func main() {
t := yay.NewViewPort(NewYay()) cmd := "yay"
if len(os.Args) > 1 {
cmd = os.Args[1]
}
var t *yay.ViewPort
switch cmd {
case "yay":
t = yay.NewViewPort(yay.NewYay())
case "shrug":
t = yay.NewViewPort(yay.NewShrug())
case "dance":
t = yay.NewViewPort(yay.NewDance())
default:
fmt.Fprintf(os.Stderr, "%s\n", usage)
os.Exit(1)
}
t.Run() t.Run()
} }

View File

@ -1,14 +1,12 @@
package main package yay
import "mcquay.me/yay"
type Dance struct { type Dance struct {
yay.Sequence Sequence
} }
func NewDance() *Dance { func NewDance() *Dance {
d := &Dance{ d := &Dance{
yay.Sequence{ Sequence{
Frames: [][]rune{ Frames: [][]rune{
[]rune(`<('o'<) `), []rune(`<('o'<) `),
[]rune(` ('-') `), []rune(` ('-') `),
@ -22,8 +20,3 @@ func NewDance() *Dance {
} }
return d return d
} }
func main() {
t := yay.NewViewPort(NewDance())
t.Run()
}

View File

@ -1,14 +1,12 @@
package main package yay
import "mcquay.me/yay"
type Shrug struct { type Shrug struct {
yay.Sequence Sequence
} }
func NewShrug() *Shrug { func NewShrug() *Shrug {
return &Shrug{ return &Shrug{
yay.Sequence{ Sequence{
Frames: [][]rune{ Frames: [][]rune{
[]rune(`¯\_(ツ )_/¯`), []rune(`¯\_(ツ )_/¯`),
[]rune(`¯\_(ツ )_/¯`), []rune(`¯\_(ツ )_/¯`),
@ -20,8 +18,3 @@ func NewShrug() *Shrug {
}, },
} }
} }
func main() {
t := yay.NewViewPort(NewShrug())
t.Run()
}

26
src/mcquay.me/yay/yay.go Normal file
View File

@ -0,0 +1,26 @@
package yay
type Yay struct {
Sequence
}
func NewYay() *Yay {
y := &Yay{
Sequence{
Frames: [][]rune{
[]rune(`.o.`),
[]rune(`.o.`),
[]rune(`.o.`),
[]rune(`.o.`),
[]rune(`.o.`),
[]rune(`.o.`),
[]rune(`-o-`),
[]rune(`\o/`),
[]rune(`\o/`),
[]rune(`\o/`),
[]rune(`-o-`),
},
},
}
return y
}