Skip to content

Commit

Permalink
Add override info to running command
Browse files Browse the repository at this point in the history
  • Loading branch information
rcaught committed Sep 15, 2019
1 parent 369c3ad commit cd140a7
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ func overrideCmd() *cobra.Command {
createHostsBackup(hostsFileLocation)
removeOverrides(hostsFileLocation) // Fixes unclean shutdown
parsedOverrides := parsedOverrides(hosts, values)
parsedOverridesAsHosts := parsedOverridesAsHosts(parsedOverrides)
appendOverrides(hostsFileLocation, parsedOverridesAsHosts)
parsedOverridesForHosts := parsedOverridesForHosts(parsedOverrides)
appendOverrides(hostsFileLocation, parsedOverridesForHosts)
fmt.Println("\nAdding the following hosts file entries for the lifetime of this process:")
fmt.Println("\n" + *parsedOverridesAsHosts(parsedOverrides) + "\n")
waitUntilExit()
removeOverrides(hostsFileLocation)
},
Expand Down Expand Up @@ -108,9 +110,16 @@ func finishComment() string {
return wrappingComment("FINISH")
}

func parsedOverridesAsHosts(parsedOverrides *map[string][]string) *string {
func parsedOverridesForHosts(parsedOverrides *map[string][]string) *string {
o := startComment()
o = o + *parsedOverridesAsHosts(parsedOverrides)
o = o + finishComment()

return &o
}

func parsedOverridesAsHosts(parsedOverrides *map[string][]string) *string {
var o string
for ip, hosts := range *parsedOverrides {
o = o + ip + " "
for _, host := range hosts {
Expand All @@ -120,8 +129,6 @@ func parsedOverridesAsHosts(parsedOverrides *map[string][]string) *string {
o = o + "\n"
}

o = o + finishComment()

return &o
}

Expand Down

0 comments on commit cd140a7

Please sign in to comment.