mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 00:02:37 +02:00
add reset option
This commit is contained in:
parent
d470338d2b
commit
1dcbe4468d
@ -100,6 +100,7 @@ func (c *Converter) InitParse() {
|
||||
c.AddSection("Default config")
|
||||
c.AddBoolParam(&c.Options.Show, "show", false, "Show your default parameters")
|
||||
c.AddBoolParam(&c.Options.Save, "save", false, "Save your parameters as default")
|
||||
c.AddBoolParam(&c.Options.Reset, "reset", false, "Reset your parameters to default")
|
||||
|
||||
c.AddSection("Other")
|
||||
c.AddBoolParam(&c.Options.Help, "help", false, "Show this help message")
|
||||
|
@ -34,8 +34,9 @@ type Options struct {
|
||||
LimitMb int `yaml:"limit_mb"`
|
||||
|
||||
// Default Config
|
||||
Show bool `yaml:"-"`
|
||||
Save bool `yaml:"-"`
|
||||
Show bool `yaml:"-"`
|
||||
Save bool `yaml:"-"`
|
||||
Reset bool `yaml:"-"`
|
||||
|
||||
// Other
|
||||
Help bool `yaml:"-"`
|
||||
@ -151,6 +152,11 @@ func (o *Options) ShowDefault() string {
|
||||
)
|
||||
}
|
||||
|
||||
func (o *Options) ResetDefault() error {
|
||||
New().SaveDefault()
|
||||
return o.LoadDefault()
|
||||
}
|
||||
|
||||
func (o *Options) SaveDefault() error {
|
||||
f, err := os.Create(o.FileName())
|
||||
if err != nil {
|
||||
|
12
main.go
12
main.go
@ -33,6 +33,18 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
if cmd.Options.Reset {
|
||||
cmd.Options.ResetDefault()
|
||||
fmt.Fprintf(
|
||||
os.Stderr,
|
||||
"%s%s\n\nReset default to %s\n",
|
||||
cmd.Options.Header(),
|
||||
cmd.Options.ShowDefault(),
|
||||
cmd.Options.FileName(),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if err := cmd.Validate(); err != nil {
|
||||
cmd.Fatal(err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user