Skip to content

Commit

Permalink
Add propagating verbose to external subcommands(CanastaWiki#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
chl178 committed Mar 15, 2023
1 parent 57e3620 commit 4076120
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/Canasta-CLI.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions internal/execute/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ import (
func Run(path, command string, cmdArgs ...string) (error, string) {
var stdout bytes.Buffer
var stderr bytes.Buffer

isVerbose := logging.GetVerbose()
if isVerbose {
if command == "docker-compose" {
cmdArgs = append([]string{"--verbose"}, cmdArgs...)
}
}

logging.Print(fmt.Sprint(command, " ", strings.Join(cmdArgs, " ")))
cmd := exec.Command("bash", "-c", command+" "+strings.Join(cmdArgs, " "))
cmd.Stdout = &stdout
Expand Down
4 changes: 4 additions & 0 deletions internal/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ func SetVerbose(v bool) {
verbose = v
}

func GetVerbose() bool {
return verbose
}

func Print(output string) {
log.SetFlags(0)
if verbose {
Expand Down

0 comments on commit 4076120

Please sign in to comment.