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
import "mcquay.me/yay"
import (
"fmt"
"os"
type Yay struct {
yay.Sequence
}
"mcquay.me/yay"
)
func NewYay() *Yay {
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
}
const usage = "usage: yay <shrug|dance>"
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()
}

View File

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

View File

@ -1,14 +1,12 @@
package main
import "mcquay.me/yay"
package yay
type Shrug struct {
yay.Sequence
Sequence
}
func NewShrug() *Shrug {
return &Shrug{
yay.Sequence{
Sequence{
Frames: [][]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
}