Files
kopia/cli/command_user_delete.go
Jarek Kowalski d2288c443f cli: major refactoring (#1046)
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
2021-05-03 10:28:00 -07:00

32 lines
753 B
Go

package cli
import (
"context"
"github.com/pkg/errors"
"github.com/kopia/kopia/internal/user"
"github.com/kopia/kopia/repo"
)
type commandServerUserDelete struct {
name string
}
func (c *commandServerUserDelete) setup(svc appServices, parent commandParent) {
cmd := parent.Command("delete", "Delete user").Alias("remove").Alias("rm")
cmd.Arg("username", "The username to delete.").Required().StringVar(&c.name)
cmd.Action(svc.repositoryWriterAction(c.run))
}
func (c *commandServerUserDelete) run(ctx context.Context, rep repo.RepositoryWriter) error {
err := user.DeleteUserProfile(ctx, rep, c.name)
if err != nil {
return errors.Wrap(err, "error deleting user profile")
}
log(ctx).Infof("User %q deleted.", c.name)
return nil
}