Compare commits

..
17 Commits
Author SHA1 Message Date
lukaszraczylo 27d5011ab1 fix: remove unnecessary verified parameter from homebrew cask
The verified parameter is only needed when the URL domain differs
from the homepage domain. Since both point to github.com, Homebrew
audit flags this as unnecessary.
2025-12-08 02:08:00 +00:00
lukaszraczylo 51119b3694 Use shared PR workflow 2025-12-08 01:31:55 +00:00
lukaszraczylo 1b66f4c6f9 Trigger autoupdater 2025-12-08 01:11:32 +00:00
lukaszraczylo 8c022fa0d2 fixup! fixup! Move to casks. 2025-12-07 15:53:46 +00:00
lukaszraczylo 5d8c72d75f fixup! Move to casks. 2025-12-07 14:58:25 +00:00
lukaszraczylo 2a6f0ee244 Move to casks. 2025-12-07 14:49:14 +00:00
lukaszraczylo 99f215cb7c Move build and release to shared workflow 2025-12-07 13:33:46 +00:00
lukaszraczylo 6eb634bfd0 Move to shared workflows. 2025-12-07 13:25:56 +00:00
lukaszraczylo 4bf0dd2cdf Update the autoupdate workflow 2025-12-07 12:36:24 +00:00
lukaszraczylo 70ac227613 Update autoupdate workflow. LOL. 2025-12-03 00:47:35 +00:00
lukaszraczylo 90e0375a83 Remove unused functions. 2025-12-02 18:19:01 +00:00
lukaszraczyloandgithub-actions[bot] 8445e50dc8 Update go.mod and go.sum 2025-12-02 03:26:03 +00:00
lukaszraczylo e1b9c15a2a fixup! fixup! Fix autoupdate workflow 2025-12-01 14:39:46 +00:00
lukaszraczyloandgithub-actions[bot] c442eade9e Update go.mod and go.sum 2025-12-01 14:32:58 +00:00
lukaszraczylo acc80882e2 fixup! Fix autoupdate workflow 2025-12-01 14:31:00 +00:00
lukaszraczylo 5e24b13595 Fix autoupdate workflow 2025-12-01 14:24:59 +00:00
lukaszraczylo 76e364ca3e bugfix: Deleted hosts were lingering in the TUI list. 2025-11-29 02:38:12 +00:00
13 changed files with 212 additions and 150 deletions
+14 -41
View File
@@ -1,47 +1,20 @@
name: AutoUpdate name: Autoupdate go.mod and go.sum
on: on:
workflow_dispatch:
schedule: schedule:
- cron: "0 3 * * *" - cron: "0 3 * * *"
workflow_dispatch:
permissions:
contents: write
actions: write
pull-requests: write
jobs: jobs:
prepare: autoupdate:
runs-on: ubuntu-latest uses: lukaszraczylo/shared-actions/.github/workflows/go-autoupdate.yaml@main
steps: with:
- name: Checkout go-version: "1.24"
uses: actions/checkout@v4 release-workflow: "release.yml"
secrets:
- name: Setup Go pat-token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
uses: actions/setup-go@v5
with:
go-version: "1.24"
cache: true
- name: Install dependencies
run: go get ./...
test:
needs: prepare
runs-on: ubuntu-latest
container: golang:1
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
run: apt-get update && apt-get install -y ca-certificates make
- name: Tidy and update modules
run: |
go mod tidy
go get -u -v ./...
- name: Run tests
run: CI_RUN=${CI} go test -v ./...
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Update go.mod and go.sum"
file_pattern: "go.mod go.sum"
+16
View File
@@ -0,0 +1,16 @@
name: Pull Request
on:
pull_request:
branches:
- main
push:
branches:
- "**"
- "!main"
jobs:
pr-checks:
uses: lukaszraczylo/shared-actions/.github/workflows/go-pr.yaml@main
with:
go-version: "1.24"
+7 -77
View File
@@ -10,82 +10,12 @@ on:
- "go.sum" - "go.sum"
workflow_dispatch: workflow_dispatch:
permissions:
contents: write
jobs: jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.24"
- name: Run tests
run: go test -race -v ./...
version:
needs: test
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version_formatted.outputs.version }}
version_tag: ${{ steps.version_formatted.outputs.version_tag }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Calculate version
id: semver
uses: lukaszraczylo/semver-generator@v1
with:
config_file: semver.yaml
repository_local: true
- name: Format version
id: version_formatted
run: |
VERSION="${{ steps.semver.outputs.semantic_version }}"
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "version_tag=v${VERSION}" >> $GITHUB_OUTPUT
- name: Print version
run: |
echo "Version: ${{ steps.version_formatted.outputs.version }}"
echo "Version tag: ${{ steps.version_formatted.outputs.version_tag }}"
release: release:
needs: version uses: lukaszraczylo/shared-actions/.github/workflows/go-release.yaml@main
if: needs.version.outputs.version_tag != '' with:
runs-on: ubuntu-latest go-version: "1.24"
permissions: secrets: inherit
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.24"
- name: Create and push tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a ${{ needs.version.outputs.version_tag }} -m "Release ${{ needs.version.outputs.version }}"
git push origin ${{ needs.version.outputs.version_tag }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: "~> v2"
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
+11 -6
View File
@@ -22,7 +22,7 @@ builds:
archives: archives:
- id: lolcathost - id: lolcathost
format: tar.gz formats: [tar.gz]
name_template: "lolcathost-{{ .Version }}-{{ .Os }}-{{ .Arch }}" name_template: "lolcathost-{{ .Version }}-{{ .Os }}-{{ .Arch }}"
files: files:
- LICENSE - LICENSE
@@ -49,14 +49,19 @@ release:
draft: false draft: false
prerelease: auto prerelease: auto
brews: homebrew_casks:
- repository: - repository:
owner: lukaszraczylo owner: lukaszraczylo
name: homebrew-taps name: homebrew-taps
token: "{{ .Env.HOMEBREW_TAP_TOKEN }}" token: "{{ .Env.HOMEBREW_TAP_TOKEN }}"
directory: Formula directory: Casks
homepage: https://github.com/lukaszraczylo/lolcathost homepage: https://github.com/lukaszraczylo/lolcathost
description: "Dynamic host management tool for macOS and Linux with TUI" description: "Dynamic host management tool with TUI"
license: MIT license: MIT
test: | hooks:
system "#{bin}/lolcathost", "--version" post:
install: |
if OS.mac?
system_command "/usr/bin/xattr",
args: ["-dr", "com.apple.quarantine", "#{staged_path}/lolcathost"]
end
+7 -2
View File
@@ -50,12 +50,17 @@ lolcathost manages your `/etc/hosts` file with an interactive terminal interface
## Installation ## Installation
### Homebrew (macOS/Linux) ### Homebrew (macOS)
```bash ```bash
brew install lukaszraczylo/taps/lolcathost brew install --cask lukaszraczylo/taps/lolcathost
``` ```
> **Note**: If you previously installed via `brew install lukaszraczylo/taps/lolcathost` (formula), uninstall first:
> ```bash
> brew uninstall lolcathost
> ```
After Homebrew installation, run: After Homebrew installation, run:
```bash ```bash
+2 -2
View File
@@ -276,9 +276,9 @@
<div class="glass p-6 rounded-xl"> <div class="glass p-6 rounded-xl">
<h3 class="font-semibold text-gray-900 dark:text-gray-100 mb-3 flex items-center"> <h3 class="font-semibold text-gray-900 dark:text-gray-100 mb-3 flex items-center">
<i class="fas fa-beer mr-2 text-amber-500"></i> <i class="fas fa-beer mr-2 text-amber-500"></i>
Homebrew (macOS/Linux) Homebrew (macOS)
</h3> </h3>
<pre class="bg-gray-900 text-gray-100 p-4 rounded-lg overflow-x-auto"><code>brew install lukaszraczylo/taps/lolcathost <pre class="bg-gray-900 text-gray-100 p-4 rounded-lg overflow-x-auto"><code>brew install --cask lukaszraczylo/taps/lolcathost
sudo lolcathost --install</code></pre> sudo lolcathost --install</code></pre>
</div> </div>
<div class="glass p-6 rounded-xl"> <div class="glass p-6 rounded-xl">
+1 -1
View File
@@ -19,7 +19,7 @@ require (
github.com/charmbracelet/x/ansi v0.11.2 // indirect github.com/charmbracelet/x/ansi v0.11.2 // indirect
github.com/charmbracelet/x/cellbuf v0.0.14 // indirect github.com/charmbracelet/x/cellbuf v0.0.14 // indirect
github.com/charmbracelet/x/term v0.2.2 // indirect github.com/charmbracelet/x/term v0.2.2 // indirect
github.com/clipperhouse/displaywidth v0.6.0 // indirect github.com/clipperhouse/displaywidth v0.6.1 // indirect
github.com/clipperhouse/stringish v0.1.1 // indirect github.com/clipperhouse/stringish v0.1.1 // indirect
github.com/clipperhouse/uax29/v2 v2.3.0 // indirect github.com/clipperhouse/uax29/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect
+2 -2
View File
@@ -20,8 +20,8 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payR
github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk= github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk=
github.com/charmbracelet/x/term v0.2.2/go.mod h1:kF8CY5RddLWrsgVwpw4kAa6TESp6EB5y3uxGLeCqzAI= github.com/charmbracelet/x/term v0.2.2/go.mod h1:kF8CY5RddLWrsgVwpw4kAa6TESp6EB5y3uxGLeCqzAI=
github.com/clipperhouse/displaywidth v0.6.0 h1:k32vueaksef9WIKCNcoqRNyKbyvkvkysNYnAWz2fN4s= github.com/clipperhouse/displaywidth v0.6.1 h1:/zMlAezfDzT2xy6acHBzwIfyu2ic0hgkT83UX5EY2gY=
github.com/clipperhouse/displaywidth v0.6.0/go.mod h1:R+kHuzaYWFkTm7xoMmK1lFydbci4X2CicfbGstSGg0o= github.com/clipperhouse/displaywidth v0.6.1/go.mod h1:R+kHuzaYWFkTm7xoMmK1lFydbci4X2CicfbGstSGg0o=
github.com/clipperhouse/stringish v0.1.1 h1:+NSqMOr3GR6k1FdRhhnXrLfztGzuG+VuFDfatpWHKCs= github.com/clipperhouse/stringish v0.1.1 h1:+NSqMOr3GR6k1FdRhhnXrLfztGzuG+VuFDfatpWHKCs=
github.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA= github.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA=
github.com/clipperhouse/uax29/v2 v2.3.0 h1:SNdx9DVUqMoBuBoW3iLOj4FQv3dN5mDtuqwuhIGpJy4= github.com/clipperhouse/uax29/v2 v2.3.0 h1:SNdx9DVUqMoBuBoW3iLOj4FQv3dN5mDtuqwuhIGpJy4=
+15
View File
@@ -219,6 +219,21 @@ func TestServer_HandleDelete(t *testing.T) {
assert.Equal(t, "ok", resp.Status) assert.Equal(t, "ok", resp.Status)
}) })
t.Run("verify deleted entry not in list", func(t *testing.T) {
// After delete, list should not contain the deleted entry
resp := server.handleList()
assert.Equal(t, "ok", resp.Status)
var data protocol.ListData
err := resp.ParseData(&data)
require.NoError(t, err)
// Check that the deleted entry is not in the list
for _, entry := range data.Entries {
assert.NotEqual(t, "todelete", entry.Alias, "deleted entry should not appear in list")
}
})
t.Run("delete nonexistent", func(t *testing.T) { t.Run("delete nonexistent", func(t *testing.T) {
req, _ := protocol.NewRequest(protocol.RequestDelete, protocol.DeletePayload{ req, _ := protocol.NewRequest(protocol.RequestDelete, protocol.DeletePayload{
Alias: "nonexistent", Alias: "nonexistent",
+68 -9
View File
@@ -9,6 +9,7 @@ import (
"github.com/charmbracelet/bubbles/textinput" "github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea" tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/lukaszraczylo/lolcathost/internal/client" "github.com/lukaszraczylo/lolcathost/internal/client"
"github.com/lukaszraczylo/lolcathost/internal/config" "github.com/lukaszraczylo/lolcathost/internal/config"
@@ -27,6 +28,7 @@ const (
ViewBackups ViewBackups
ViewHelp ViewHelp
ViewSearch ViewSearch
ViewConfirmDelete
) )
// Model is the main Bubble Tea model. // Model is the main Bubble Tea model.
@@ -45,13 +47,14 @@ type Model struct {
searchInput textinput.Model searchInput textinput.Model
// State // State
width int width int
height int height int
message string message string
messageStyle string // "error" or "success" messageStyle string // "error" or "success"
messageTime time.Time messageTime time.Time
searchTerm string searchTerm string
allGroups []string // All groups including empty ones allGroups []string // All groups including empty ones
pendingDeleteAlias string // Alias of host pending delete confirmation
// Update notification // Update notification
updateAvailable bool updateAvailable bool
@@ -352,7 +355,8 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// Mark as disconnected to trigger reconnect // Mark as disconnected to trigger reconnect
m.connected = false m.connected = false
m.client.Close() m.client.Close()
} else if msg.entries != nil { } else {
// Always update the list, even if entries is nil/empty
m.list.SetItems(msg.entries) m.list.SetItems(msg.entries)
} }
@@ -385,7 +389,10 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.mode = ViewList m.mode = ViewList
case deleteMsg: case deleteMsg:
// Clear pending state regardless of success/failure
m.list.SetPending(msg.alias, false)
if msg.err != nil { if msg.err != nil {
m.list.SetError(msg.alias, true)
m.setError(fmt.Sprintf("Delete failed: %v", msg.err)) m.setError(fmt.Sprintf("Delete failed: %v", msg.err))
} else { } else {
cmds = append(cmds, m.refresh()) cmds = append(cmds, m.refresh())
@@ -521,6 +528,8 @@ func (m *Model) handleKey(msg tea.KeyMsg) tea.Cmd {
return m.handleHelpKey(msg) return m.handleHelpKey(msg)
case ViewSearch: case ViewSearch:
return m.handleSearchKey(msg) return m.handleSearchKey(msg)
case ViewConfirmDelete:
return m.handleConfirmDeleteKey(msg)
} }
return nil return nil
@@ -554,7 +563,8 @@ func (m *Model) handleListKey(msg tea.KeyMsg) tea.Cmd {
} }
case "d": case "d":
if item := m.list.Selected(); item != nil { if item := m.list.Selected(); item != nil {
return m.deleteHost(item.Entry.Alias) m.pendingDeleteAlias = item.Entry.Alias
m.mode = ViewConfirmDelete
} }
case "p": case "p":
m.mode = ViewPresets m.mode = ViewPresets
@@ -850,6 +860,23 @@ func (m *Model) handleSearchKey(msg tea.KeyMsg) tea.Cmd {
return cmd return cmd
} }
func (m *Model) handleConfirmDeleteKey(msg tea.KeyMsg) tea.Cmd {
switch msg.String() {
case "y", "Y":
alias := m.pendingDeleteAlias
m.pendingDeleteAlias = ""
m.mode = ViewList
// Set pending state for visual feedback
m.list.SetPending(alias, true)
return m.deleteHost(alias)
case "n", "N", "esc":
m.pendingDeleteAlias = ""
m.mode = ViewList
return nil
}
return nil
}
func (m *Model) toggleSelected() tea.Cmd { func (m *Model) toggleSelected() tea.Cmd {
item := m.list.Selected() item := m.list.Selected()
if item == nil { if item == nil {
@@ -904,6 +931,8 @@ func (m *Model) View() string {
sb.WriteString(m.helpView()) sb.WriteString(m.helpView())
case ViewSearch: case ViewSearch:
sb.WriteString(m.searchView()) sb.WriteString(m.searchView())
case ViewConfirmDelete:
sb.WriteString(m.confirmDeleteView())
} }
// Message // Message
@@ -1077,6 +1106,36 @@ func (m *Model) searchView() string {
return dialogStyle.Render(sb.String()) return dialogStyle.Render(sb.String())
} }
func (m *Model) confirmDeleteView() string {
var sb strings.Builder
sb.WriteString(titleStyle.Render("Confirm Delete"))
sb.WriteString("\n\n")
// Find the entry details for the pending delete
var domain, ip string
for _, item := range m.list.items {
if item.Entry.Alias == m.pendingDeleteAlias {
domain = item.Entry.Domain
ip = item.Entry.IP
break
}
}
warningStyle := lipgloss.NewStyle().Foreground(colorWarning).Bold(true)
sb.WriteString(warningStyle.Render("Are you sure you want to delete this host?"))
sb.WriteString("\n\n")
sb.WriteString(fmt.Sprintf(" Alias: %s\n", helpKeyStyle.Render(m.pendingDeleteAlias)))
sb.WriteString(fmt.Sprintf(" Domain: %s\n", helpDescStyle.Render(domain)))
sb.WriteString(fmt.Sprintf(" IP: %s\n", helpDescStyle.Render(ip)))
sb.WriteString("\n")
sb.WriteString(helpDescStyle.Render("y confirm • n/Esc cancel"))
return dialogStyle.Render(sb.String())
}
// Run starts the TUI application. // Run starts the TUI application.
func Run(socketPath string) error { func Run(socketPath string) error {
return RunWithVersion(socketPath, "dev", "", "") return RunWithVersion(socketPath, "dev", "", "")
-5
View File
@@ -295,11 +295,6 @@ func (l *ListView) ViewFiltered(searchTerm string) string {
return sb.String() return sb.String()
} }
// GroupCount returns the number of groups.
func (l *ListView) GroupCount() int {
return len(l.groupOrder)
}
// GetGroups returns all group names. // GetGroups returns all group names.
func (l *ListView) GetGroups() []string { func (l *ListView) GetGroups() []string {
return l.groupOrder return l.groupOrder
+69
View File
@@ -407,3 +407,72 @@ func BenchmarkListView_View(b *testing.B) {
_ = lv.View() _ = lv.View()
} }
} }
func TestListView_DeleteSimulation(t *testing.T) {
lv := NewListView()
// Initial entries
entries := []protocol.HostEntry{
{Domain: "a.com", IP: "127.0.0.1", Alias: "a", Enabled: true, Group: "dev"},
{Domain: "b.com", IP: "127.0.0.1", Alias: "b", Enabled: false, Group: "dev"},
{Domain: "c.com", IP: "192.168.1.1", Alias: "c", Enabled: true, Group: "staging"},
}
lv.SetItems(entries)
require.Equal(t, 3, lv.Len())
// Select the second item
lv.MoveDown()
selected := lv.Selected()
require.NotNil(t, selected)
require.Equal(t, "b", selected.Entry.Alias)
// Simulate delete: set new items without the deleted entry
entriesAfterDelete := []protocol.HostEntry{
{Domain: "a.com", IP: "127.0.0.1", Alias: "a", Enabled: true, Group: "dev"},
{Domain: "c.com", IP: "192.168.1.1", Alias: "c", Enabled: true, Group: "staging"},
}
lv.SetItems(entriesAfterDelete)
// Verify list has only 2 items now
assert.Equal(t, 2, lv.Len())
// Verify "b" is no longer in the list
for i := 0; i < lv.Len(); i++ {
assert.NotEqual(t, "b", lv.items[i].Entry.Alias, "deleted entry should not be in list")
}
// Cursor should be adjusted if needed
assert.LessOrEqual(t, lv.cursor, lv.Len()-1)
}
func TestListView_SetItemsWithNil(t *testing.T) {
lv := NewListView()
// Initial entries
entries := []protocol.HostEntry{
{Domain: "a.com", IP: "127.0.0.1", Alias: "a", Enabled: true, Group: "dev"},
}
lv.SetItems(entries)
require.Equal(t, 1, lv.Len())
// Set nil entries (simulating empty list from server)
lv.SetItems(nil)
assert.Equal(t, 0, lv.Len())
assert.Equal(t, 0, lv.cursor)
}
func TestListView_SetItemsWithEmptySlice(t *testing.T) {
lv := NewListView()
// Initial entries
entries := []protocol.HostEntry{
{Domain: "a.com", IP: "127.0.0.1", Alias: "a", Enabled: true, Group: "dev"},
}
lv.SetItems(entries)
require.Equal(t, 1, lv.Len())
// Set empty slice
lv.SetItems([]protocol.HostEntry{})
assert.Equal(t, 0, lv.Len())
assert.Equal(t, 0, lv.cursor)
}
-5
View File
@@ -146,11 +146,6 @@ func StatusText(enabled bool, pending bool, hasError bool) string {
return disabledStyle.Render("○ Disabled") return disabledStyle.Render("○ Disabled")
} }
// HelpItem formats a help item.
func HelpItem(key, desc string) string {
return helpKeyStyle.Render(key) + " " + helpDescStyle.Render(desc)
}
// WrapHelpText wraps help text to fit within maxWidth, splitting on bullet separators. // WrapHelpText wraps help text to fit within maxWidth, splitting on bullet separators.
// If maxWidth is 0 or negative, returns the original text. // If maxWidth is 0 or negative, returns the original text.
func WrapHelpText(text string, maxWidth int) string { func WrapHelpText(text string, maxWidth int) string {