diff --git a/internal/app/app.go b/internal/app/app.go index 82003143..4c81a9b2 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -416,28 +416,6 @@ func (a *application) confirm(cmd *cobra.Command, description string) error { return terminal.Confirm(cmd.Context(), description, a.options.yes, a.deps.Streams, a.policy(s), a.deps.Prompter) } -// confirmTyped asks the user to type answer before an irreversible action unless --yes was supplied. -func (a *application) confirmTyped(cmd *cobra.Command, description, answer string) error { - if a.options.yes { - return nil - } - s, err := a.deps.Settings.Load() - if err != nil { - return err - } - if !a.policy(s).CanPrompt(a.deps.Streams) { - return clierr.Wrap(clierr.Usage, errors.New("confirmation required: supply --yes")) - } - typed, err := a.deps.Prompter.Input(cmd.Context(), description+" Type "+answer+" to confirm:") - if err != nil { - return err - } - if !strings.EqualFold(strings.TrimSpace(typed), answer) { - return clierr.Wrap(clierr.Canceled, errors.New("operation canceled")) - } - return nil -} - // require prompts for a missing required value under the prompt policy. func (a *application) require(cmd *cobra.Command, value *string, flag string) (bool, error) { s, err := a.deps.Settings.Load() diff --git a/internal/app/doctor.go b/internal/app/doctor.go index d289cf65..2183a60a 100644 --- a/internal/app/doctor.go +++ b/internal/app/doctor.go @@ -148,7 +148,7 @@ func (a *application) instanceCheck(ctx context.Context, t target) doctorCheck { if err != nil { return doctorCheck{"Instance", checkFailed, where + ": " + Explain(ctx, a.deps, err).Error(), "check --host, the instance URL and your network"} } - return doctorCheck{"Instance", checkPassed, fmt.Sprintf("%s · Gitea %s · %s", where, version, time.Since(start).Round(time.Millisecond)), ""} + return doctorCheck{"Instance", checkPassed, fmt.Sprintf("%s · Gitea %s · %dms", where, version, max(time.Since(start).Milliseconds(), 1)), ""} } // accountCheck reports whether the account authenticates, and the scopes of its token. diff --git a/internal/app/helpers_test.go b/internal/app/helpers_test.go index d026bdd5..4b104e65 100644 --- a/internal/app/helpers_test.go +++ b/internal/app/helpers_test.go @@ -299,3 +299,12 @@ var ansiSequence = regexp.MustCompile("\x1b\\[[0-9;]*m") func withoutANSI(s string) string { return ansiSequence.ReplaceAllString(s, "") } + +// rawMarkdown keeps Markdown bodies unrendered so terminal views can be compared byte for byte. +func rawMarkdown(t *testing.T, deps Dependencies) { + t.Helper() + require.NoError(t, deps.Settings.Update(settings.TargetPreferences, func(s *settings.Snapshot) error { + s.Preferences.Markdown = "raw" + return nil + })) +} diff --git a/internal/app/releases_test.go b/internal/app/releases_test.go index dc4fe07b..02c6b6a9 100644 --- a/internal/app/releases_test.go +++ b/internal/app/releases_test.go @@ -36,7 +36,8 @@ func TestReleaseViewShowsTheLatestReleaseWithNotesAndAssets(t *testing.T) { })) defer server.Close() deps, out, _ := repoTTYDeps(t, server.URL) - deps.Getenv = serverEnv(server.URL, map[string]string{"TERM": "dumb", "TEA_MARKDOWN": "raw"}) + deps.Getenv = serverEnv(server.URL, map[string]string{"TERM": "dumb"}) + rawMarkdown(t, deps) require.NoError(t, Execute(context.Background(), deps, []string{"release", "view", "-R", "alice/project"})) require.Equal(t, `First release v0.1.0 Latest • alice released this about 2 hours ago · target main diff --git a/internal/app/repos_test.go b/internal/app/repos_test.go index 17c6cff8..6805d8d5 100644 --- a/internal/app/repos_test.go +++ b/internal/app/repos_test.go @@ -86,7 +86,8 @@ func TestRepoViewShowsStateAndReadme(t *testing.T) { })) defer server.Close() deps, out, _ := repoTTYDeps(t, server.URL) - deps.Getenv = serverEnv(server.URL, map[string]string{"TERM": "dumb", "TEA_MARKDOWN": "raw"}) + deps.Getenv = serverEnv(server.URL, map[string]string{"TERM": "dumb"}) + rawMarkdown(t, deps) require.NoError(t, Execute(context.Background(), deps, []string{"repo", "view", "bob/project", "--branch", "develop"})) require.Equal(t, `bob/project public • fork • archived (read-only) • ★ 1 · 0 forks · 2 open issues · 1 open pull request · updated about 1 hour ago @@ -150,7 +151,8 @@ func TestRepoViewOfAnEmptyRepositorySkipsTheReadme(t *testing.T) { })) defer server.Close() deps, out, _ := repoTTYDeps(t, server.URL) - deps.Getenv = serverEnv(server.URL, map[string]string{"TERM": "dumb", "TEA_MARKDOWN": "raw"}) + deps.Getenv = serverEnv(server.URL, map[string]string{"TERM": "dumb"}) + rawMarkdown(t, deps) require.NoError(t, Execute(context.Background(), deps, []string{"repo", "view", "alice/empty"})) require.Contains(t, out.String(), "private • empty • ★ 0") require.Contains(t, out.String(), "_This repository is empty._") diff --git a/internal/app/wiki_test.go b/internal/app/wiki_test.go index 9a487409..496532db 100644 --- a/internal/app/wiki_test.go +++ b/internal/app/wiki_test.go @@ -60,7 +60,8 @@ func TestWikiViewAndCreate(t *testing.T) { })) defer server.Close() deps, out, diagnostics := repoTTYDeps(t, server.URL) - deps.Getenv = serverEnv(server.URL, map[string]string{"TERM": "dumb", "TEA_MARKDOWN": "raw"}) + deps.Getenv = serverEnv(server.URL, map[string]string{"TERM": "dumb"}) + rawMarkdown(t, deps) require.NoError(t, Execute(context.Background(), deps, []string{"wiki", "view", "Page Two", "-R", "alice/x"})) require.Equal(t, "Page Two\nalice · updated about 1 hour ago · 3 revisions\n\nbody\n\nView this wiki page on Gitea: https://gitea.test/alice/x/wiki/Page-Two\n", out.String()) out.Reset()