17778: update docs.
[arvados.git] / lib / costanalyzer / cmd.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: Apache-2.0
4
5 package costanalyzer
6
7 import (
8         "io"
9         "time"
10
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         uuids      arrayFlags
19         resultsDir string
20         cache      bool
21         begin      time.Time
22         end        time.Time
23 }
24
25 type NoPrefixFormatter struct{}
26
27 func (f *NoPrefixFormatter) Format(entry *logrus.Entry) ([]byte, error) {
28         return []byte(entry.Message), nil
29 }
30
31 // RunCommand implements the subcommand "costanalyzer <collection> <collection> ..."
32 func (c command) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
33         var err error
34         logger := ctxlog.New(stderr, "text", "info")
35         defer func() {
36                 if err != nil {
37                         logger.Error("\n" + err.Error() + "\n")
38                 }
39         }()
40
41         logger.SetFormatter(new(NoPrefixFormatter))
42
43         exitcode, err := c.costAnalyzer(prog, args, logger, stdout, stderr)
44
45         return exitcode
46 }