Skip to content

Commit

Permalink
feat: Add quiet flag to disable logging executed commands (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
pojntfx committed Aug 25, 2021
1 parent fb60f8a commit 3525b0d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Usage: %s [OPTION...] "<COMMAND...>"
contextFlag := pflag.StringP("context", "c", "", "Directory to use in the container")
extraArgs := pflag.StringP("extra-args", "e", "", "Extra arguments to pass to the Docker command")
pullFlag := pflag.BoolP("pull", "p", false, "Always pull the latest available tag of the Docker images")
quietFlag := pflag.BoolP("quiet", "q", false, "Disable logging executed commands")

pflag.Parse()

Expand Down Expand Up @@ -86,7 +87,9 @@ Usage: %s [OPTION...] "<COMMAND...>"
for _, target := range targets {
existsCmd := exec.Command("docker", strings.Split(fmt.Sprintf(`inspect %v`, getImageNameWithSuffix(target.OS, target.Architecture)), " ")...)

log.Println(existsCmd)
if !*quietFlag {
log.Println(existsCmd)
}

shouldPullAndTag := true
if *pullFlag {
Expand All @@ -104,15 +107,19 @@ Usage: %s [OPTION...] "<COMMAND...>"
if !shouldPullAndTag {
runCmd := exec.Command("docker", strings.Split(fmt.Sprintf(`pull --platform linux/%v %v`, target.Architecture, target.OS), " ")...)

log.Println(runCmd)
if !*quietFlag {
log.Println(runCmd)
}

if output, err := runCmd.CombinedOutput(); err != nil {
log.Fatalln("could not pull image:", err.Error()+":", string(output))
}

tagCmd := exec.Command("docker", strings.Split(fmt.Sprintf(`tag %v %v`, target.OS, getImageNameWithSuffix(target.OS, target.Architecture)), " ")...)

log.Println(tagCmd)
if !*quietFlag {
log.Println(tagCmd)
}

if output, err := tagCmd.CombinedOutput(); err != nil {
log.Fatalln("could not tag image:", err.Error()+":", string(output))
Expand Down Expand Up @@ -152,7 +159,9 @@ Usage: %s [OPTION...] "<COMMAND...>"
// Construct the command
cmd := exec.Command("docker", append(strings.Split(dockerArgs, " "), commandArgs)...)

log.Println(cmd)
if !*quietFlag {
log.Println(cmd)
}

// Handle interactivity
if *itFlag {
Expand Down

0 comments on commit 3525b0d

Please sign in to comment.