Skip to content

Commit a7f7e07

Browse files
authored
[ux] Add FNotice (#1139)
## Summary 1. add `FNotice` and reuse it ## How was it tested? 1. Install an old version of devbox 2. Run `devbox` to trigger version checking 3. See the notice message
1 parent d39e72b commit a7f7e07

File tree

7 files changed

+18
-18
lines changed

7 files changed

+18
-18
lines changed

go.mod

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ require (
77
github.com/AlecAivazis/survey/v2 v2.3.6
88
github.com/MakeNowJust/heredoc/v2 v2.0.1
99
github.com/MicahParks/keyfunc/v2 v2.1.0
10-
github.com/a8m/envsubst v1.4.2
1110
github.com/alessio/shellescape v1.4.1
1211
github.com/bmatcuk/doublestar/v4 v4.6.0
1312
github.com/briandowns/spinner v1.23.0
@@ -33,16 +32,13 @@ require (
3332
github.com/spf13/cobra v1.6.1
3433
github.com/spf13/pflag v1.0.5
3534
github.com/stretchr/testify v1.8.2
35+
github.com/zealic/go2node v0.1.0
3636
golang.org/x/exp v0.0.0-20230321023759-10a507213a29
3737
golang.org/x/mod v0.9.0
3838
gopkg.in/natefinch/lumberjack.v2 v2.2.1
3939
gopkg.in/yaml.v3 v3.0.1
4040
)
4141

42-
require github.com/lib/pq v1.10.7 // indirect
43-
44-
require github.com/zealic/go2node v0.1.0 // indirect
45-
4642
require (
4743
github.com/InVisionApp/go-health/v2 v2.1.3 // indirect
4844
github.com/InVisionApp/go-logger v1.0.1 // indirect
@@ -58,6 +54,7 @@ require (
5854
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
5955
github.com/klauspost/compress v1.16.3 // indirect
6056
github.com/klauspost/pgzip v1.2.5 // indirect
57+
github.com/lib/pq v1.10.7 // indirect
6158
github.com/mattn/go-colorable v0.1.13 // indirect
6259
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
6360
github.com/mpvl/unique v0.0.0-20150818121801-cbe035fff7de // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ github.com/MicahParks/keyfunc/v2 v2.1.0/go.mod h1:rW42fi+xgLJ2FRRXAfNx9ZA8WpD4Oe
1515
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
1616
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
1717
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
18-
github.com/a8m/envsubst v1.4.2 h1:4yWIHXOLEJHQEFd4UjrWDrYeYlV7ncFWJOCBRLOZHQg=
19-
github.com/a8m/envsubst v1.4.2/go.mod h1:MVUTQNGQ3tsjOOtKCNd+fl8RzhsXcDvvAEzkhGtlsbY=
2018
github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0=
2119
github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30=
2220
github.com/alicebob/gopher-json v0.0.0-20180125190556-5a6b3ba71ee6/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=

internal/boxcli/global.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/pkg/errors"
1010
"github.com/spf13/cobra"
11+
1112
"go.jetpack.io/devbox"
1213
"go.jetpack.io/devbox/internal/impl/devopt"
1314
"go.jetpack.io/devbox/internal/ux"

internal/boxcli/setup.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package boxcli
66
import (
77
"os"
88

9-
"github.com/fatih/color"
109
"github.com/samber/lo"
1110
"github.com/spf13/cobra"
1211

@@ -38,10 +37,10 @@ func setupCmd() *cobra.Command {
3837

3938
func runInstallNixCmd(cmd *cobra.Command) error {
4039
if nix.BinaryInstalled() {
41-
color.New(color.FgYellow).Fprint(
40+
ux.Finfo(
4241
cmd.ErrOrStderr(),
43-
"Nix is already installed. If this is incorrect please remove the "+
44-
"nix-shell binary from your path.\n",
42+
"Nix is already installed. If this is incorrect "+
43+
"please remove the nix-shell binary from your path.\n",
4544
)
4645
return nil
4746
}

internal/nix/install.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"go.jetpack.io/devbox/internal/build"
2121
"go.jetpack.io/devbox/internal/cmdutil"
2222
"go.jetpack.io/devbox/internal/fileutil"
23+
"go.jetpack.io/devbox/internal/ux"
2324
)
2425

2526
const rootError = "warning: installing Nix as root is not supported by this script!"
@@ -70,9 +71,9 @@ func Install(writer io.Writer, daemon *bool) error {
7071
}
7172

7273
if strings.Contains(buf.String(), rootError) {
73-
color.New(color.FgYellow).Fprintln(
74+
ux.Finfo(
7475
writer,
75-
"If installing nix as root, consider using the --daemon flag to install in multi-user mode.",
76+
"If installing nix as root, consider using the --daemon flag to install in multi-user mode.\n",
7677
)
7778
}
7879
close(done)

internal/ux/messages.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ func Fsuccess(w io.Writer, format string, a ...any) {
1515
fmt.Fprintf(w, format, a...)
1616
}
1717

18+
func Finfo(w io.Writer, format string, a ...any) {
19+
color.New(color.FgYellow).Fprint(w, "Info: ")
20+
fmt.Fprintf(w, format, a...)
21+
}
22+
1823
func Fwarning(w io.Writer, format string, a ...any) {
1924
color.New(color.FgHiYellow).Fprint(w, "Warning: ")
2025
fmt.Fprintf(w, format, a...)

internal/vercheck/vercheck.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ import (
1616
"github.com/fatih/color"
1717
"github.com/pkg/errors"
1818
"github.com/samber/lo"
19+
"golang.org/x/mod/semver"
20+
1921
"go.jetpack.io/devbox/internal/boxcli/usererr"
2022
"go.jetpack.io/devbox/internal/build"
2123
"go.jetpack.io/devbox/internal/cmdutil"
2224
"go.jetpack.io/devbox/internal/envir"
2325
"go.jetpack.io/devbox/internal/ux"
2426
"go.jetpack.io/devbox/internal/xdg"
25-
"golang.org/x/mod/semver"
2627
)
2728

2829
// Keep this in-sync with latest version in launch.sh.
@@ -73,17 +74,15 @@ func CheckVersion(w io.Writer, commandPath string) {
7374
// check launcher version
7475
launcherNotice := launcherVersionNotice()
7576
if launcherNotice != "" {
76-
// TODO: use ux.FNotice
77-
color.New(color.FgYellow).Fprintf(w, launcherNotice)
77+
ux.Finfo(w, launcherNotice)
7878

7979
// fallthrough to alert the user about a new Devbox CLI binary being possibly available
8080
}
8181

8282
// check devbox CLI version
8383
devboxNotice := devboxVersionNotice()
8484
if devboxNotice != "" {
85-
// TODO: use ux.FNotice
86-
color.New(color.FgYellow).Fprintf(w, devboxNotice)
85+
ux.Finfo(w, devboxNotice)
8786
}
8887

8988
os.Setenv(envName, "1")

0 commit comments

Comments
 (0)