Add self-update, release 1.0.2

nscan update installs the newest release from git.micw.org, nscan
update -c only checks; --update and --check-update work as well. The
download lands next to the running binary, is started once with
--version and only then replaces it.

Once a day an ordinary run asks in the background and mentions a newer
release in the title bar and on stderr, only on a terminal and not with
NSCAN_NO_UPDATE_CHECK set. selfupdate.go is goca's copyable template.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
mikeandClaude Opus 5.5 committed 2026-10-26 16:25:36 +01:00
1 parent 60257239d7
commit c91dbe9f7d
11 files changed
+761 -16

No files matched your search

+1
View File
@@ -38,6 +38,7 @@ type Config struct {
OUI *oui.DB
ExportDir string
Version string // shown in the title bar and the help screen
Update string // a newer release, if one is known
}
// Run starts the interface and blocks until the user quits.
+13
View File
@@ -234,3 +234,16 @@ func TestLayoutFollowsContent(t *testing.T) {
t.Errorf("table %d wide, want 100", got)
}
}
func TestUpdateHintShown(t *testing.T) {
m := testModel(t)
m.cfg.Version, m.cfg.Update = "1.0.1", "1.0.2"
m.Update(tea.WindowSizeMsg{Width: 120, Height: 40})
if got := ansi.Strip(m.View()); !strings.Contains(got, "nscan 1.0.1 → 1.0.2") {
t.Errorf("title bar without the update: %q", strings.SplitN(got, "\n", 2)[0])
}
m.Update(key("?"))
if got := ansi.Strip(m.View()); !strings.Contains(got, "1.0.2 is available, run nscan update") {
t.Error("help screen does not mention the update")
}
}
+1
View File
@@ -50,6 +50,7 @@ var (
styleBar = fg(mwxWhite).Background(mwxSurface)
styleBarName = fg(mwxViolet).Background(mwxSurface).Bold(true)
styleBarDim = fg(mwxGrey).Background(mwxSurface)
styleBarWarn = fg(mwxYellow).Background(mwxSurface)
// The selected row looks like fzf's current line: white on darker with a
// violet pointer.
+7
View File
@@ -155,6 +155,9 @@ func (m *model) titleBar(right string) string {
if m.cfg.Version != "" {
left += styleBarDim.Render(m.cfg.Version + " ")
}
if m.cfg.Update != "" {
left += styleBarWarn.Render("→ " + m.cfg.Update + " ")
}
left += styleBar.Render(" ")
info := fmt.Sprintf("%s · %s", n.Iface.Name, m.cfg.Range)
if n.Gateway.IsValid() {
@@ -549,6 +552,10 @@ func (m *model) viewHelp() string {
if m.cfg.Version != "" {
lines = append(lines, styleDim.Render(" Version: ")+m.cfg.Version)
}
if m.cfg.Update != "" {
lines = append(lines, styleDim.Render(" Update: ")+styleWarn.Render(m.cfg.Update+" is available")+
styleDim.Render(", run ")+"nscan update"+styleDim.Render(" after quitting"))
}
body := lines[1:]
m.helpOff = min(m.helpOff, max(0, len(body)-(m.h-2)))
return m.screen(append([]string{lines[0]}, body[m.helpOff:]...), m.footer("↑/↓ scroll", "esc back"))