17840: Deduplicate flag-parsing code.
[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
31         exitcode, err := c.costAnalyzer(prog, args, logger, stdout, stderr)
32         if err != nil {
33                 logger.Error("\n" + err.Error())
34         }
35         return exitcode
36 }