Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add silent mode - Don't show progress messages #12

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions internal/out/out.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ import (
"log"
)

var Silent = false

func Outf(format string, args ...interface{}) {
if Silent {
return
}
fmt.Printf(format, args...)
}

func Outln(args ...interface{}) {
if Silent {
return
}
fmt.Println(args...)
}

Expand Down
5 changes: 5 additions & 0 deletions internal/pkg/argparsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func parseArgs(flags flagSet) (*cmdArgs, error) {
debug, err := flags.GetBool("debug")
check(err)

silent, err := flags.GetBool("silent")
check(err)

diffArgsStr, err := flags.GetString("diffargs")
check(err)

Expand Down Expand Up @@ -72,6 +75,7 @@ func parseArgs(flags flagSet) (*cmdArgs, error) {
diffArgs: diffArgs,
buildArgs: buildArgs,
debug: debug,
silent: silent,
keepWorktree: keepWorktree,
}, nil
}
Expand All @@ -83,5 +87,6 @@ type cmdArgs struct {
diffArgs []string
buildArgs []string
debug bool
silent bool
keepWorktree bool
}
7 changes: 5 additions & 2 deletions internal/pkg/functionality.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func RunRootCommand(cmd *cobra.Command) {
os.Exit(1)
}
out.Debug = context.debug
out.Silent = context.silent

err = runMain(git.NewGit(), *context)
if err != nil {
Expand Down Expand Up @@ -151,8 +152,10 @@ func runHugo(hugoRootDir string, outputDir string, userArgs []string) error {

// TODO: if --debug is NOT specified, should hang on to these and then only
// print them if an error occurs.
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
if !out.Silent {
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
}
return exec.Run(cmd)
}

Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func main() {
rootCmd.Flags().String("buildargs", "", "Arguments to pass on to the hugo build command")
rootCmd.Flags().BoolP("tool", "t", false, "Invoke 'git difftool' instead of 'git diff'")
rootCmd.Flags().Bool("debug", false, "Enables additional logging")
rootCmd.Flags().Bool("silent", false, "Don't show progress messages.")
rootCmd.Flags().Bool("keep-worktree", false, "Keeps the source worktree around after running grouse. Useful for debugging and development, but adds cruft to your git repo")
rootCmd.Flags().MarkHidden("keep-worktree")
if err := rootCmd.Execute(); err != nil {
Expand Down