Skip to content

Commit fcd4b0e

Browse files
fix(upgrade): add --auto flag to upgrade command
Co-authored-by: JanDeDobbeleer <2492783+JanDeDobbeleer@users.noreply.github.com>
1 parent 293e371 commit fcd4b0e

15 files changed

Lines changed: 20 additions & 17 deletions

src/cli/upgrade.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
var (
2222
force bool
23+
auto bool
2324
)
2425

2526
// upgradeCmd represents the upgrade command
@@ -63,7 +64,8 @@ var upgradeCmd = &cobra.Command{
6364

6465
cache.Init(sh, cache.Persist)
6566

66-
if _, OK := cache.Get[string](cache.Device, upgrade.CACHEKEY); OK && !force {
67+
// Only respect the cache interval when using --auto flag
68+
if _, OK := cache.Get[string](cache.Device, upgrade.CACHEKEY); OK && auto {
6769
log.Debug("upgrade check already performed recently, skipping")
6870
return
6971
}
@@ -76,7 +78,7 @@ var upgradeCmd = &cobra.Command{
7678
defer func() {
7779
fmt.Print(terminal.StopProgress())
7880

79-
// always reset the cache key so we respect the interval no matter what the outcome
81+
// Set the cache key after any upgrade check to prevent redundant checks
8082
cache.Set(cache.Device, upgrade.CACHEKEY, "true", cfg.Upgrade.Interval)
8183

8284
cache.Close()
@@ -144,6 +146,7 @@ func executeUpgrade(cfg *upgrade.Config) int {
144146

145147
func init() {
146148
upgradeCmd.Flags().BoolVarP(&force, "force", "f", false, "force the upgrade even if the version is up to date")
149+
upgradeCmd.Flags().BoolVar(&auto, "auto", false, "respect the cache interval for automatic upgrades")
147150
upgradeCmd.Flags().BoolVar(&debug, "debug", false, "enable/disable debug mode")
148151
RootCmd.AddCommand(upgradeCmd)
149152
}

src/shell/bash_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func TestBashFeatures(t *testing.T) {
1212

1313
want := `// these are the features
1414
_omp_ftcs_marks=1
15-
"$_omp_executable" upgrade
15+
"$_omp_executable" upgrade --auto
1616
"$_omp_executable" notice
1717
_omp_cursor_positioning=1`
1818

@@ -33,7 +33,7 @@ bleopt prompt_ps1_final='$(
3333
--escape=false
3434
)'
3535
_omp_ftcs_marks=1
36-
"$_omp_executable" upgrade
36+
"$_omp_executable" upgrade --auto
3737
"$_omp_executable" notice
3838
bleopt prompt_rps1='$(
3939
"$_omp_executable" print right \

src/shell/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (f Features) Cmd() Code {
1919
case Tooltips:
2020
return "enable_tooltips()"
2121
case Upgrade:
22-
return `os.execute(string.format('"%s" upgrade', omp_executable))`
22+
return `os.execute(string.format('"%s" upgrade --auto', omp_executable))`
2323
case Notice:
2424
return `os.execute(string.format('"%s" notice', omp_executable))`
2525
case PromptMark, PoshGit, Azure, LineError, Jobs, CursorPositioning, Async:

src/shell/cmd_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestCmdFeatures(t *testing.T) {
1414
enable_tooltips()
1515
transient_enabled = true
1616
ftcs_marks_enabled = true
17-
os.execute(string.format('"%s" upgrade', omp_executable))
17+
os.execute(string.format('"%s" upgrade --auto', omp_executable))
1818
os.execute(string.format('"%s" notice', omp_executable))
1919
rprompt_enabled = true`
2020

src/shell/code.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type Code string
1111
const (
1212
unixFTCSMarks Code = "_omp_ftcs_marks=1"
1313
unixCursorPositioning Code = "_omp_cursor_positioning=1"
14-
unixUpgrade Code = `"$_omp_executable" upgrade`
14+
unixUpgrade Code = `"$_omp_executable" upgrade --auto`
1515
unixNotice Code = `"$_omp_executable" notice`
1616
)
1717

src/shell/elvish.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var elvishInit string
1010
func (f Features) Elvish() Code {
1111
switch f {
1212
case Upgrade:
13-
return "$_omp_executable upgrade"
13+
return "$_omp_executable upgrade --auto"
1414
case Notice:
1515
return "$_omp_executable notice"
1616
case PromptMark, RPrompt, PoshGit, Azure, LineError, Jobs, CursorPositioning, Tooltips, Transient, FTCSMarks, Async:

src/shell/elvish_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func TestElvishFeatures(t *testing.T) {
1010
got := allFeatures.Lines(ELVISH).String("// these are the features")
1111

1212
want := `// these are the features
13-
$_omp_executable upgrade
13+
$_omp_executable upgrade --auto
1414
$_omp_executable notice`
1515

1616
assert.Equal(t, want, got)

src/shell/fish_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestFishFeatures(t *testing.T) {
1414
enable_poshtooltips
1515
set --global _omp_transient_prompt 1
1616
set --global _omp_ftcs_marks 1
17-
"$_omp_executable" upgrade
17+
"$_omp_executable" upgrade --auto
1818
"$_omp_executable" notice
1919
set --global _omp_prompt_mark 1`
2020

src/shell/nu.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func (f Features) Nu() Code {
1414
case Transient:
1515
return `$env.TRANSIENT_PROMPT_COMMAND = {|| _omp_get_prompt transient }`
1616
case Upgrade:
17-
return "^$_omp_executable upgrade"
17+
return "^$_omp_executable upgrade --auto"
1818
case Notice:
1919
return "^$_omp_executable notice"
2020
case PromptMark, RPrompt, PoshGit, Azure, LineError, Jobs, Tooltips, FTCSMarks, CursorPositioning, Async:

src/shell/nu_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func TestNuFeatures(t *testing.T) {
1212

1313
want := `// these are the features
1414
$env.TRANSIENT_PROMPT_COMMAND = {|| _omp_get_prompt transient }
15-
^$_omp_executable upgrade
15+
^$_omp_executable upgrade --auto
1616
^$_omp_executable notice`
1717

1818
assert.Equal(t, want, got)

0 commit comments

Comments
 (0)