Skip to content

Commit

Permalink
remove version reporting from v1 command
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Mar 11, 2023
1 parent f82d293 commit 1d41414
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 48 deletions.
26 changes: 1 addition & 25 deletions cmd/slackdump/internal/v1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"flag"
"fmt"
"io"
"os"
"os/signal"
"runtime/trace"
Expand Down Expand Up @@ -33,8 +32,6 @@ const (
envSlackToken = "SLACK_TOKEN"
envSlackCookie = "COOKIE"
envSlackFileToken = "SLACK_FILE_TOKEN"

bannerFmt = "Slackdump %[1]s Copyright (c) 2018-%[2]s rusq (build: %s)\n\n"
)

var CmdV1 = &base.Command{
Expand Down Expand Up @@ -86,12 +83,6 @@ func init() {
// defFilenameTemplate is the default file naming template.
const defFilenameTemplate = "{{.ID}}{{ if .ThreadTS}}-{{.ThreadTS}}{{end}}"

var (
build = "dev"
buildYear = "2077"
commit = "placeholder"
)

// secrets defines the names of the supported secret files that we load our
// secrets from. Inexperienced Windows users might have bad experience trying
// to create .env file with the notepad as it will battle for having the
Expand All @@ -107,20 +98,14 @@ type params struct {
traceFile string // trace file
logFile string //log file, if not specified, outputs to stderr.

printVersion bool
verbose bool
verbose bool
}

func runV1(ctx context.Context, cmd *base.Command, args []string) error {
banner(os.Stderr)
loadSecrets(secrets)

params, cfgErr := parseCmdLine(args[0:])

if params.printVersion {
fmt.Println(build)
return nil
}
if params.authReset {
if err := cache.AuthReset(params.appCfg.SlackConfig.CacheDir); err != nil {
if !os.IsNotExist(err) {
Expand Down Expand Up @@ -382,7 +367,6 @@ func parseCmdLine(args []string) (params, error) {
// - main executable parameters
fs.StringVar(&p.logFile, "log", osenv.Value("LOG_FILE", ""), "log `file`, if not specified, messages are printed to STDERR")
fs.StringVar(&p.traceFile, "trace", osenv.Value("TRACE_FILE", ""), "trace `file` (optional)")
fs.BoolVar(&p.printVersion, "V", false, "print version and exit")
fs.BoolVar(&p.verbose, "v", osenv.Value("DEBUG", false), "verbose messages")

os.Unsetenv(envSlackToken)
Expand All @@ -404,17 +388,9 @@ func parseCmdLine(args []string) (params, error) {

// validate checks if the parameters are valid.
func (p *params) validate() error {
if p.printVersion {
return nil
}
return p.appCfg.Validate()
}

// banner prints the program banner.
func banner(w io.Writer) {
fmt.Fprintf(w, bannerFmt, build, buildYear, trunc(commit, 7))
}

// trunc truncates string s to n chars
func trunc(s string, n uint) string {
if uint(len(s)) <= n {
Expand Down
23 changes: 0 additions & 23 deletions cmd/slackdump/internal/v1/main_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package v1

import (
"bytes"
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -109,27 +107,6 @@ func Test_checkParameters(t *testing.T) {
}
}

func Test_banner(t *testing.T) {
tests := []struct {
name string
wantW string
}{
{
"make sure I haven't fucked up",
fmt.Sprintf(bannerFmt, version, commit, date),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
w := &bytes.Buffer{}
banner(w)
if gotW := w.String(); gotW != tt.wantW {
t.Errorf("banner() = %v, want %v", gotW, tt.wantW)
}
})
}
}

func Test_trunc(t *testing.T) {
type args struct {
s string
Expand Down

0 comments on commit 1d41414

Please sign in to comment.