Skip to content

Commit fbeddc4

Browse files
committed
Address comments
1 parent ee610ae commit fbeddc4

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

internal/cli/root/atlas/builder.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,7 @@ func Builder(profile *string) *cobra.Command {
124124
writer: w,
125125
}
126126

127-
c, _ := homebrew.NewChecker(fs)
128-
isHb := c.IsHomebrew()
129-
130-
if notifier.shouldCheck() {
127+
if check, isHb := notifier.shouldCheck(); check {
131128
_ = notifier.notifyIfApplicable(isHb)
132129
}
133130
},
@@ -204,16 +201,27 @@ func formattedVersion() string {
204201
runtime.Compiler)
205202
}
206203

207-
func (c *Notifier) shouldCheck() bool {
208-
return !config.SkipUpdateCheck() && cli.IsTerminal(c.writer)
204+
func (n *Notifier) shouldCheck() (shouldCheck, isHb bool) {
205+
shouldCheck = !config.SkipUpdateCheck() && cli.IsTerminal(n.writer)
206+
isHb = false
207+
208+
if !shouldCheck {
209+
return shouldCheck, isHb
210+
}
211+
212+
c, _ := homebrew.NewChecker(n.filesystem)
213+
isHb = c.IsHomebrew()
214+
215+
return shouldCheck, isHb
209216
}
210217

211-
func (c *Notifier) notifyIfApplicable(isHb bool) error {
212-
release, err := c.finder.Find()
218+
func (n *Notifier) notifyIfApplicable(isHb bool) error {
219+
release, err := n.finder.Find()
213220
if err != nil || release == nil {
214221
return err
215222
}
216223

224+
// homebrew is an external dependency we give them 24h to have the cli available there
217225
if isHb && !isAtLeast24HoursPast(release.PublishedAt) {
218226
return nil
219227
}
@@ -231,7 +239,7 @@ A new version of %s is available '%s'!
231239
232240
To disable this alert, run "%s config set skip_update_check true".
233241
`
234-
_, err = fmt.Fprintf(c.writer, newVersionTemplate, config.ToolName, release.Version, upgradeInstructions, config.BinName())
242+
_, err = fmt.Fprintf(n.writer, newVersionTemplate, config.ToolName, release.Version, upgradeInstructions, config.BinName())
235243
return err
236244
}
237245

internal/cli/root/mongocli/builder.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,7 @@ func Builder(profile *string, argsWithoutProg []string) *cobra.Command {
7474
writer: w,
7575
}
7676

77-
c, _ := homebrew.NewChecker(fs)
78-
isHb := c.IsHomebrew()
79-
80-
if notifier.shouldCheck() {
77+
if check, isHb := notifier.shouldCheck(); check {
8178
_ = notifier.notifyIfApplicable(isHb)
8279
}
8380
},
@@ -145,16 +142,27 @@ func formattedVersion() string {
145142
runtime.Compiler)
146143
}
147144

148-
func (c *Notifier) shouldCheck() bool {
149-
return !config.SkipUpdateCheck() && cli.IsTerminal(c.writer)
145+
func (n *Notifier) shouldCheck() (shouldCheck, isHb bool) {
146+
shouldCheck = !config.SkipUpdateCheck() && cli.IsTerminal(n.writer)
147+
isHb = false
148+
149+
if !shouldCheck {
150+
return shouldCheck, isHb
151+
}
152+
153+
c, _ := homebrew.NewChecker(n.filesystem)
154+
isHb = c.IsHomebrew()
155+
156+
return shouldCheck, isHb
150157
}
151158

152-
func (c *Notifier) notifyIfApplicable(isHb bool) error {
153-
release, err := c.finder.Find()
159+
func (n *Notifier) notifyIfApplicable(isHb bool) error {
160+
release, err := n.finder.Find()
154161
if err != nil || release == nil {
155162
return err
156163
}
157164

165+
// homebrew is an external dependency we give them 24h to have the cli available there
158166
if isHb && !isAtLeast24HoursPast(release.PublishedAt) {
159167
return nil
160168
}
@@ -172,7 +180,7 @@ A new version of %s is available '%s'!
172180
173181
To disable this alert, run "%s config set skip_update_check true".
174182
`
175-
_, err = fmt.Fprintf(c.writer, newVersionTemplate, config.ToolName, release.Version, upgradeInstructions, config.BinName())
183+
_, err = fmt.Fprintf(n.writer, newVersionTemplate, config.ToolName, release.Version, upgradeInstructions, config.BinName())
176184
return err
177185
}
178186

0 commit comments

Comments
 (0)