Skip to content

Commit

Permalink
renabled verbosity (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsvihladremio committed Oct 12, 2023
1 parent a4ce711 commit 9544cef
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
1 change: 1 addition & 0 deletions cmd/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var linkCmd = &cobra.Command{
`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
SetVerbosity()
if C.SsAPIKey == "" {
slog.Error("ss-api-key is not set and this is required")
os.Exit(1)
Expand Down
15 changes: 11 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,11 @@ var programLevel = new(slog.LevelVar) // Info by default
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
//initialize logger with verbosity set
if Verbose {
programLevel.Set(slog.LevelDebug)
}
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}

}

func DefaultDownloadDir() string {
Expand Down Expand Up @@ -104,6 +101,16 @@ func init() {
initConfig()
}

// made avaiable to subcommands via this method
func SetVerbosity() {
//initialize logger with verbosity set
if Verbose {
programLevel.Set(slog.LevelDebug)
} else {
programLevel.Set(slog.LevelInfo)
}
}

// initConfig reads in config file if present
func initConfig() {
fileToLoad, err := config.ReadConfigFile(cfgFile)
Expand Down
43 changes: 43 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright 2022 Ryan SVIHLA
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// cmd package contains all the command line flag configuration
package cmd

import (
"log/slog"
"testing"

"github.com/stretchr/testify/assert"
)

func TestVerbosityLevel(t *testing.T) {
defer func() {
Verbose = false
}()
Verbose = true
SetVerbosity()
assert.Equal(t, slog.LevelDebug, programLevel.Level())
}

func TestVerbosityLevelDefault(t *testing.T) {
defer func() {
Verbose = false
}()
Verbose = false
SetVerbosity()
assert.Equal(t, slog.LevelInfo, programLevel.Level())
}
1 change: 1 addition & 0 deletions cmd/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var ticketCmd = &cobra.Command{
`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
SetVerbosity()
d := downloader.NewGenericDownloader(DownloadBufferSize)
password := ""
if useZendeskPassword {
Expand Down

0 comments on commit 9544cef

Please sign in to comment.