commit 6f16f94d5721285bd4c41e4669e3ebdb32159809
parent f497e873e169b37e9456f4fcbb6c889212189325
Author: Sean Enck <sean@ttypty.com>
Date: Sat, 7 Dec 2024 11:19:50 -0500
spawn a new config helper
Diffstat:
10 files changed, 29 insertions(+), 26 deletions(-)
diff --git a/README.md b/README.md
@@ -40,8 +40,8 @@ store = "$HOME/.passwords/secrets.kdbx"
password = ["gpg", "--decrypt", "$HOME/.secrets/key.gpg"]
```
-Use `lb help verbose` for additional information about options and
-configuration variables
+Use `lb help verbose` for additional information about functionality and
+`lb help config` for details on configuration variables
### supported systems
diff --git a/internal/app/completions.go b/internal/app/completions.go
@@ -33,6 +33,7 @@ type (
JSONCommand string
HelpCommand string
HelpAdvancedCommand string
+ HelpConfigCommand string
Options []CompletionOption
TOTPSubCommands []CompletionOption
Conditionals struct {
@@ -93,6 +94,7 @@ func GenerateCompletions(completionType, exe string) ([]string, error) {
JSONCommand: JSONCommand,
HelpCommand: HelpCommand,
HelpAdvancedCommand: HelpAdvancedCommand,
+ HelpConfigCommand: HelpConfigCommand,
TOTPCommand: TOTPCommand,
MoveCommand: MoveCommand,
DoList: fmt.Sprintf("%s %s", exe, ListCommand),
diff --git a/internal/app/core.go b/internal/app/core.go
@@ -4,7 +4,6 @@ package app
import (
"bytes"
"embed"
- "errors"
"fmt"
"io"
"os"
@@ -43,6 +42,8 @@ const (
HelpCommand = "help"
// HelpAdvancedCommand shows advanced help
HelpAdvancedCommand = "verbose"
+ // HelpConfigCommand shows configuration information
+ HelpConfigCommand = "config"
// RemoveCommand removes an entry
RemoveCommand = "rm"
// EnvCommand shows environment information used by lockbox
@@ -223,6 +224,7 @@ func Usage(verbose bool, exe string) ([]string, error) {
results = append(results, command(EnvCommand, "", "display environment variable information"))
results = append(results, command(HelpCommand, "", "show this usage information"))
results = append(results, subCommand(HelpCommand, HelpAdvancedCommand, "", "display verbose help information"))
+ results = append(results, subCommand(HelpCommand, HelpConfigCommand, "", "display verbose configuration information"))
results = append(results, command(InsertCommand, "entry", "insert a new entry into the store"))
results = append(results, command(JSONCommand, "filter", "display detailed information"))
results = append(results, command(ListCommand, "", "list entries"))
@@ -263,7 +265,6 @@ func Usage(verbose bool, exe string) ([]string, error) {
return nil, err
}
var buf bytes.Buffer
- var env string
for _, f := range files {
n := f.Name()
if !strings.HasSuffix(n, textFile) {
@@ -274,24 +275,9 @@ func Usage(verbose bool, exe string) ([]string, error) {
if err != nil {
return nil, err
}
- switch header {
- case "[toml]":
- env = s
- default:
- buf.WriteString(s)
- }
- }
- if env == "" {
- return nil, errors.New("no environment header configured")
+ buf.WriteString(s)
}
- buf.WriteString(env)
results = append(results, strings.Split(strings.TrimSpace(buf.String()), "\n")...)
- results = append(results, "")
- toml, err := config.DefaultTOML()
- if err != nil {
- return nil, err
- }
- results = append(results, toml)
}
return append(usage, results...), nil
}
diff --git a/internal/app/core_test.go b/internal/app/core_test.go
@@ -9,7 +9,7 @@ import (
func TestUsage(t *testing.T) {
u, _ := app.Usage(false, "lb")
- if len(u) != 26 {
+ if len(u) != 27 {
t.Errorf("invalid usage, out of date? %d", len(u))
}
u, _ = app.Usage(true, "lb")
diff --git a/internal/app/doc/toml.txt b/internal/app/doc/toml.txt
@@ -3,6 +3,8 @@ environment settings, but these settings are secondary (overriden)
by TOML configuration file(s) if given. The following represents
all available environment and TOML settings as a TOML file with
comments indicating the mapping to the underlying environment
-settings:
+settings.
----
+Arrays defined within the TOML configuration are flattened into
+a string (space delimited), quoting should be done within array
+parameters when needed.
diff --git a/internal/app/info.go b/internal/app/info.go
@@ -44,6 +44,12 @@ func info(command string, args []string) ([]string, error) {
switch args[0] {
case HelpAdvancedCommand:
isAdvanced = true
+ case HelpConfigCommand:
+ data, err := config.DefaultTOML()
+ if err != nil {
+ return nil, err
+ }
+ return []string{data}, nil
default:
return nil, errors.New("invalid help option")
}
diff --git a/internal/app/info_test.go b/internal/app/info_test.go
@@ -42,6 +42,13 @@ func TestHelpInfo(t *testing.T) {
if _, err = app.Info(&buf, "help", []string{"verbose", "A"}); err.Error() != "invalid help command" {
t.Errorf("invalid error: %v", err)
}
+ ok, err = app.Info(&buf, "help", []string{"config"})
+ if !ok || err != nil {
+ t.Errorf("invalid error: %v", err)
+ }
+ if buf.String() == "" || old == buf.String() {
+ t.Error("nothing written")
+ }
}
func TestEnvInfo(t *testing.T) {
diff --git a/internal/app/shell/bash.sh b/internal/app/shell/bash.sh
@@ -30,7 +30,7 @@ _{{ $.Executable }}() {
if [ "$COMP_CWORD" -eq 2 ]; then
case "$chosen" in
"{{ $.HelpCommand }}")
- opts="{{ $.HelpAdvancedCommand }}"
+ opts="{{ $.HelpAdvancedCommand }} {{ $.HelpConfigCommand }}"
;;
"{{ $.InsertCommand }}" | "{{ $.MultiLineCommand }}" | "{{ $.MoveCommand }}" | "{{ $.RemoveCommand }}")
if {{ $.Conditionals.Not.AskMode }}; then
diff --git a/internal/app/shell/fish.sh b/internal/app/shell/fish.sh
@@ -12,7 +12,7 @@ function {{ $.Executable }}-completion
end
{{- 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 }}"
+ complete -c {{ $.Executable }} -n "__fish_seen_subcommand_from {{ $.HelpCommand }}; and test (count (commandline -opc)) -lt 3" -a "{{ $.HelpAdvancedCommand }} {{ $.HelpConfigCommand }}"
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 }})"
diff --git a/internal/app/shell/zsh.sh b/internal/app/shell/zsh.sh
@@ -41,7 +41,7 @@ _{{ $.Executable }}() {
case $chosen in
"{{ $.HelpCommand }}")
if [ "$len" -eq 3 ]; then
- compadd "$@" "{{ $.HelpAdvancedCommand }}"
+ compadd "$@" "{{ $.HelpAdvancedCommand }} {{ $.HelpConfigCommand }}"
fi
;;
"{{ $.InsertCommand }}" | "{{ $.MultiLineCommand }}" | "{{ $.RemoveCommand }}")