-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd.go
More file actions
151 lines (140 loc) · 3.97 KB
/
Copy pathcmd.go
File metadata and controls
151 lines (140 loc) · 3.97 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package main
import (
"context"
"fmt"
altsrc "github.com/urfave/cli-altsrc/v3"
"github.com/urfave/cli-altsrc/v3/toml"
"github.com/urfave/cli/v3"
)
var Version string
const (
demoFlagName = "demo"
configFlagName = "config"
createConfigFlagName = "create-config"
debugFlagName = "debug"
makemkvconFlagName = "makemkvcon"
profileFlagName = "profile"
createProfileFlagName = "create-profile"
cacheFlagName = "cache"
minLengthFlagName = "minlength"
outputDirFlagName = "output-dir"
quietFlagName = "quiet"
askForTitleFlagName = "ask-title"
logFileFlagName = "log"
)
const (
defaultConfigPath = "mkvbot.toml"
defaultProfilePath = "makemkv.xml"
)
// configPath holds the resolved --config value. It is populated when urfave/cli
// parses the --config flag (via Destination) and is read indirectly by every
// other flag's TOML source through a StringPtrSourcer, which dereferences it
// lazily at Lookup time.
var configPath string
func newCLICommand() *cli.Command {
configSource := altsrc.NewStringPtrSourcer(&configPath)
tomlSource := func(key string) cli.ValueSourceChain {
return cli.NewValueSourceChain(toml.TOML(key, configSource))
}
cmd := &cli.Command{
Name: "mkvbot",
Version: Version,
Usage: "Automation for makemkv",
Copyright: "(c) 2025–2026 Curt Hash",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: demoFlagName,
Usage: "show the TUI with fake data and exit on Ctrl+C",
},
&cli.StringFlag{
Name: configFlagName,
Value: defaultConfigPath,
Usage: "`PATH` to mkvbot config file (TOML)",
Destination: &configPath,
},
&cli.BoolFlag{
Name: createConfigFlagName,
Usage: fmt.Sprintf("write a default mkvbot config file (%q) then exit", defaultConfigPath),
},
&cli.BoolFlag{
Name: debugFlagName,
Value: false,
Usage: "log debug messages",
Sources: tomlSource("debug"),
},
&cli.StringFlag{
Name: makemkvconFlagName,
Value: "",
Usage: "`PATH` to makemkvcon executable",
Aliases: []string{"m"},
Sources: tomlSource("makemkvcon_path"),
},
&cli.StringFlag{
Name: profileFlagName,
Value: defaultProfilePath,
Usage: "pass --profile=`PATH` to makemkv",
Aliases: []string{"p"},
Sources: tomlSource("makemkv_profile_path"),
},
&cli.BoolFlag{
Name: createProfileFlagName,
Usage: fmt.Sprintf("write the default makemkv profile (%q) then exit", defaultProfilePath),
},
&cli.Int64Flag{
Name: cacheFlagName,
Value: 1024,
Usage: "pass --cache=`SIZE`MiB to makemkv",
Aliases: []string{"c"},
Sources: tomlSource("cache_size"),
},
&cli.Int64Flag{
Name: minLengthFlagName,
Value: 1800,
Usage: "pass --minlength=`N` to makemkv",
Aliases: []string{"l"},
Sources: tomlSource("min_length"),
},
&cli.StringFlag{
Name: outputDirFlagName,
Value: ".",
Usage: "create output files in `DIR`",
Aliases: []string{"o"},
Sources: tomlSource("output_dir_path"),
},
&cli.BoolFlag{
Name: quietFlagName,
Usage: "do not beep",
Aliases: []string{"q"},
Sources: tomlSource("quiet"),
},
&cli.BoolFlag{
Name: askForTitleFlagName,
Usage: "ask you to choose the best title",
Aliases: []string{"a"},
Sources: tomlSource("ask_for_title"),
},
&cli.StringFlag{
Name: logFileFlagName,
Usage: "append log messages to `FILE`",
Aliases: []string{"L"},
Sources: tomlSource("log_file_path"),
},
},
Commands: []*cli.Command{
newUpdateKeyCommand(),
},
Action: func(ctx context.Context, cmd *cli.Command) error {
return run(ctx, cmd)
},
}
for _, h := range bestTitleHeuristics {
cmd.Flags = append(cmd.Flags, &cli.Int64Flag{
Name: h.flagName,
Value: h.weight,
Usage: h.flagUsage,
Destination: &h.weight,
Sources: tomlSource("best_title_heuristic_weights." + h.name),
})
}
return cmd
}