lib/sct/commands/hostfile.rb in sct-0.1.12 vs lib/sct/commands/hostfile.rb in sct-0.1.13

- old
+ new

@@ -34,20 +34,35 @@ hosts_paths << "/mnt/c/Windows/System32/drivers/etc/hosts" end end hosts_paths.each do |hosts_path| - hosts = Hosts::File.read(hosts_path) - if ([ingressAddress].any? { |ip| hosts.to_s =~ /#{ip}/ }) - puts "Skipped patching #{hosts_path} (already up to date)".green - else - validate_if_exist(hosts) - add_entry(ingressAddress, hosts) - hosts.write - puts "Patched #{hosts_path} with #{ingressAddress}".green + begin + hosts = Hosts::File.read(hosts_path) + + if ([ingressAddress].any? { |ip| hosts.to_s =~ /#{ip}/ }) + puts "Skipped patching #{hosts_path} (already up to date)".green + else + validate_if_exist(hosts) + add_entry(ingressAddress, hosts) + hosts.write + puts "Patched #{hosts_path} with #{ingressAddress}".green + end + rescue ArgumentError + puts "🔥 Can't read your hostfile".red + puts " Please update your hostsfile manually at #{hosts_path} with the following entries" + puts " " + puts " #{ingressAddress} spend.cloud.local".yellow + puts " #{ingressAddress} mail.spend.cloud.local".yellow + puts " #{ingressAddress} config.spend.cloud.local".yellow + puts " #{ingressAddress} spend-cloud.spend.cloud.local".yellow + puts " #{ingressAddress} docs.spend.cloud.local".yellow + puts " " end + end + end def add_entry(url, hosts) spend = Hosts::Entry.new( url,