From a0e53d5cd7aa142e48d6b846591a9b9b37ba75e6 Mon Sep 17 00:00:00 2001 From: Thomas Mills Date: Fri, 3 Feb 2023 17:40:03 +0000 Subject: [PATCH] Prevent multiple AIRACs being read --- README.md | 7 ++++++- go.mod | 2 ++ go.sum | 4 ++++ main.go | 9 ++++++++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4796f61..997dea2 100644 --- a/README.md +++ b/README.md @@ -32,11 +32,16 @@ Larry Benwater ``` ## Usage -The easiest way to use this is copy and paste the desired changelog list from [https://raw.githubusercontent.com/VATSIM-UK/UK-Sector-File/main/.github/CHANGELOG.md](https://raw.githubusercontent.com/VATSIM-UK/UK-Sector-File/main/.github/CHANGELOG.md) into a `changelog.md` file locally, and just run with `./UKSFCG` +There are two ways to use this program: +- Locally - copy and paste the desired changelog list from [https://raw.githubusercontent.com/VATSIM-UK/UK-Sector-File/main/.github/CHANGELOG.md](https://raw.githubusercontent.com/VATSIM-UK/UK-Sector-File/main/.github/CHANGELOG.md) into a `changelog.md` file locally, and just run with `./UKSFCG` +- Online - run the program using `./UKSFCG --url`, which will read from the default URL specified below Flags: - `--in` - sets the input file, optional, default `changelog.md` - `--out` - sets the output file, optional, default `output.txt` +- `--url` - sets the url, optional, if `--url` is present but empty then it defaults to `https://raw.githubusercontent.com/VATSIM-UK/UK-Sector-File/main/.github/CHANGELOG.md` + +The `--url` flag takes precedence over `--in`, so if both are specified, then it will read from online. ## Limitations - If a contributor has been added in the format `- thanks to @John (John Smith) and Smith John`, Smith John would not be on the contributors list diff --git a/go.mod b/go.mod index 5fcaa39..c347f86 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,8 @@ require github.com/stretchr/testify v1.8.1 require ( github.com/davecgh/go-spew v1.1.1 // indirect + github.com/jessevdk/go-flags v1.5.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 2ec90f7..89b2701 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc= +github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -10,6 +12,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4 h1:EZ2mChiOa8udjfp6rRmswTbtZN/QzUQp4ptM4rnjHvc= +golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go index 956a7d7..9574c73 100644 --- a/main.go +++ b/main.go @@ -98,9 +98,16 @@ func GetWebChangelog(urls string) []byte { func GetChanges(filebytes []byte) []string { changes := []string{} split := strings.Split(string(filebytes), "\n") // split the document into newlines + airacnumbers := 0 numberReComp := regexp.MustCompile(numberRe) for _, s := range split { - b := numberReComp.MatchString(s) // ensures that it isn't the AIRAC title + if airacnumbers >= 2 { + break // if we go through multiple AIRACs then stop + } + if strings.Contains(s, "#") { + airacnumbers = airacnumbers + 1 + } + b := numberReComp.MatchString(s) // only match changelog entries if b { s = numberReComp.ReplaceAllString(s, "") // removes the number from the start changes = append(changes, s)