commit c4d4d484169ca387469dcba07f24480a6ed88ea3
parent b83c0e54b3678a39a6942d9784e113f3c6b023ed
Author: Sean Enck <sean@ttypty.com>
Date: Sat, 15 Oct 2022 12:08:30 -0400
use the executable name
Diffstat:
3 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/cmd/main.go b/cmd/main.go
@@ -73,7 +73,7 @@ func getInfoDefault(args []string, possibleArg string) (bool, error) {
func processInfoCommands(command string, args []string) ([]string, error) {
switch command {
case cli.HelpCommand:
- return cli.Usage(), nil
+ return cli.Usage()
case cli.VersionCommand:
return []string{fmt.Sprintf("version: %s", strings.TrimSpace(version))}, nil
case cli.EnvCommand, cli.BashCommand:
diff --git a/internal/cli/core.go b/internal/cli/core.go
@@ -5,6 +5,7 @@ import (
"bytes"
_ "embed"
"fmt"
+ "os"
"sort"
"text/template"
@@ -100,6 +101,10 @@ func commandText(args, name, desc string) string {
// BashCompletions handles creating bash completion outputs
func BashCompletions(defaults bool) ([]string, error) {
+ exeName, err := os.Executable()
+ if err != nil {
+ return nil, err
+ }
c := Completions{
InsertCommand: InsertCommand,
RemoveCommand: RemoveCommand,
@@ -111,8 +116,8 @@ func BashCompletions(defaults bool) ([]string, error) {
InsertMultiCommand: InsertMultiCommand,
TOTPCommand: TOTPCommand,
MoveCommand: MoveCommand,
- DoList: fmt.Sprintf("lb %s", ListCommand),
- DoTOTPList: fmt.Sprintf("lb %s %s", TOTPCommand, TOTPListCommand),
+ DoList: fmt.Sprintf("%s %s", exeName, ListCommand),
+ DoTOTPList: fmt.Sprintf("%s %s %s", exeName, TOTPCommand, TOTPListCommand),
}
isReadOnly := false
isClip := true
@@ -152,7 +157,11 @@ func BashCompletions(defaults bool) ([]string, error) {
}
// Usage return usage information
-func Usage() []string {
+func Usage() ([]string, error) {
+ exeName, err := os.Executable()
+ if err != nil {
+ return nil, err
+ }
var results []string
results = append(results, command(BashCommand, "", "generate bash completions"))
results = append(results, subCommand(BashCommand, BashDefaultsCommand, "", "generate default bash completion, not user environment specific"))
@@ -173,6 +182,6 @@ func Usage() []string {
results = append(results, subCommand(TOTPCommand, TOTPShortCommand, "entry", "display the first generated code with no details"))
results = append(results, command(VersionCommand, "", "display version information"))
sort.Strings(results)
- usage := []string{"lb usage:"}
- return append(usage, results...)
+ usage := []string{fmt.Sprintf("%s usage:", exeName)}
+ return append(usage, results...), nil
}
diff --git a/internal/cli/core_test.go b/internal/cli/core_test.go
@@ -8,7 +8,7 @@ import (
)
func TestUsage(t *testing.T) {
- u := cli.Usage()
+ u, _ := cli.Usage()
if len(u) != 19 {
t.Errorf("invalid usage, out of date? %d", len(u))
}