Skip to content

Commit

Permalink
import: fix paddings and import-all workflow (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonehusin authored May 14, 2024
1 parent cb69282 commit dc7d9c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 8 additions & 2 deletions cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,10 @@ func importUsers(ctx context.Context, provider pager.Pager, fh *firehydrant.Clie
idPad := console.PadStrings(unmatched, func(u store.ExtUser) int { return len(u.ID) })
emailPad := console.PadStrings(unmatched, func(u store.ExtUser) int { return len(u.Email) })

importOpts := []store.ExtUser{{ID: "[+] IMPORT ALL"}, {ID: "[<] SKIP ALL"}}
importOpts := []store.ExtUser{
{ID: "[+] IMPORT ALL"},
{ID: "[<] SKIP ALL "}, // Extra spaces for padding alignment of icons
}
importOpts = append(importOpts, unmatched...)
selected, toImport, err := console.MultiSelectf(importOpts, func(u store.ExtUser) string {
return fmt.Sprintf("%*s %-*s %s", idPad, u.ID, emailPad, u.Email, u.Name)
Expand Down Expand Up @@ -326,7 +329,10 @@ func importUsers(ctx context.Context, provider pager.Pager, fh *firehydrant.Clie

namePad := console.PadStrings(fhUsers, func(u store.FhUser) int { return len(u.Name) })

matchOpts := []store.FhUser{{Name: "[+] CREATE THE REST OF USERS AS NEW"}, {Name: "[+] CREATE USER AS NEW"}}
matchOpts := []store.FhUser{
{Name: "[+] CREATE THE REST OF USERS AS NEW"},
{Name: "[+] CREATE USER AS NEW "}, // Extra spaces for padding alignment of icons
}
matchOpts = append(matchOpts, fhUsers...)
for i, u := range toImport {
selected, fhUser, err := console.Selectf(matchOpts, func(u store.FhUser) string {
Expand Down
11 changes: 9 additions & 2 deletions console/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package console
import (
"fmt"
"slices"
"strings"

"github.com/charmbracelet/huh"
)
Expand Down Expand Up @@ -52,8 +53,14 @@ func MultiSelectf[T any](options []T, toString func(T) string, title string, arg
continue
}
Warnf("You have selected: \n")
for _, i := range values {
Warnf(" %s\n", opts[i].Key)
if len(values) == 1 {
// Don't perform padding based on list's max when it's only one value,
// as it would look oddly spaced out.
Warnf(" %s\n", strings.TrimSpace(opts[values[0]].Key))
} else {
for _, i := range values {
Warnf(" %s\n", opts[i].Key)
}
}

response, _, err := Selectf([]string{"Yes", "No"}, func(s string) string { return s }, "Confirm selection?")
Expand Down

0 comments on commit dc7d9c9

Please sign in to comment.