Skip to content

Commit f926149

Browse files
authored
fix: wrap post-install message text (#46)
closes #19
1 parent 260c2b7 commit f926149

File tree

6 files changed

+77
-47
lines changed

6 files changed

+77
-47
lines changed

cmd/dbc/install.go

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ type progressiveInstallModel struct {
130130

131131
state installState
132132
spinner spinner.Model
133+
134+
width, height int
133135
}
134136

135137
func (m progressiveInstallModel) Init() tea.Cmd {
@@ -142,6 +144,31 @@ func (m progressiveInstallModel) Init() tea.Cmd {
142144
})
143145
}
144146

147+
func (m progressiveInstallModel) FinalOutput() string {
148+
if m.conflictingInfo.ID != "" && m.conflictingInfo.Version != nil {
149+
if m.conflictingInfo.Version.Equal(m.DriverPackage.Version) {
150+
return fmt.Sprintf("\nDriver %s %s already installed at %s\n",
151+
m.conflictingInfo.ID, m.conflictingInfo.Version, filepath.SplitList(m.cfg.Location)[0])
152+
}
153+
}
154+
155+
var b strings.Builder
156+
if m.state == stDone {
157+
if m.conflictingInfo.ID != "" && m.conflictingInfo.Version != nil {
158+
b.WriteString(fmt.Sprintf("\nRemoved conflicting driver: %s (version: %s)",
159+
m.conflictingInfo.ID, m.conflictingInfo.Version))
160+
}
161+
162+
b.WriteString(fmt.Sprintf("\nInstalled %s %s to %s\n",
163+
m.Driver, m.DriverPackage.Version, filepath.SplitList(m.cfg.Location)[0]))
164+
165+
if m.postInstallMessage != "" {
166+
b.WriteString("\n" + postMsgStyle.Render(m.postInstallMessage) + "\n")
167+
}
168+
}
169+
return b.String()
170+
}
171+
145172
func (m progressiveInstallModel) searchForDriver(d dbc.Driver) tea.Cmd {
146173
return func() tea.Msg {
147174
pkg, err := d.GetPackage(m.VersionInput, config.PlatformTuple())
@@ -190,6 +217,8 @@ func (m progressiveInstallModel) startInstalling(downloaded *os.File) (tea.Model
190217

191218
func (m progressiveInstallModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
192219
switch msg := msg.(type) {
220+
case tea.WindowSizeMsg:
221+
m.width, m.height = msg.Width, msg.Height
193222
case spinner.TickMsg:
194223
var cmd tea.Cmd
195224
m.spinner, cmd = m.spinner.Update(msg)
@@ -248,8 +277,7 @@ func (m progressiveInstallModel) View() string {
248277

249278
if m.conflictingInfo.ID != "" && m.conflictingInfo.Version != nil {
250279
if m.conflictingInfo.Version.Equal(m.DriverPackage.Version) {
251-
return fmt.Sprintf("\nDriver %s %s already installed at %s\n",
252-
m.conflictingInfo.ID, m.conflictingInfo.Version, filepath.SplitList(m.cfg.Location)[0])
280+
return ""
253281
}
254282
}
255283

@@ -263,18 +291,5 @@ func (m progressiveInstallModel) View() string {
263291
b.WriteByte('\n')
264292
}
265293

266-
if m.state == stDone {
267-
if m.conflictingInfo.ID != "" && m.conflictingInfo.Version != nil {
268-
b.WriteString(fmt.Sprintf("\nRemoved conflicting driver: %s (version: %s)",
269-
m.conflictingInfo.ID, m.conflictingInfo.Version))
270-
}
271-
272-
b.WriteString(fmt.Sprintf("\nInstalled %s %s to %s\n",
273-
m.Driver, m.DriverPackage.Version, filepath.SplitList(m.cfg.Location)[0]))
274-
275-
if m.postInstallMessage != "" {
276-
b.WriteString("\n" + postMsgStyle.Render(m.postInstallMessage) + "\n")
277-
}
278-
}
279294
return b.String()
280295
}

cmd/dbc/install_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ func (suite *SubcommandTestSuite) TestInstall() {
1616
GetModelCustom(baseModel{getDriverList: getTestDriverList, downloadPkg: downloadTestPkg})
1717
out := suite.runCmd(m)
1818

19-
suite.validateOutput("\r[✓] searching\r\n[✓] downloading\r\n[✓] installing\r\n[✓] verifying signature\r\n"+
20-
"\r\nInstalled test-driver-1 1.1.0 to "+suite.tempdir+"\r\n", out)
19+
suite.validateOutput("\r[✓] searching\r\n[✓] downloading\r\n[✓] installing\r\n[✓] verifying signature\r\n",
20+
"\nInstalled test-driver-1 1.1.0 to "+suite.tempdir+"\n", out)
2121
if runtime.GOOS != "windows" {
2222
suite.FileExists(filepath.Join(suite.tempdir, "test-driver-1.toml"))
2323
}
@@ -26,7 +26,7 @@ func (suite *SubcommandTestSuite) TestInstall() {
2626
func (suite *SubcommandTestSuite) TestInstallDriverNotFound() {
2727
m := InstallCmd{Driver: "foo", Level: config.ConfigEnv}.
2828
GetModelCustom(baseModel{getDriverList: getTestDriverList, downloadPkg: downloadTestPkg})
29-
suite.validateOutput("Error: could not find driver: driver `foo` not found in driver index\r\n\r ", suite.runCmdErr(m))
29+
suite.validateOutput("Error: could not find driver: driver `foo` not found in driver index\r\n\r ", "", suite.runCmdErr(m))
3030
}
3131

3232
func (suite *SubcommandTestSuite) TestInstallUserFake() {
@@ -85,8 +85,8 @@ func (suite *SubcommandTestSuite) TestInstallVenv() {
8585

8686
m := InstallCmd{Driver: "test-driver-1"}.
8787
GetModelCustom(baseModel{getDriverList: getTestDriverList, downloadPkg: downloadTestPkg})
88-
suite.validateOutput("\r[✓] searching\r\n[✓] downloading\r\n[✓] installing\r\n[✓] verifying signature\r\n"+
89-
"\r\nInstalled test-driver-1 1.1.0 to "+filepath.Join(suite.tempdir, "etc", "adbc", "drivers")+"\r\n", suite.runCmd(m))
88+
suite.validateOutput("\r[✓] searching\r\n[✓] downloading\r\n[✓] installing\r\n[✓] verifying signature\r\n",
89+
"\nInstalled test-driver-1 1.1.0 to "+filepath.Join(suite.tempdir, "etc", "adbc", "drivers")+"\n", suite.runCmd(m))
9090
}
9191

9292
func (suite *SubcommandTestSuite) TestInstallCondaPrefix() {
@@ -96,8 +96,8 @@ func (suite *SubcommandTestSuite) TestInstallCondaPrefix() {
9696

9797
m := InstallCmd{Driver: "test-driver-1"}.
9898
GetModelCustom(baseModel{getDriverList: getTestDriverList, downloadPkg: downloadTestPkg})
99-
suite.validateOutput("\r[✓] searching\r\n[✓] downloading\r\n[✓] installing\r\n[✓] verifying signature\r\n"+
100-
"\r\nInstalled test-driver-1 1.1.0 to "+filepath.Join(suite.tempdir, "etc", "adbc", "drivers")+"\r\n", suite.runCmd(m))
99+
suite.validateOutput("\r[✓] searching\r\n[✓] downloading\r\n[✓] installing\r\n[✓] verifying signature\r\n",
100+
"\nInstalled test-driver-1 1.1.0 to "+filepath.Join(suite.tempdir, "etc", "adbc", "drivers")+"\n", suite.runCmd(m))
101101
}
102102

103103
func (suite *SubcommandTestSuite) TestInstallUserFakeExplicitLevelOverrides() {
@@ -120,9 +120,9 @@ func (suite *SubcommandTestSuite) TestInstallUserFakeExplicitLevelOverrides() {
120120
func (suite *SubcommandTestSuite) TestInstallManifestOnlyDriver() {
121121
m := InstallCmd{Driver: "test-driver-manifest-only"}.
122122
GetModelCustom(baseModel{getDriverList: getTestDriverList, downloadPkg: downloadTestPkg})
123-
suite.validateOutput("\r[✓] searching\r\n[✓] downloading\r\n[✓] installing\r\n[✓] verifying signature\r\n"+
124-
"\r\nInstalled test-driver-manifest-only 1.0.0 to "+suite.tempdir+"\r\n"+
125-
"\r\nMust have libtest_driver installed to load this driver\r\n", suite.runCmd(m))
123+
suite.validateOutput("\r[✓] searching\r\n[✓] downloading\r\n[✓] installing\r\n[✓] verifying signature\r\n",
124+
"\nInstalled test-driver-manifest-only 1.0.0 to "+suite.tempdir+"\n"+
125+
"\nMust have libtest_driver installed to load this driver\n", suite.runCmd(m))
126126
if runtime.GOOS != "windows" {
127127
suite.FileExists(filepath.Join(suite.tempdir, "test-driver-manifest-only.toml"))
128128
}
@@ -149,6 +149,6 @@ func (suite *SubcommandTestSuite) TestInstallDriverNoSignature() {
149149

150150
m = InstallCmd{Driver: "test-driver-no-sig", NoVerify: true}.
151151
GetModelCustom(baseModel{getDriverList: getTestDriverList, downloadPkg: downloadTestPkg})
152-
suite.validateOutput("\r[✓] searching\r\n[✓] downloading\r\n[✓] installing\r\n[✓] verifying signature\r\n"+
153-
"\r\nInstalled test-driver-no-sig 1.0.0 to "+suite.tempdir+"\r\n", suite.runCmd(m))
152+
suite.validateOutput("\r[✓] searching\r\n[✓] downloading\r\n[✓] installing\r\n[✓] verifying signature\r\n",
153+
"\nInstalled test-driver-no-sig 1.0.0 to "+suite.tempdir+"\n", suite.runCmd(m))
154154
}

cmd/dbc/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ func errCmd(format string, a ...any) tea.Cmd {
3434
}
3535
}
3636

37+
type HasFinalOutput interface {
38+
FinalOutput() string
39+
}
40+
3741
type HasStatus interface {
3842
Status() int
3943
}
@@ -83,6 +87,8 @@ func (m baseModel) Status() int {
8387
return m.status
8488
}
8589

90+
func (m baseModel) FinalOutput() string { return "" }
91+
8692
func (m baseModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
8793
switch msg := msg.(type) {
8894
case tea.KeyMsg:
@@ -134,6 +140,10 @@ func main() {
134140
os.Exit(1)
135141
}
136142

143+
if fo, ok := m.(HasFinalOutput); ok {
144+
fmt.Print(fo.FinalOutput())
145+
}
146+
137147
if h, ok := m.(HasStatus); ok {
138148
os.Exit(h.Status())
139149
}

cmd/dbc/search_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func (suite *SubcommandTestSuite) TestSearchCmd() {
1515
suite.validateOutput("• test-driver-1 - This is a test driver\r\n"+
1616
"• test-driver-2 - This is another test driver\r\n"+
1717
"• test-driver-manifest-only - This is manifest-only driver\r\n"+
18-
"• test-driver-no-sig - Driver manifest missing Files.signature entry\r\n\r ", suite.runCmd(m))
18+
"• test-driver-no-sig - Driver manifest missing Files.signature entry\r\n\r ", "", suite.runCmd(m))
1919
}
2020

2121
func (suite *SubcommandTestSuite) TestSearchCmdWithInstalled() {
@@ -28,7 +28,7 @@ func (suite *SubcommandTestSuite) TestSearchCmdWithInstalled() {
2828
downloadPkg: downloadTestPkg})
2929
suite.validateOutput("• test-driver-1 - This is a test driver [installed: env=>1.1.0]\r\n"+
3030
"• test-driver-2 - This is another test driver\r\n• test-driver-manifest-only - This is manifest-only driver\r\n"+
31-
"• test-driver-no-sig - Driver manifest missing Files.signature entry\r\n\r ", suite.runCmd(m))
31+
"• test-driver-no-sig - Driver manifest missing Files.signature entry\r\n\r ", "", suite.runCmd(m))
3232
}
3333

3434
func (suite *SubcommandTestSuite) TestSearchCmdVerbose() {
@@ -46,7 +46,7 @@ func (suite *SubcommandTestSuite) TestSearchCmdVerbose() {
4646
"Available Versions:\r\n ╰── 1.0.0\r\n"+
4747
"• test-driver-no-sig\r\n Title: Test Driver No Signature\r\n "+
4848
"Description: Driver manifest missing Files.signature entry\r\n License: Apache-2.0\r\n "+
49-
"Available Versions:\r\n ╰── 1.0.0\r\n\r ", suite.runCmd(m))
49+
"Available Versions:\r\n ╰── 1.0.0\r\n\r ", "", suite.runCmd(m))
5050
}
5151

5252
func (suite *SubcommandTestSuite) TestSearchCmdVerboseWithInstalled() {
@@ -75,5 +75,5 @@ func (suite *SubcommandTestSuite) TestSearchCmdVerboseWithInstalled() {
7575
" Description: Driver manifest missing Files.signature entry\r\n"+
7676
" License: Apache-2.0\r\n"+
7777
" Available Versions:\r\n"+
78-
" ╰── 1.0.0\r\n\r ", suite.runCmd(m))
78+
" ╰── 1.0.0\r\n\r ", "", suite.runCmd(m))
7979
}

cmd/dbc/sync_test.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,21 @@ func (suite *SubcommandTestSuite) runCmd(m tea.Model) string {
101101
m, err = p.Run()
102102
suite.Require().NoError(err)
103103
suite.Equal(0, m.(HasStatus).Status(), "The command exited with a non-zero status.")
104-
return out.String()
104+
105+
var extra string
106+
if fo, ok := m.(HasFinalOutput); ok {
107+
extra = fo.FinalOutput()
108+
}
109+
return out.String() + extra
105110
}
106111

107-
func (suite *SubcommandTestSuite) validateOutput(expected, actual string) {
112+
func (suite *SubcommandTestSuite) validateOutput(expected, extra, actual string) {
108113
const (
109114
terminalPrefix = "\x1b[?25l\x1b[?2004h"
110115
terminalSuffix = "\r\x1b[2K\r\x1b[?2004l\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l"
111116
)
112117

113-
suite.Equal(terminalPrefix+expected+terminalSuffix, actual)
118+
suite.Equal(terminalPrefix+expected+terminalSuffix+extra, actual)
114119
}
115120

116121
func (suite *SubcommandTestSuite) TestSync() {
@@ -124,14 +129,14 @@ func (suite *SubcommandTestSuite) TestSync() {
124129
Path: filepath.Join(suite.tempdir, "dbc.toml"),
125130
}.GetModelCustom(
126131
baseModel{getDriverList: getTestDriverList, downloadPkg: downloadTestPkg})
127-
suite.validateOutput("✓ test-driver-1-1.1.0\r\n\rDone!\r\n", suite.runCmd(m))
132+
suite.validateOutput("✓ test-driver-1-1.1.0\r\n\rDone!\r\n", "", suite.runCmd(m))
128133
suite.FileExists(filepath.Join(suite.tempdir, "test-driver-1.toml"))
129134

130135
m = SyncCmd{
131136
Path: filepath.Join(suite.tempdir, "dbc.toml"),
132137
}.GetModelCustom(
133138
baseModel{getDriverList: getTestDriverList, downloadPkg: downloadTestPkg})
134-
suite.validateOutput("✓ test-driver-1-1.1.0 already installed\r\n\rDone!\r\n", suite.runCmd(m))
139+
suite.validateOutput("✓ test-driver-1-1.1.0 already installed\r\n\rDone!\r\n", "", suite.runCmd(m))
135140
}
136141

137142
func (suite *SubcommandTestSuite) TestSyncVirtualEnv() {
@@ -150,14 +155,14 @@ func (suite *SubcommandTestSuite) TestSyncVirtualEnv() {
150155
Path: filepath.Join(suite.tempdir, "dbc.toml"),
151156
}.GetModelCustom(
152157
baseModel{getDriverList: getTestDriverList, downloadPkg: downloadTestPkg})
153-
suite.validateOutput("✓ test-driver-1-1.1.0\r\n\rDone!\r\n", suite.runCmd(m))
158+
suite.validateOutput("✓ test-driver-1-1.1.0\r\n\rDone!\r\n", "", suite.runCmd(m))
154159
suite.FileExists(filepath.Join(suite.tempdir, "etc", "adbc", "drivers", "test-driver-1.toml"))
155160

156161
m = SyncCmd{
157162
Path: filepath.Join(suite.tempdir, "dbc.toml"),
158163
}.GetModelCustom(
159164
baseModel{getDriverList: getTestDriverList, downloadPkg: downloadTestPkg})
160-
suite.validateOutput("✓ test-driver-1-1.1.0 already installed\r\n\rDone!\r\n", suite.runCmd(m))
165+
suite.validateOutput("✓ test-driver-1-1.1.0 already installed\r\n\rDone!\r\n", "", suite.runCmd(m))
161166
}
162167

163168
func (suite *SubcommandTestSuite) TestSyncCondaPrefix() {
@@ -176,14 +181,14 @@ func (suite *SubcommandTestSuite) TestSyncCondaPrefix() {
176181
Path: filepath.Join(suite.tempdir, "dbc.toml"),
177182
}.GetModelCustom(
178183
baseModel{getDriverList: getTestDriverList, downloadPkg: downloadTestPkg})
179-
suite.validateOutput("✓ test-driver-1-1.1.0\r\n\rDone!\r\n", suite.runCmd(m))
184+
suite.validateOutput("✓ test-driver-1-1.1.0\r\n\rDone!\r\n", "", suite.runCmd(m))
180185
suite.FileExists(filepath.Join(suite.tempdir, "etc", "adbc", "drivers", "test-driver-1.toml"))
181186

182187
m = SyncCmd{
183188
Path: filepath.Join(suite.tempdir, "dbc.toml"),
184189
}.GetModelCustom(
185190
baseModel{getDriverList: getTestDriverList, downloadPkg: downloadTestPkg})
186-
suite.validateOutput("✓ test-driver-1-1.1.0 already installed\r\n\rDone!\r\n", suite.runCmd(m))
191+
suite.validateOutput("✓ test-driver-1-1.1.0 already installed\r\n\rDone!\r\n", "", suite.runCmd(m))
187192
}
188193

189194
func TestSubcommands(t *testing.T) {

cmd/dbc/uninstall_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (suite *SubcommandTestSuite) TestUninstallNotFound() {
1919

2020
m := UninstallCmd{Driver: "notfound"}.GetModel()
2121
suite.validateOutput("Error: failed to find driver `notfound` in order to uninstall it: error opening manifest "+
22-
filepath.Join(suite.tempdir, "notfound.toml")+": open "+filepath.Join(suite.tempdir, "notfound.toml")+": no such file or directory\r\n\r ", suite.runCmdErr(m))
22+
filepath.Join(suite.tempdir, "notfound.toml")+": open "+filepath.Join(suite.tempdir, "notfound.toml")+": no such file or directory\r\n\r ", "", suite.runCmdErr(m))
2323
}
2424

2525
func (suite *SubcommandTestSuite) TestUninstallManifestOnly() {
@@ -37,7 +37,7 @@ func (suite *SubcommandTestSuite) TestUninstallManifestOnly() {
3737
os.WriteFile(path.Join(suite.tempdir, "found.toml"), []byte(contents), 0644)
3838

3939
m := UninstallCmd{Driver: "found", Level: config.ConfigEnv}.GetModel()
40-
suite.validateOutput("Driver `found` uninstalled successfully!\r\n\r\n\r ", suite.runCmd(m))
40+
suite.validateOutput("Driver `found` uninstalled successfully!\r\n\r\n\r ", "", suite.runCmd(m))
4141
}
4242

4343
func (suite *SubcommandTestSuite) TestUninstallDriverAndManifest() {
@@ -58,7 +58,7 @@ func (suite *SubcommandTestSuite) TestUninstallDriverAndManifest() {
5858
os.WriteFile(path.Join(pkgdir, "some.dll"), []byte("anything"), 0o644)
5959

6060
m := UninstallCmd{Driver: "found", Level: config.ConfigEnv}.GetModel()
61-
suite.validateOutput("Driver `found` uninstalled successfully!\r\n\r\n\r ", suite.runCmd(m))
61+
suite.validateOutput("Driver `found` uninstalled successfully!\r\n\r\n\r ", "", suite.runCmd(m))
6262
}
6363

6464
// Test what happens when a user installs a driver in multiple locations
@@ -129,9 +129,9 @@ func (suite *SubcommandTestSuite) TestUninstallMultipleLocationsNonDefault() {
129129
func (suite *SubcommandTestSuite) TestUninstallManifestOnlyDriver() {
130130
m := InstallCmd{Driver: "test-driver-manifest-only"}.
131131
GetModelCustom(baseModel{getDriverList: getTestDriverList, downloadPkg: downloadTestPkg})
132-
suite.validateOutput("\r[✓] searching\r\n[✓] downloading\r\n[✓] installing\r\n[✓] verifying signature\r\n"+
133-
"\r\nInstalled test-driver-manifest-only 1.0.0 to "+suite.tempdir+"\r\n"+
134-
"\r\nMust have libtest_driver installed to load this driver\r\n", suite.runCmd(m))
132+
suite.validateOutput("\r[✓] searching\r\n[✓] downloading\r\n[✓] installing\r\n[✓] verifying signature\r\n",
133+
"\nInstalled test-driver-manifest-only 1.0.0 to "+suite.tempdir+"\n"+
134+
"\nMust have libtest_driver installed to load this driver\n", suite.runCmd(m))
135135
if runtime.GOOS != "windows" {
136136
suite.FileExists(filepath.Join(suite.tempdir, "test-driver-manifest-only.toml"))
137137
}
@@ -147,7 +147,7 @@ func (suite *SubcommandTestSuite) TestUninstallManifestOnlyDriver() {
147147
// Now uninstall and verify we clean up
148148
m = UninstallCmd{Driver: "test-driver-manifest-only"}.
149149
GetModelCustom(baseModel{getDriverList: getTestDriverList, downloadPkg: downloadTestPkg})
150-
suite.validateOutput("Driver `test-driver-manifest-only` uninstalled successfully!\r\n\r\n\r ", suite.runCmd(m))
150+
suite.validateOutput("Driver `test-driver-manifest-only` uninstalled successfully!\r\n\r\n\r ", "", suite.runCmd(m))
151151
if runtime.GOOS != "windows" {
152152
suite.NoFileExists(filepath.Join(suite.tempdir, "test-driver-manifest-only.toml"))
153153
}

0 commit comments

Comments
 (0)