-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
66 lines (53 loc) · 1.5 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
/*
Contents: wav to DSB converter.
This program converts .wav file to .DSB files.
Please run `wav_to_DSB --help` for details.
Usage: wav_to_DSB (-o /path/to/out.DSB) /path/to/file.wav
Author: Tetsu Takizawa
E-mail: tt15219@tomakomai.kosen-ac.jp
LastUpdate: 2019/11/16
DateCreated : 2019/11/16
*/
package main
import (
"os"
"github.com/pkg/errors"
"github.com/urfave/cli"
"github.com/tetsuzawa/research-tools/goresearch"
)
func main() {
app := cli.NewApp()
defer app.Run(os.Args)
app.CustomAppHelpTemplate = HelpTemplate
app.Name = "wav_to_DSB"
app.Usage = `This app converts .wav file to .DSB file.`
app.Version = "0.1.0"
app.Action = action
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "outpath, o",
Usage: "specify output path like as /path/to/file",
},
}
}
func action(ctx *cli.Context) error {
if ctx.Args().Get(0) == "" {
return cli.NewExitError("too few arguments. need input file path. \nUsage: wav-to-DSB-multi /path/to/file.wav", 2)
}
fileName := ctx.Args().Get(0)
name, ext := goresearch.SplitPathAndExt(fileName)
if ext != ".wav" {
return cli.NewExitError("incorrect file format. need .wav file. \nUsage: wav-to-DSB-multi /path/to/file.wav", 2)
}
if ctx.String("o") != "" {
argName := ctx.String("o")
name, _ = goresearch.SplitPathAndExt(argName)
}
f, err := os.Open(fileName)
if err != nil {
err = errors.Wrap(err, "error occurred while opening input file")
return cli.NewExitError("no such a file", 2)
}
defer f.Close()
return wavToDSB(ctx, f, name)
}