-
Notifications
You must be signed in to change notification settings - Fork 42
Description
Problem
If you work with multiple environments you end up with blocks of hosts entries that you comment and uncomment by hand. hostctl has profile management for this, but only as a CLI with no library API.
txeh already has AddHostWithComment and RemoveByComment, which track where entries came from. Profiles can build on that.
Proposed solution
Tag entries with [profile:name] in a comment. Enabled entries are active lines; disabled entries are comment-prefixed. The hosts file stays readable and editable by hand.
10.0.0.1 myservice.local # [profile:dev]
# [profile:staging] 10.1.0.1 myservice.local
CLI:
txeh profile add dev 10.0.0.1 myservice.local
txeh profile enable dev
txeh profile disable dev # comments out, doesn't delete
txeh profile list
txeh profile show dev
txeh profile remove staging
txeh profile export dev > dev.json
txeh profile import < team.jsonLibrary:
hosts.AddProfile("dev", []ProfileEntry{
{IP: "10.0.0.1", Hosts: []string{"myservice.local"}},
})
hosts.EnableProfile("dev")
hosts.DisableProfile("staging")
hosts.ListProfiles() // []string
hosts.ProfileEntries("dev") // []ProfileEntry
hosts.RemoveProfile("dev")
hosts.ExportProfile("dev") // []byte (JSON)
hosts.ImportProfile(data)Enabling a profile doesn't disable others. Entries without a profile tag are left alone. All operations go through the existing mutex.
Alternatives considered
Separate file per profile: you lose the single-file view when editing /etc/hosts by hand, and merging adds complexity.
Sidecar state file (SQLite, JSON): the hosts file should be the source of truth. Comment tags keep everything in one place with no extra dependencies.