6065ad2c0b2cb934607826d8500215bbabf0d868
[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/lib/cmd"
12         "git.arvados.org/arvados.git/sdk/go/ctxlog"
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 // RunCommand implements the subcommand "costanalyzer <collection> <collection> ..."
26 func (c 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         logger.SetFormatter(cmd.NoPrefixFormatter{})
30         defer func() {
31                 if err != nil {
32                         logger.Error("\n" + err.Error())
33                 }
34         }()
35
36         exitcode, err := c.costAnalyzer(prog, args, logger, stdout, stderr)
37
38         return exitcode
39 }