commit 176bc2b46f671fe7149584ef4e600d78a15f63ff
parent 66aec70cf927f7f7bad1f3ab6a2b512e8a9cc46b
Author: Sean Enck <sean@ttypty.com>
Date: Wed, 15 Feb 2023 18:54:51 -0500
move this test to unit tests
Diffstat:
6 files changed, 32 insertions(+), 57 deletions(-)
diff --git a/Makefile b/Makefile
@@ -22,7 +22,6 @@ $(TESTDIR):
cd $@ && go test
check: $(TARGET) $(TESTDIR) $(DOC) $(RUNS)
- sed -n '/\(.\)\{79\}/p' $(DOC) | wc -l | grep -q '^0$$'
$(RUNS):
rm -f $(BUILD)*.kdbx
diff --git a/cmd/doc.sections b/cmd/doc.sections
@@ -1,38 +0,0 @@
-[database]
-While 'lb' uses a kdbx file (version 4), it is opinionated about how to store
-data within the file. This means 'lb' should be the only way a user normally
-interacts with or changes the underlying database. However as the file is a
-normal kdbx file format (e.g. can be opened in tools supporting the format) it
-is possible to use the database in those applications, just take caution when
-changing it outside of 'lb' usage. If a database not normally used by 'lb' is
-to be used by 'lb', try using the various readonly settings to control
-interactions.
-
-[remove]
-The 'rm' command can handle a simplistic glob if it is at the END of the path.
-This allows for bulk-removal of entries at multiple levels. Confirmation will
-still be required for removal (matching entries will be listed)
-
-lb rm path/to/leaf/dir/*
-
-lb rm path/to/*
-
-[clipboard]
-By default clipboard commands are detected via determing the platform and
-utilizing default commands to interact with (copy to/paste to) the clipboard.
-These settings can be overriden via environment variables
-
-[totp]
-By default 'lb' tries to use some reasonable defaults to setup/manage oauth
-token inputs and displaying of code outputs. Many of these settings can be
-changed via environment variables
-
-[rekey]
-The password store can have the key (and file) changed via the 'key'
-subcommand. This will require setting additional environment variables for the
-new key, key mode, key file, and store (as specified as environment variables)
-but with '_NEW' added as a suffix
-
-[environment variables]
-
-The following environment variables can alter how 'lb' works
diff --git a/cmd/main.go b/cmd/main.go
@@ -17,12 +17,8 @@ import (
"github.com/enckse/lockbox/internal/totp"
)
-var (
- //go:embed "vers.txt"
- version string
- //go:embed "doc.sections"
- docSection string
-)
+//go:embed "vers.txt"
+var version string
type (
callbackFunction func([]string) error
@@ -86,16 +82,10 @@ func processInfoCommands(command string, args []string) ([]string, error) {
return nil, errors.New("invalid help option")
}
}
- results, err := cli.Usage()
+ results, err := cli.Usage(isAdvanced)
if err != nil {
return nil, err
}
- if isAdvanced {
- results = append(results, "")
- results = append(results, strings.Split(strings.TrimSpace(docSection), "\n")...)
- results = append(results, "")
- results = append(results, inputs.ListEnvironmentVariables(false)...)
- }
return results, nil
case cli.VersionCommand:
return []string{fmt.Sprintf("version: %s", version)}, nil
diff --git a/internal/cli/core.go b/internal/cli/core.go
@@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"sort"
+ "strings"
"text/template"
"github.com/enckse/lockbox/internal/inputs"
@@ -66,8 +67,13 @@ const (
ReKeyCommand = "rekey"
)
-//go:embed "completions.bash"
-var bashCompletions string
+var (
+ //go:embed "completions.bash"
+ bashCompletions string
+
+ //go:embed "doc.txt"
+ docSection string
+)
type (
// Completions handles the inputs to completions for templating
@@ -195,7 +201,7 @@ func BashCompletions(defaults bool) ([]string, error) {
}
// Usage return usage information
-func Usage() ([]string, error) {
+func Usage(verbose bool) ([]string, error) {
name, err := exeName()
if err != nil {
return nil, err
@@ -224,5 +230,11 @@ func Usage() ([]string, error) {
results = append(results, command(VersionCommand, "", "display version information"))
sort.Strings(results)
usage := []string{fmt.Sprintf("%s usage:", name)}
+ if verbose {
+ results = append(results, "")
+ results = append(results, strings.Split(strings.TrimSpace(docSection), "\n")...)
+ results = append(results, "")
+ results = append(results, inputs.ListEnvironmentVariables(false)...)
+ }
return append(usage, results...), nil
}
diff --git a/internal/cli/core_test.go b/internal/cli/core_test.go
@@ -2,16 +2,28 @@ package cli_test
import (
"os"
+ "strings"
"testing"
"github.com/enckse/lockbox/internal/cli"
)
func TestUsage(t *testing.T) {
- u, _ := cli.Usage()
+ u, _ := cli.Usage(false)
if len(u) != 22 {
t.Errorf("invalid usage, out of date? %d", len(u))
}
+ u, _ = cli.Usage(true)
+ if len(u) != 81 {
+ t.Errorf("invalid verbose usage, out of date? %d", len(u))
+ }
+ for _, usage := range u {
+ for _, l := range strings.Split(usage, "\n") {
+ if len(l) > 79 {
+ t.Errorf("usage line > 79 (%d), line: %s", len(l), l)
+ }
+ }
+ }
}
func TestCompletionsBash(t *testing.T) {
diff --git a/internal/inputs/env.go b/internal/inputs/env.go
@@ -305,7 +305,7 @@ func (o environmentOutput) formatEnvironmentVariable(required bool, name, val, d
if len(value) == 0 {
value = "(unset)"
}
- description := strings.ReplaceAll(desc, "\n", "\n ")
+ description := strings.ReplaceAll(desc, "\n", "\n ")
return fmt.Sprintf("\n%s\n %s\n\n required: %t\n value: %s\n options: %s\n", name, description, required, value, strings.Join(allowed, "|"))
}