Added fixed command to get exit status 0/1 if hosts file is already formatted

pull/26/head
Chris Bednarski 8 years ago
parent 9ab36e01a3
commit c8aa1a891b

@ -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",

@ -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)

Loading…
Cancel
Save