diff --git a/cmd/hostess/hostess.go b/cmd/hostess/hostess.go index 4bc3751..05ecefb 100644 --- a/cmd/hostess/hostess.go +++ b/cmd/hostess/hostess.go @@ -100,6 +100,12 @@ func main() { Action: hostess.Fix, Flags: app.Flags, }, + { + Name: "fixed", + Usage: "exit 0 if the hosts file is formatted, 1 if not", + Action: hostess.Fixed, + Flags: app.Flags, + }, { Name: "dump", Usage: "dump the hosts file as JSON", diff --git a/commands.go b/commands.go index 57e6a1e..1914783 100644 --- a/commands.go +++ b/commands.go @@ -239,6 +239,18 @@ func Fix(c *cli.Context) { MaybeSaveHostFile(c, hostsfile) } +// Fixed command removes duplicates and conflicts from the hosts file +func Fixed(c *cli.Context) { + hostsfile := AlwaysLoadHostFile(c) + if bytes.Equal(hostsfile.GetData(), hostsfile.Format()) { + MaybePrintln(c, fmt.Sprintf("%s is already formatted and contains no dupes or conflicts", GetHostsPath())) + os.Exit(0) + } else { + MaybePrintln(c, fmt.Sprintf("%s is not formatted. Use hostess fix to format it", GetHostsPath())) + os.Exit(1) + } +} + // Dump command outputs hosts file contents as JSON func Dump(c *cli.Context) { hostsfile := AlwaysLoadHostFile(c)