-
Notifications
You must be signed in to change notification settings - Fork 177
feat(notify): make permission-prompt alerts on by default and discoverable #1001
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
Open
gauravbhatia4601
wants to merge
6
commits into
Gitlawb:main
Choose a base branch
from
gauravbhatia4601:feat/notify-discoverable
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a269245
feat(notify): make permission-prompt alerts on by default and discove…
cf4e7be
Merge remote-tracking branch 'origin/main' into feat/notify-discoverable
334c688
fix(notify): apply review feedback from CodeRabbit
15929bf
fix(notify): read cfg under the lock in Notify
18e851a
fix(notify): keep defaults out of the resolver; preserve the user's o…
703d9f5
fix(cli): zero config notify no longer requires a configured provider
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io" | ||
| "strings" | ||
|
|
||
| "github.com/Gitlawb/zero/internal/config" | ||
| ) | ||
|
|
||
| // runConfigNotify implements `zero config notify`: with no flags it prints the | ||
| // current mode/focusMode; --mode/--focus update them via the same | ||
| // config.SetNotify writer the TUI /notify command uses, so all surfaces stay | ||
| // in lockstep; --reset blanks both fields so the resolver defaults apply. | ||
| func runConfigNotify(args []string, stdout io.Writer, stderr io.Writer, deps appDeps) int { | ||
| options, help, err := parseConfigNotifyArgs(args) | ||
| if err != nil { | ||
| return writeExecUsageError(stderr, err.Error()) | ||
| } | ||
| if help { | ||
| if err := writeConfigNotifyHelp(stdout); err != nil { | ||
| return exitCrash | ||
| } | ||
| return exitSuccess | ||
| } | ||
|
|
||
| resolved, exitCode := resolveCommandCenterConfig(stderr, deps) | ||
| if exitCode != exitSuccess { | ||
| return exitCode | ||
| } | ||
|
|
||
| if options.mode != "" || options.focus != "" || options.reset { | ||
| configPath, err := deps.userConfigPath() | ||
| if err != nil { | ||
| return writeAppError(stderr, err.Error(), exitCrash) | ||
| } | ||
| notify := config.NotifyConfig{Mode: options.mode, FocusMode: options.focus} | ||
| if options.reset { | ||
| notify = config.NotifyConfig{} | ||
| } | ||
| if _, err := config.SetNotify(configPath, notify); err != nil { | ||
| return writeAppError(stderr, err.Error(), exitUsage) | ||
| } | ||
| // Re-resolve so the printed value reflects what the next launch will | ||
| // actually use (e.g. a reset shows the built-in defaults). | ||
| resolved, exitCode = resolveCommandCenterConfig(stderr, deps) | ||
| if exitCode != exitSuccess { | ||
| return exitCode | ||
| } | ||
| } | ||
|
|
||
| if options.json { | ||
| if err := writePrettyJSON(stdout, map[string]any{ | ||
| "mode": resolved.Notify.Mode, | ||
| "focusMode": resolved.Notify.FocusMode, | ||
| }); err != nil { | ||
| return exitCrash | ||
| } | ||
| return exitSuccess | ||
| } | ||
| lines := []string{ | ||
| "Notify", | ||
| "mode: " + displayCLIValue(resolved.Notify.Mode, "(default)"), | ||
| "focusMode: " + displayCLIValue(resolved.Notify.FocusMode, "(default)"), | ||
| } | ||
| if _, err := fmt.Fprintln(stdout, strings.Join(lines, "\n")); err != nil { | ||
| return exitCrash | ||
| } | ||
| return exitSuccess | ||
| } | ||
|
|
||
| type configNotifyOptions struct { | ||
| mode string | ||
| focus string | ||
| reset bool | ||
| json bool | ||
| } | ||
|
|
||
| func parseConfigNotifyArgs(args []string) (configNotifyOptions, bool, error) { | ||
| options := configNotifyOptions{} | ||
| for index := 0; index < len(args); index++ { | ||
| arg := args[index] | ||
| switch { | ||
| case arg == "-h" || arg == "--help" || arg == "help": | ||
| return options, true, nil | ||
| case arg == "--json": | ||
| options.json = true | ||
| case arg == "--reset": | ||
| options.reset = true | ||
| case arg == "--mode": | ||
| value, next, err := nextFlagValue(args, index, arg) | ||
| if err != nil { | ||
| return options, false, err | ||
| } | ||
| options.mode = value | ||
| index = next | ||
| case strings.HasPrefix(arg, "--mode="): | ||
| value, err := requiredInlineFlagValue(arg, "--mode") | ||
| if err != nil { | ||
| return options, false, err | ||
| } | ||
| options.mode = value | ||
| case arg == "--focus": | ||
| value, next, err := nextFlagValue(args, index, arg) | ||
| if err != nil { | ||
| return options, false, err | ||
| } | ||
| options.focus = value | ||
| index = next | ||
| case strings.HasPrefix(arg, "--focus="): | ||
| value, err := requiredInlineFlagValue(arg, "--focus") | ||
| if err != nil { | ||
| return options, false, err | ||
| } | ||
| options.focus = value | ||
| case strings.HasPrefix(arg, "-"): | ||
| return options, false, execUsageError{fmt.Sprintf("unknown flag %q", arg)} | ||
| default: | ||
| return options, false, execUsageError{fmt.Sprintf("unexpected argument %q", arg)} | ||
| } | ||
| } | ||
| return options, false, nil | ||
| } | ||
|
|
||
| func writeConfigNotifyHelp(w io.Writer) error { | ||
| _, err := fmt.Fprint(w, "Usage:\n"+ | ||
| " zero config notify [flags]\n"+ | ||
| "\n"+ | ||
| "Print or update the permission-prompt notify preference.\n"+ | ||
| "\n"+ | ||
| "When run with no flag, prints the current mode and focusMode (the resolver\n"+ | ||
| "defaults to \"both\" and \"unfocused\" when the config block is empty).\n"+ | ||
| "\n"+ | ||
| "Examples:\n"+ | ||
| " zero config notify\n"+ | ||
| " zero config notify --json\n"+ | ||
| " zero config notify --mode both --focus unfocused\n"+ | ||
| " zero config notify --mode off\n"+ | ||
| " zero config notify --reset # clear config so the resolver defaults apply\n"+ | ||
| "\n"+ | ||
| "Flags:\n"+ | ||
| " --mode <off|bell|notify|both> Notification mechanism\n"+ | ||
| " --focus <unfocused|always|focused> When the alert fires\n"+ | ||
| " --reset Clear both fields so the resolver defaults apply\n"+ | ||
| " --json Machine-readable output\n"+ | ||
| " -h, --help Show this help\n") | ||
| return err | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.