From 36d0eacf8fabf37807163c20e4b38baaa14ab960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20=C3=85hall?= Date: Tue, 23 Apr 2024 20:24:40 +0200 Subject: [PATCH] Added -list option --- flag.go | 7 +++++++ main.go | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/flag.go b/flag.go index 1689d95..8783efb 100644 --- a/flag.go +++ b/flag.go @@ -20,12 +20,14 @@ func (i *arrayFlags) Set(value string) error { var ( flagVersion bool + flagList bool flagIncludeAll bool flagExcludeAll bool flagExcept arrayFlags ) func init() { + flag.BoolVar(&flagList, "list", false, "Only list database names.") flag.BoolVar(&flagVersion, "version", false, "Prints version and exits.") flag.BoolVar(&flagIncludeAll, "include-all", false, "Split out all databases, with provided exceptions.") flag.BoolVar(&flagExcludeAll, "exclude-all", false, "Split out no databases, with provided exceptions.") @@ -37,6 +39,11 @@ func init() { os.Exit(0) } + if flagList && (flagIncludeAll || flagExcludeAll || len(flagExcept) > 0) { + fmt.Println("-list is not usable with any other flag.") + os.Exit(1) + } + if flagIncludeAll && flagExcludeAll { fmt.Println("-include-all and -exclude-all are mutually exclusive") os.Exit(1) diff --git a/main.go b/main.go index 929bbc1..fbebdb6 100644 --- a/main.go +++ b/main.go @@ -75,11 +75,11 @@ func main() { } } - if db.IsOpen() { + if !flagList && db.IsOpen() { db.Write(line) } - if dbDone.MatchString(line) { + if !flagList && dbDone.MatchString(line) { db.Completed = true db.Close() prevDb = db