Skip to content

Commit

Permalink
chore: more comments, typos, error message in unmanaged
Browse files Browse the repository at this point in the history
  • Loading branch information
ZinoKader committed Feb 13, 2023
1 parent f7263f0 commit f8cf369
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ build:
go build -o portal ./cmd/portal/

build-production:
CGO=0 go build -ldflags=${LINKER_FLAGS} -o portal ./cmd/portal
CGO=0 go build -ldflags=${LINKER_FLAGS} -o portal ./cmd/portal

build-wasm:
GOOS=js GOARCH=wasm go build -o portal.wasm ./cmd/wasm/main.go
Expand Down
1 change: 1 addition & 0 deletions cmd/portal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
)

// version represents the version of portal.
// injected at link time using -ldflags.
var version string

// rootCmd is the top level `portal` command on which the other subcommands are attached to.
Expand Down
15 changes: 8 additions & 7 deletions ui/sender/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@ func New(filenames []string, addr string, opts ...Option) *tea.Program {
}

func (m model) Init() tea.Cmd {
if m.version == nil {
return tea.Batch(m.spinner.Tick, readFilesCmd(m.fileNames), connectCmd(m.rendezvousAddr))
var versionCmd tea.Cmd
if m.version != nil {
versionCmd = ui.VersionCmd(*m.version)
}
return ui.VersionCmd(*m.version)
return tea.Sequence(versionCmd, tea.Batch(m.spinner.Tick, readFilesCmd(m.fileNames), connectCmd(m.rendezvousAddr)))
}

// ------------------------------------------------------- Update ------------------------------------------------------
Expand All @@ -129,18 +130,18 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case semver.CompareNewMajor,
semver.CompareNewMinor,
semver.CompareNewPatch:
//lint:ignore ST1005 error string displayed in UI
return m, ui.ErrorCmd(fmt.Errorf("Your version is (%s) is incompatible with the latest version (%s)", m.version, msg.Latest))
case semver.CompareOldMajor:
return m, ui.ErrorCmd(fmt.Errorf("New major version available (%s -> %s)", m.version, msg.Latest))
message = ui.WarningText(fmt.Sprintf("New major version available (%s -> %s)", m.version, msg.Latest))
case semver.CompareOldMinor:
message = ui.WarningText(fmt.Sprintf("New minor version available (%s -> %s)", m.version, msg.Latest))
case semver.CompareOldPatch:
message = ui.WarningText(fmt.Sprintf("New patch available (%s -> %s)", m.version, msg.Latest))
case semver.CompareEqual:
message = ui.CheckText(fmt.Sprintf("You have the latest version (%s)", m.version))
default:
return m, ui.TaskCmd(message, tea.Batch(m.spinner.Tick, readFilesCmd(m.fileNames), connectCmd(m.rendezvousAddr)))
message = ui.CheckText(fmt.Sprintf("On latest version (%s)", m.version))
}
return m, ui.TaskCmd(message, nil)

case fileReadMsg:
m.uncompressedSize = msg.size
Expand Down
2 changes: 1 addition & 1 deletion ui/transferprogress/transferprogress.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
bytesRemaining := m.PayloadSize - m.bytesTransferred
linearRemainingSeconds := float64(bytesRemaining) * secondsSpent / float64(m.bytesTransferred)
if remainingDuration, err := time.ParseDuration(fmt.Sprintf("%fs", linearRemainingSeconds)); err != nil {
return m, ui.ErrorCmd(errors.Wrap(err, "failed to parse duration of estimated remaining transfer time"))
return m, ui.ErrorCmd(errors.Wrap(err, "failed to parse duration of transfer ETA"))
} else {
m.estimatedRemainingDuration = remainingDuration
}
Expand Down
5 changes: 1 addition & 4 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,5 @@ func VersionCmd(version semver.Version) tea.Cmd {
}

func ErrorCmd(err error) tea.Cmd {
cmd := func() tea.Msg {
return ErrorMsg(err)
}
return TaskCmd(ErrorText(err.Error()), cmd)
return TaskCmd(ErrorText(err.Error()), QuitCmd())
}

0 comments on commit f8cf369

Please sign in to comment.