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

feat: have --quiet supress all stderr messages for success #151

Merged
merged 1 commit into from
Nov 14, 2023
Merged
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ Your desired level of fanciness.

`-q`, `--quiet`, `MODS_QUIET`

Output nothing to standard err.
Only output errors to standard err. Hides the spinner and success messages
that would go to standard err.

#### Reset Settings

Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var help = map[string]string{
"prompt": "Include the prompt from the arguments and stdin, truncate stdin to specified number of lines.",
"prompt-args": "Include the prompt from the arguments in the response.",
"raw": "Render output as raw text when connected to a TTY.",
"quiet": "Quiet mode (hide the spinner while loading).",
"quiet": "Quiet mode (hide the spinner while loading and stderr messages for success).",
"help": "Show help and exit.",
"version": "Show version and exit.",
"max-retries": "Maximum number of times to retry API calls.",
Expand Down
50 changes: 30 additions & 20 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ var (
)}
}

fmt.Fprintln(stderr, "Wrote config file to:", config.SettingsPath)
if !config.Quiet {
fmt.Fprintln(stderr, "Wrote config file to:", config.SettingsPath)
}
return nil
}

Expand Down Expand Up @@ -308,12 +310,14 @@ func resetSettings() error {
if err != nil {
return modsError{err, "Couldn't write new config file."}
}
fmt.Fprintln(os.Stderr, "\nSettings restored to defaults!")
fmt.Fprintf(os.Stderr,
"\n %s %s\n\n",
stderrStyles().Comment.Render("Your old settings have been saved to:"),
stderrStyles().Link.Render(config.SettingsPath+".bak"),
)
if !config.Quiet {
fmt.Fprintln(os.Stderr, "\nSettings restored to defaults!")
fmt.Fprintf(os.Stderr,
"\n %s %s\n\n",
stderrStyles().Comment.Render("Your old settings have been saved to:"),
stderrStyles().Link.Render(config.SettingsPath+".bak"),
)
}
return nil
}

Expand All @@ -331,7 +335,9 @@ func deleteConversation() error {
return modsError{err, "Couldn't delete conversation."}
}

fmt.Fprintln(os.Stderr, "Conversation deleted:", convo.ID[:sha1minLen])
if !config.Quiet {
fmt.Fprintln(os.Stderr, "Conversation deleted:", convo.ID[:sha1minLen])
}
return nil
}

Expand Down Expand Up @@ -380,12 +386,14 @@ func listConversations() error {

func saveConversation(mods *Mods) error {
if config.NoCache {
fmt.Fprintf(
os.Stderr,
"\nConversation was not saved because %s or %s is set.\n",
stderrStyles().InlineCode.Render("--no-cache"),
stderrStyles().InlineCode.Render("NO_CACHE"),
)
if !config.Quiet {
fmt.Fprintf(
os.Stderr,
"\nConversation was not saved because %s or %s is set.\n",
stderrStyles().InlineCode.Render("--no-cache"),
stderrStyles().InlineCode.Render("NO_CACHE"),
)
}
return nil
}

Expand Down Expand Up @@ -415,11 +423,13 @@ func saveConversation(mods *Mods) error {
)}
}

fmt.Fprintln(
os.Stderr,
"\nConversation saved:",
stderrStyles().InlineCode.Render(config.cacheWriteToID[:sha1short]),
stderrStyles().Comment.Render(title),
)
if !config.Quiet {
fmt.Fprintln(
os.Stderr,
"\nConversation saved:",
stderrStyles().InlineCode.Render(config.cacheWriteToID[:sha1short]),
stderrStyles().Comment.Render(title),
)
}
return nil
}
Loading