commit 214932508ac5a1e32a621758f3c12c38be296d2b
parent e169c2834d76b50eddc556db0e111faac8ccce4c
Author: Sean Enck <sean@ttypty.com>
Date: Sun, 6 Oct 2024 19:38:09 -0400
invert conditionals for template clarity
Diffstat:
4 files changed, 25 insertions(+), 23 deletions(-)
diff --git a/internal/app/completions.go b/internal/app/completions.go
@@ -31,10 +31,12 @@ type (
Options []CompletionOption
TOTPSubCommands []CompletionOption
Conditionals struct {
- ReadOnly string
- NoClip string
- NoTOTP string
- AskMode string
+ Not struct {
+ ReadOnly string
+ NoClip string
+ NoTOTP string
+ AskMode string
+ }
}
}
// CompletionOption are conditional wrapped logic for options that may be disabled
@@ -92,10 +94,10 @@ func GenerateCompletions(completionType, exe string) ([]string, error) {
DoList: fmt.Sprintf("%s %s", exe, ListCommand),
DoTOTPList: fmt.Sprintf("%s %s %s", exe, TOTPCommand, TOTPListCommand),
}
- c.Conditionals.ReadOnly = config.EnvReadOnly.ShellIsNotConditional(config.YesValue)
- c.Conditionals.NoClip = config.EnvNoClip.ShellIsNotConditional(config.YesValue)
- c.Conditionals.NoTOTP = config.EnvNoTOTP.ShellIsNotConditional(config.YesValue)
- c.Conditionals.AskMode = config.KeyModeAskConditional()
+ c.Conditionals.Not.ReadOnly = config.EnvReadOnly.ShellIsNotConditional(config.YesValue)
+ c.Conditionals.Not.NoClip = config.EnvNoClip.ShellIsNotConditional(config.YesValue)
+ c.Conditionals.Not.NoTOTP = config.EnvNoTOTP.ShellIsNotConditional(config.YesValue)
+ c.Conditionals.Not.AskMode = config.KeyModeAskConditional()
c.Options = newGenOptions([]string{EnvCommand, HelpCommand, ListCommand, ShowCommand, VersionCommand, JSONCommand},
map[string]shellPreparer{
diff --git a/internal/app/shell/bash.sh b/internal/app/shell/bash.sh
@@ -33,7 +33,7 @@ _{{ $.Executable }}() {
opts="{{ $.HelpAdvancedCommand }}"
;;
"{{ $.InsertCommand }}" | "{{ $.MultiLineCommand }}" | "{{ $.MoveCommand }}" | "{{ $.RemoveCommand }}")
- if {{ $.Conditionals.AskMode }}; then
+ if {{ $.Conditionals.Not.AskMode }}; then
opts="$opts $({{ $.DoList }})"
fi
;;
@@ -46,7 +46,7 @@ _{{ $.Executable }}() {
{{- end}}
;;
"{{ $.ShowCommand }}" | "{{ $.JSONCommand }}" | "{{ $.ClipCommand }}")
- if {{ $.Conditionals.AskMode }}; then
+ if {{ $.Conditionals.Not.AskMode }}; then
opts=$({{ $.DoList }})
fi
;;
@@ -55,7 +55,7 @@ _{{ $.Executable }}() {
if [ "$COMP_CWORD" -eq 3 ]; then
case "$chosen" in
"{{ $.MoveCommand }}")
- if {{ $.Conditionals.AskMode }}; then
+ if {{ $.Conditionals.Not.AskMode }}; then
opts=$({{ $.DoList }})
fi
;;
@@ -64,7 +64,7 @@ _{{ $.Executable }}() {
{{- range $key, $value := $.TOTPSubCommands }}
"{{ $value.Key }}")
if {{ $value.Conditional }}; then
- if {{ $.Conditionals.AskMode }}; then
+ if {{ $.Conditionals.Not.AskMode }}; then
opts=$({{ $.DoTOTPList }})
fi
fi
diff --git a/internal/app/shell/fish.sh b/internal/app/shell/fish.sh
@@ -13,13 +13,13 @@ function {{ $.Executable }}-completion
{{- end }}
complete -c {{ $.Executable }} -n "not __fish_seen_subcommand_from $commands" -a "$commands"
complete -c {{ $.Executable }} -n "__fish_seen_subcommand_from {{ $.HelpCommand }}; and test (count (commandline -opc)) -lt 3" -a "{{ $.HelpAdvancedCommand }}"
- if {{ $.Conditionals.ReadOnly }}
- if {{ $.Conditionals.AskMode }}
+ if {{ $.Conditionals.Not.ReadOnly }}
+ if {{ $.Conditionals.Not.AskMode }}
complete -c {{ $.Executable }} -n "__fish_seen_subcommand_from {{ $.InsertCommand }} {{ $.MultiLineCommand }} {{ $.RemoveCommand }}; and test (count (commandline -opc)) -lt 3" -a "({{ $.DoList }})"
complete -c {{ $.Executable }} -n "__fish_seen_subcommand_from {{ $.MoveCommand }}; and test (count (commandline -opc)) -lt 4" -a "({{ $.DoList }})"
end
end
- if {{ $.Conditionals.NoTOTP }}
+ if {{ $.Conditionals.Not.NoTOTP }}
set -f totps ""
{{- range $idx, $value := $.TOTPSubCommands }}
{{- if gt $idx 0 }}
@@ -30,16 +30,16 @@ function {{ $.Executable }}-completion
end
{{- end }}
complete -c {{ $.Executable }} -n "__fish_seen_subcommand_from {{ $.TOTPCommand }}; and not __fish_seen_subcommand_from $totps" -a "$totps"
- if {{ $.Conditionals.AskMode }}
+ if {{ $.Conditionals.Not.AskMode }}
complete -c {{ $.Executable }} -n "__fish_seen_subcommand_from {{ $.TOTPCommand }}; and __fish_seen_subcommand_from $totps; and test (count (commandline -opc)) -lt 4" -a "({{ $.DoTOTPList }})"
end
end
- if {{ $.Conditionals.NoClip }}
- if {{ $.Conditionals.AskMode }}
+ if {{ $.Conditionals.Not.NoClip }}
+ if {{ $.Conditionals.Not.AskMode }}
complete -c {{ $.Executable }} -n "__fish_seen_subcommand_from {{ $.ClipCommand }}; and test (count (commandline -opc)) -lt 3" -a "({{ $.DoList}})"
end
end
- if {{ $.Conditionals.AskMode }}
+ if {{ $.Conditionals.Not.AskMode }}
complete -c {{ $.Executable }} -n "__fish_seen_subcommand_from {{ $.ShowCommand }} {{ $.JSONCommand }}; and test (count (commandline -opc)) -lt 3" -a "({{ $.DoList}})"
end
end
diff --git a/internal/app/shell/zsh.sh b/internal/app/shell/zsh.sh
@@ -46,7 +46,7 @@ _{{ $.Executable }}() {
;;
"{{ $.InsertCommand }}" | "{{ $.MultiLineCommand }}" | "{{ $.RemoveCommand }}")
if [ "$len" -eq 3 ]; then
- if {{ $.Conditionals.AskMode }}; then
+ if {{ $.Conditionals.Not.AskMode }}; then
compadd "$@" $({{ $.DoList }})
fi
fi
@@ -54,7 +54,7 @@ _{{ $.Executable }}() {
"{{ $.MoveCommand }}")
case "$len" in
3 | 4)
- if {{ $.Conditionals.AskMode }}; then
+ if {{ $.Conditionals.Not.AskMode }}; then
compadd "$@" $({{ $.DoList }})
fi
;;
@@ -75,7 +75,7 @@ _{{ $.Executable }}() {
{{- range $key, $value := .TOTPSubCommands }}
"{{ $value.Key }}")
if {{ $value.Conditional }}; then
- if {{ $.Conditionals.AskMode }}; then
+ if {{ $.Conditionals.Not.AskMode }}; then
compadd "$@" $({{ $.DoTOTPList }})
fi
fi
@@ -86,7 +86,7 @@ _{{ $.Executable }}() {
;;
"{{ $.ShowCommand }}" | "{{ $.JSONCommand }}" | "{{ $.ClipCommand }}")
if [ "$len" -eq 3 ]; then
- if {{ $.Conditionals.AskMode }}; then
+ if {{ $.Conditionals.Not.AskMode }}; then
compadd "$@" $({{ $.DoList }})
fi
fi