storj/cmd/uplinkng/cmd_version.go
Jeff Wendling a1bf9ab6de cmd/uplinkng: initial commit with skeleton
Change-Id: I764618cc60c46882955e9b08b72b3c162aa4929f
2021-05-18 10:04:44 -04:00

46 lines
949 B
Go

// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"fmt"
"runtime/debug"
"strconv"
"strings"
"text/tabwriter"
"github.com/zeebo/clingy"
"github.com/zeebo/errs"
)
type cmdVersion struct {
verbose bool
}
func (c *cmdVersion) Setup(a clingy.Arguments, f clingy.Flags) {
c.verbose = f.New(
"verbose", "prints all dependency versions", false,
clingy.Short('v'),
clingy.Transform(strconv.ParseBool)).(bool)
}
func (c *cmdVersion) Execute(ctx clingy.Context) error {
bi, ok := debug.ReadBuildInfo()
if !ok {
return errs.New("unable to read build info")
}
tw := tabwriter.NewWriter(ctx.Stdout(), 4, 4, 4, ' ', 0)
defer func() { _ = tw.Flush() }()
fmt.Fprintf(tw, "%s\t%s\n", bi.Main.Path, bi.Main.Version)
for _, mod := range bi.Deps {
if c.verbose || strings.HasPrefix(mod.Path, "storj.io/") {
fmt.Fprintf(tw, " %s\t%s\n", mod.Path, mod.Version)
}
}
return nil
}