From e899791fceb0811a03deeb82f32361523b5216aa Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Tue, 10 Mar 2020 10:22:15 -0700 Subject: [PATCH] Don't fail when a duplicate is encountered (fixes #39) --- commands.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/commands.go b/commands.go index 5de8683..4ddadf0 100644 --- a/commands.go +++ b/commands.go @@ -25,11 +25,21 @@ func PrintErrLn(err error) { func LoadHostfile() (*hostess.Hostfile, error) { hosts, errs := hostess.LoadHostfile() + fatal := false + if len(errs) > 0 { for _, err := range errs { PrintErrLn(err) + // If we find a duplicate we'll notify the user and continue. For + // other errors we'll bail out. + if !strings.Contains(err.Error(), "duplicate hostname entry") { + fatal = true + } } - return nil, errors.New("Errors while parsing hostsfile. Please fix any dupes or conflicts and try again.") + } + + if fatal { + return nil, errors.New("Errors while parsing hostsfile. Please resolve any conflicts and try again.") } return hosts, nil @@ -210,7 +220,7 @@ func List(options *Options) error { return nil } -// Format command removes duplicates and conflicts from the hosts file +// Format command removes duplicates from the hosts file func Format(options *Options) error { hostsfile, err := LoadHostfile() if err != nil {