-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (64 loc) · 1.3 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"log"
"os"
"github.com/urfave/cli/v2"
)
var (
app = cli.App{
Name: "snapsound",
Version: "0.1.0",
Usage: "Play pixels",
Commands: []*cli.Command{&snap, &sound, &play},
}
snap = cli.Command{
Name: "snap",
Usage: "Snap that shot",
Args: true,
ArgsUsage: "<SOURCE>",
Action: snapAction,
}
sound = cli.Command{
Name: "sound",
Usage: "Make it yours",
Args: true,
ArgsUsage: "<SOURCE>",
Action: soundAction,
}
play = cli.Command{
Name: "play",
Usage: "Play it now",
Args: true,
ArgsUsage: "<SOURCE>",
Action: playAction,
}
)
func snapAction(ctx *cli.Context) error {
name := ctx.Args().First()
bytes, err := readFile(name)
if err != nil {
return err
}
return saveImage(trimExtension(name)+".png", encodeBytesAsImage(bytes))
}
func soundAction(ctx *cli.Context) error {
name := ctx.Args().First()
bytes, err := originalBytesFromFile(name)
if err != nil {
return err
}
return saveFile(trimExtension(name)+" (Reverted).mp3", bytes)
}
func playAction(ctx *cli.Context) error {
name := ctx.Args().First()
bytes, err := originalBytesFromFile(name)
if err != nil {
return err
}
return playBytes(bytes)
}
func main() {
if err := app.Run(os.Args); err != nil {
log.Fatalln(err)
}
}