Skip to content

Explicitly make zip preamble options mutually exclusive #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"slices"

"github.com/peterebden/go-cli-init/v5/flags"
"github.com/peterebden/go-cli-init/v5/logging"
Expand All @@ -31,6 +32,20 @@ var javaExcludePrefixes = []string{

var log = logging.MustGetLogger()

// countFunc returns the number of elements in s that satisfy f.
func countFunc[S []E, E comparable](s S, f func(e E) bool) int {
var n int
for {
i := slices.IndexFunc(s, f)
if i == -1 {
break
}
n++
s = s[i+1:]
}
return n
}

func must(err error) {
if err != nil {
log.Fatalf("%s", err)
Expand Down Expand Up @@ -179,6 +194,14 @@ func main() {
os.Exit(0)
}

if countFunc([]string{
opts.Zip.Preamble,
opts.Zip.PreambleFrom,
opts.Zip.PreambleFile,
}, func(s string) bool { return s != "" }) > 1 {
log.Fatal("Only one of --preamble, --preamble_from or --preamble_file may be specified.")
}

if opts.Zip.ExcludeJavaPrefixes {
opts.Zip.ExcludeInternalPrefix = javaExcludePrefixes
}
Expand Down
Loading