go mod & remove add command
This commit is contained in:
parent
39b9656baa
commit
c0953419d2
5
go.mod
Normal file
5
go.mod
Normal file
@ -0,0 +1,5 @@
|
||||
module github.com/dalu/spamip
|
||||
|
||||
go 1.13
|
||||
|
||||
require github.com/urfave/cli v1.22.1
|
12
go.sum
Normal file
12
go.sum
Normal file
@ -0,0 +1,12 @@
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/urfave/cli v1.22.1 h1:+mkCCcOFKPnCmVYVcURKps1Xe+3zP90gSYGNfRkjoIY=
|
||||
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
32
main.go
32
main.go
@ -15,12 +15,12 @@ const (
|
||||
zoneFilePath = "/var/bind/pri/localhost.zone"
|
||||
)
|
||||
|
||||
var re = regexp.MustCompile(`^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$`)
|
||||
var re = regexp.MustCompile(`^([0-9]{1,3}|\*)\.([0-9]{1,3}|\*)\.([0-9]{1,3}|\*)\.([0-9]{1,3}|\*)$`)
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "spamip"
|
||||
app.Version = "0.1"
|
||||
app.Version = "0.2"
|
||||
app.Compiled = time.Now()
|
||||
app.Authors = []cli.Author{
|
||||
{
|
||||
@ -42,24 +42,18 @@ func main() {
|
||||
},
|
||||
}
|
||||
|
||||
app.Commands = []cli.Command{
|
||||
{
|
||||
Name: "add",
|
||||
Aliases: []string{"a"},
|
||||
Usage: "add an IP address to the zone file",
|
||||
Action: func(c *cli.Context) error {
|
||||
if len(c.Args()) != 1 {
|
||||
return errors.New("add takes exactly 1 argument, an IPv4 address")
|
||||
}
|
||||
if !re.MatchString(c.Args().First()) {
|
||||
return errors.New(c.Args().First() + "is not an IPv4 address")
|
||||
}
|
||||
s := re.FindStringSubmatch(c.Args().First())
|
||||
text := fmt.Sprintf("%s.%s.%s.%s\tIN\tA\t127.0.0.3\n", s[4], s[3], s[2], s[1])
|
||||
return appendText(text, c.GlobalString("file"))
|
||||
},
|
||||
},
|
||||
app.Action = func(c *cli.Context) error {
|
||||
if len(c.Args()) != 1 {
|
||||
return errors.New("add takes exactly 1 argument, an IPv4 address")
|
||||
}
|
||||
if !re.MatchString(c.Args().First()) {
|
||||
return errors.New(c.Args().First() + "is not an IPv4 address")
|
||||
}
|
||||
s := re.FindStringSubmatch(c.Args().First())
|
||||
text := fmt.Sprintf("%s.%s.%s.%s\tIN\tA\t127.0.0.3\n", s[4], s[3], s[2], s[1])
|
||||
return appendText(text, c.GlobalString("file"))
|
||||
}
|
||||
|
||||
err := app.Run(os.Args)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
Loading…
Reference in New Issue
Block a user