diff --git a/cmd/hostess/hostess.go b/cmd/hostess/hostess.go index 1ccdd8b..094ab69 100644 --- a/cmd/hostess/hostess.go +++ b/cmd/hostess/hostess.go @@ -79,14 +79,14 @@ func main() { Flags: app.Flags, }, { - Name: "off", - Usage: "disable a hosts entry (don't delete it)", - Action: hostess.Off, + Name: "on", + Usage: "enable a hosts entry (if if exists)", + Action: hostess.On, Flags: app.Flags, }, { - Name: "on", - Usage: "enable a hosts entry (if if exists)", + Name: "off", + Usage: "disable a hosts entry (don't delete it)", Action: hostess.On, Flags: app.Flags, }, diff --git a/commands.go b/commands.go index e27d798..24ce6b5 100644 --- a/commands.go +++ b/commands.go @@ -150,29 +150,29 @@ func Has(c *cli.Context) { } -// Off command disables (comments) the specified hostname in the hosts file -func Off(c *cli.Context) { - if len(c.Args()) != 1 { - MaybeError(c, "expected ") - } - -} - -// On command enabled (uncomments) the specified hostname in the hosts file +// On (and off) command enables (uncomments) or disables (comments) the +// specified hostname in the hosts file func On(c *cli.Context) { if len(c.Args()) != 1 { MaybeError(c, "expected ") } domain := c.Args()[0] hostsfile := MaybeLoadHostFile(c) - success := hostsfile.Hosts.Enable(domain) + + // Switch on / off commands + success := false + if c.Command.Name == "on" { + success = hostsfile.Hosts.Enable(domain) + } else { + success = hostsfile.Hosts.Disable(domain) + } + if success { MaybeSaveHostFile(c, hostsfile) MaybePrintln(c, fmt.Sprintf("Enabled %s", domain)) } else { MaybeError(c, fmt.Sprintf("%s not found in %s", domain, GetHostsPath())) } - } // Ls command shows a list of hostnames in the hosts file