mirror of
https://github.com/kopia/kopia.git
synced 2026-01-23 22:07:54 -05:00
cli: major refactoring of how CLI commands are registered The goal is to eliminate flags as global variables to allow for better testing. Each command and subcommand and most sets of flags are now their own struct with 'setup()' methods that attached the flags or subcommand to the provided parent. This change is 94.3% mechanical, but is fully organic and hand-made. * introduced cli.appServices interface which provides the environment in which commands run * remove auto-maintenance global flag * removed globals in memory_tracking.go * removed globals from cli_progress.go * removed globals from the update_check.go * moved configPath into TheApp * removed remaining globals from config.go * refactored logfile to get rid of global variables * removed 'app' global variable * linter fixes * fixed password_*.go build * fixed BSD build
39 lines
1.5 KiB
Go
39 lines
1.5 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/alecthomas/kingpin"
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/kopia/kopia/snapshot/policy"
|
|
)
|
|
|
|
type policyErrorFlags struct {
|
|
policyIgnoreFileErrors string
|
|
policyIgnoreDirectoryErrors string
|
|
policyIgnoreUnknownTypes string
|
|
}
|
|
|
|
func (c *policyErrorFlags) setup(cmd *kingpin.CmdClause) {
|
|
cmd.Flag("ignore-file-errors", "Ignore errors reading files while traversing ('true', 'false', 'inherit')").EnumVar(&c.policyIgnoreFileErrors, booleanEnumValues...)
|
|
cmd.Flag("ignore-dir-errors", "Ignore errors reading directories while traversing ('true', 'false', 'inherit").EnumVar(&c.policyIgnoreDirectoryErrors, booleanEnumValues...)
|
|
cmd.Flag("ignore-unknown-types", "Ignore unknown entry types in directories ('true', 'false', 'inherit").EnumVar(&c.policyIgnoreUnknownTypes, booleanEnumValues...)
|
|
}
|
|
|
|
func (c *policyErrorFlags) setErrorHandlingPolicyFromFlags(ctx context.Context, fp *policy.ErrorHandlingPolicy, changeCount *int) error {
|
|
if err := applyPolicyBoolPtr(ctx, "ignore file errors", &fp.IgnoreFileErrors, c.policyIgnoreFileErrors, changeCount); err != nil {
|
|
return errors.Wrap(err, "ignore file errors")
|
|
}
|
|
|
|
if err := applyPolicyBoolPtr(ctx, "ignore directory errors", &fp.IgnoreDirectoryErrors, c.policyIgnoreDirectoryErrors, changeCount); err != nil {
|
|
return errors.Wrap(err, "ignore directory errors")
|
|
}
|
|
|
|
if err := applyPolicyBoolPtr(ctx, "ignore unknown types", &fp.IgnoreUnknownTypes, c.policyIgnoreUnknownTypes, changeCount); err != nil {
|
|
return errors.Wrap(err, "ignore unknown types")
|
|
}
|
|
|
|
return nil
|
|
}
|