Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/entire/cli/strategy/manual_commit_reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (

// isAccessibleMode returns true if accessibility mode should be enabled.
// This checks the ACCESSIBLE environment variable.
//
//nolint:unused // kept for strategy prompts that cannot use uiform.New directly
func isAccessibleMode() bool {
return os.Getenv("ACCESSIBLE") != ""
}
Expand Down
6 changes: 2 additions & 4 deletions cmd/entire/cli/strategy/manual_commit_rewind.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/entireio/cli/cmd/entire/cli/osroot"
"github.com/entireio/cli/cmd/entire/cli/paths"
"github.com/entireio/cli/cmd/entire/cli/trailers"
"github.com/entireio/cli/cmd/entire/cli/uiform"
"github.com/entireio/cli/cmd/entire/cli/validation"

"charm.land/huh/v2"
Expand Down Expand Up @@ -979,16 +980,13 @@ func PromptOverwriteNewerLogs(errW io.Writer, sessions []SessionRestoreInfo) (bo
fmt.Fprintf(errW, "\nOverwriting will lose the newer local entries.\n\n")

var confirmed bool
form := huh.NewForm(
form := uiform.New(
huh.NewGroup(
huh.NewConfirm().
Title("Overwrite local session logs with checkpoint versions?").
Value(&confirmed),
),
)
if isAccessibleMode() {
form = form.WithAccessible(true)
}

if err := form.Run(); err != nil {
if errors.Is(err, huh.ErrUserAborted) {
Expand Down
64 changes: 64 additions & 0 deletions cmd/entire/cli/uiform/uiform_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package uiform

import (
"os"
"path/filepath"
"strings"
"testing"
)

func TestProductionFormsUseUIFormHelper(t *testing.T) {
t.Parallel()

root := findRepoRoot(t)
cliDir := filepath.Join(root, "cmd", "entire", "cli")
allowed := filepath.ToSlash(filepath.Join("cmd", "entire", "cli", "uiform", "uiform.go"))

err := filepath.WalkDir(cliDir, func(path string, entry os.DirEntry, walkErr error) error {
if walkErr != nil {
return walkErr
}
if entry.IsDir() || !strings.HasSuffix(path, ".go") || strings.HasSuffix(path, "_test.go") {
return nil
}

data, err := os.ReadFile(path)
if err != nil {
return err
}
if !strings.Contains(string(data), "huh.NewForm(") {
return nil
}

rel, err := filepath.Rel(root, path)
if err != nil {
return err
}
if filepath.ToSlash(rel) != allowed {
t.Errorf("%s uses huh.NewForm directly; use uiform.New instead", rel)
}
return nil
})
if err != nil {
t.Fatalf("walk CLI files: %v", err)
}
}

func findRepoRoot(t *testing.T) string {
t.Helper()

dir, err := os.Getwd()
if err != nil {
t.Fatalf("get working directory: %v", err)
}
for {
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil {
return dir
}
parent := filepath.Dir(dir)
if parent == dir {
t.Fatalf("could not find repo root from %s", dir)
}
dir = parent
}
}
6 changes: 2 additions & 4 deletions cmd/entire/cli/versioncheck/autoupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/entireio/cli/cmd/entire/cli/interactive"
"github.com/entireio/cli/cmd/entire/cli/logging"
"github.com/entireio/cli/cmd/entire/cli/uiform"
)

// envKillSwitch disables the interactive update prompt regardless of TTY.
Expand Down Expand Up @@ -114,10 +115,7 @@ func realChooseUpdate(ctx context.Context, currentVersion, latestVersion, cmdStr
huh.NewOption("Skip until next version", autoUpdateActionSkipUntilNextVersion),
).
Value(&action)
form := huh.NewForm(huh.NewGroup(sel)).WithTheme(huh.ThemeFunc(huh.ThemeDracula))
if os.Getenv("ACCESSIBLE") != "" {
form = form.WithAccessible(true)
}
form := uiform.New(huh.NewGroup(sel))
if err := form.RunWithContext(ctx); err != nil {
if errors.Is(err, huh.ErrUserAborted) || errors.Is(err, huh.ErrTimeout) {
return autoUpdateActionSkip, nil
Expand Down