Files
kopia/cli/command_user_list.go
Jarek Kowalski 74833cefcb cli: added standard --json flags to several commands (#910)
* cli: added standard --json flags to several commands

Fixes #272

* Update flag description

Co-authored-by: Julio López <julio+gh@kasten.io>
2021-03-25 17:55:18 -07:00

40 lines
704 B
Go

package cli
import (
"context"
"github.com/pkg/errors"
"github.com/kopia/kopia/internal/user"
"github.com/kopia/kopia/repo"
)
var userListCommand = userCommands.Command("list", "List users").Alias("ls")
func runUserList(ctx context.Context, rep repo.Repository) error {
var jl jsonList
jl.begin()
defer jl.end()
profiles, err := user.ListUserProfiles(ctx, rep)
if err != nil {
return errors.Wrap(err, "error listing user profiles")
}
for _, p := range profiles {
if jsonOutput {
jl.emit(p)
} else {
printStdout("%v\n", p.Username)
}
}
return nil
}
func init() {
registerJSONOutputFlags(userListCommand)
userListCommand.Action(repositoryReaderAction(runUserList))
}