-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from guillaumerose/master
Prepare for diverging from goodhost-cli
- Loading branch information
Showing
313 changed files
with
28,434 additions
and
17,164 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
.DS_Store | ||
goodhosts | ||
goodhosts.exe | ||
admin-helper | ||
admin-helper.exe | ||
.idea | ||
dist | ||
out | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
run: | ||
timeout: 10m | ||
|
||
linters: | ||
enable: | ||
- errcheck | ||
- goimports | ||
- gofmt | ||
- gosec | ||
- gocritic | ||
- deadcode | ||
- misspell | ||
- golint |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,44 @@ | ||
package cmd | ||
|
||
import ( | ||
"strings" | ||
"fmt" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/urfave/cli/v2" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func Add() *cli.Command { | ||
return &cli.Command{ | ||
Name: "add", | ||
Aliases: []string{"a"}, | ||
Usage: "Add an entry to the hostsfile", | ||
Action: add, | ||
ArgsUsage: "[IP] [HOST] ([HOST]...)", | ||
} | ||
var Add = &cobra.Command{ | ||
Use: "add", | ||
Aliases: []string{"a"}, | ||
Short: "Add an entry to the hostsfile", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return add(args) | ||
}, | ||
} | ||
func add(c *cli.Context) error { | ||
|
||
args := c.Args() | ||
|
||
if args.Len() < 2 { | ||
logrus.Infof("adding a hostsfile entry requires an ip and a hostname.") | ||
return nil | ||
func add(args []string) error { | ||
if len(args) < 2 { | ||
return fmt.Errorf("adding to hosts file requires an ip and a hostname") | ||
} | ||
|
||
hostsfile, err := loadHostsfile(c) | ||
hostsFile, err := loadHostsFile() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ip := args.Slice()[0] | ||
ip := args[0] | ||
uniqueHosts := map[string]bool{} | ||
var hostEntries []string | ||
|
||
for i := 1; i < args.Len(); i++ { | ||
uniqueHosts[args.Slice()[i]] = true | ||
for i := 1; i < len(args); i++ { | ||
uniqueHosts[args[i]] = true | ||
} | ||
|
||
for key, _ := range uniqueHosts { | ||
for key := range uniqueHosts { | ||
hostEntries = append(hostEntries, key) | ||
} | ||
|
||
err = hostsfile.Add(ip, hostEntries...) | ||
if err != nil { | ||
return cli.NewExitError(err.Error(), 2) | ||
} | ||
|
||
logrus.Debugln("flushing hosts file to disk") | ||
err = hostsfile.Flush() | ||
if err != nil { | ||
return cli.NewExitError(err.Error(), 2) | ||
if err := hostsFile.Add(ip, hostEntries...); err != nil { | ||
return err | ||
} | ||
|
||
logrus.Infof("hosts entry added: %s %s\n", ip, strings.Join(hostEntries, " ")) | ||
return debugFooter(c) | ||
return hostsFile.Flush() | ||
} |
Oops, something went wrong.