-
Notifications
You must be signed in to change notification settings - Fork 0
/
flag.go
111 lines (89 loc) · 2.08 KB
/
flag.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package main
import (
"fmt"
"flag"
)
const (
version = "0.0.0"
description = "Clean up audio collection setting metadata & embedding artwork"
)
const args = `
Positional Args:
PATH directory path
`
const printUsage = `
audiocc v%s
%s
Usage: audiocc [MODE] [OPTIONS] PATH
%s
Mode (specify only one):
--artist "NAME"
treat as specific artist
--collection
treat as collection of artists
Options:
--bitrate "BITRATE"
V0 (default)
convert to variable 256kbps mp3
320
convert to constant 320kbps mp3
--fast
skips album directory if starts w/ year
--fix
fixes incorrect track length, ie 1035:36:51
--force
processes all files, even if path info matches tag info
--write
write changes to disk
Debug:
--version
print program version, then exit
`
type Flags struct {
Artist, Bitrate string
Collection, Fast, Fix, Force, Version, Write bool
}
var flags = Flags{}
func init() {
// setup mode
flag.StringVar(&flags.Artist, "artist", "", "")
flag.BoolVar(&flags.Collection, "collection", false, "")
// setup options
flag.StringVar(&flags.Bitrate, "bitrate", "V0", "")
flag.BoolVar(&flags.Fast, "fast", false, "")
flag.BoolVar(&flags.Fix, "fix", false, "")
flag.BoolVar(&flags.Force, "force", false, "")
flag.BoolVar(&flags.Write, "write", false, "")
// detup debug options
flag.BoolVar(&flags.Version, "version", false, "")
// --help
flag.Usage = func() {
fmt.Printf(printUsage, version, description, args)
fmt.Println()
}
}
func processFlags() ([]string, bool) {
flag.Parse()
a := flag.Args()
// --version
if flags.Version {
fmt.Printf("%s\n", version)
return a, false
}
// show --help unless args
if len(a) != 1 {
flag.Usage()
return a, false
}
// must specify --artist OR --collection
if flags.Artist == "" && !flags.Collection {
fmt.Printf("\nError: Must provide option --artist OR --collection\n")
flag.Usage()
return a, false
}
// default to V0 unless 320 specified
if flags.Bitrate != "320" {
flags.Bitrate = "V0"
}
return a, true
}