16573: add a deduplication-report command to arvados-client
[arvados.git] / lib / deduplicationreport / command.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: Apache-2.0
4
5 package deduplicationreport
6
7 import (
8         "io"
9
10         "git.arvados.org/arvados.git/lib/config"
11         "git.arvados.org/arvados.git/sdk/go/ctxlog"
12         "github.com/sirupsen/logrus"
13 )
14
15 var Command command
16
17 type command struct{}
18
19 type NoPrefixFormatter struct{}
20
21 func (f *NoPrefixFormatter) Format(entry *logrus.Entry) ([]byte, error) {
22         return []byte(entry.Message), nil
23 }
24
25 // RunCommand implements the subcommand "deduplication-report <collection> <collection> ..."
26 func (command) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
27         var err error
28         logger := ctxlog.New(stderr, "text", "info")
29         defer func() {
30                 if err != nil {
31                         logger.WithError(err).Error("fatal")
32                 }
33         }()
34
35         logger.SetFormatter(new(NoPrefixFormatter))
36
37         loader := config.NewLoader(stdin, logger)
38         loader.SkipLegacy = true
39
40         exitcode := report(prog, args, loader, logger, stdout, stderr)
41
42         return exitcode
43 }