add reset option

This commit is contained in:
Celogeek 2023-04-02 23:40:37 +02:00
parent d470338d2b
commit 1dcbe4468d
Signed by: celogeek
SSH Key Fingerprint: SHA256:njNJLzoLQdbV9PC6ehcruRb0QnEgxABoCYZ+0+aUIYc
3 changed files with 21 additions and 2 deletions

View File

@ -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")

View File

@ -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
View File

@ -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)
}