Better handling of list, bumped to v4
This commit is contained in:
parent
77260743a0
commit
01e4588bf7
17
main.go
17
main.go
@ -9,7 +9,7 @@ import (
|
|||||||
"slices"
|
"slices"
|
||||||
)
|
)
|
||||||
|
|
||||||
const VERSION = "v3"
|
const VERSION = "v4"
|
||||||
const MAXLINE = 1048576
|
const MAXLINE = 1048576
|
||||||
|
|
||||||
type Db struct {
|
type Db struct {
|
||||||
@ -18,10 +18,12 @@ type Db struct {
|
|||||||
file *os.File
|
file *os.File
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDb(name string) (db Db, err error) {
|
func NewDb(name string) (db Db) {
|
||||||
db.Name = name
|
db.Name = name
|
||||||
fmt.Printf("Database %s\n", db.Name)
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *Db) Open() (err error) {
|
||||||
db.file, err = os.OpenFile(
|
db.file, err = os.OpenFile(
|
||||||
db.Name+".sql",
|
db.Name+".sql",
|
||||||
os.O_CREATE|os.O_WRONLY|os.O_TRUNC,
|
os.O_CREATE|os.O_WRONLY|os.O_TRUNC,
|
||||||
@ -64,12 +66,17 @@ func main() {
|
|||||||
prevDb.Close()
|
prevDb.Close()
|
||||||
|
|
||||||
dbName := dbMatch[1]
|
dbName := dbMatch[1]
|
||||||
|
db = NewDb(dbName)
|
||||||
if (flagIncludeAll && slices.Contains(flagExcept, dbName)) || (flagExcludeAll && !slices.Contains(flagExcept, dbName)) {
|
if (flagIncludeAll && slices.Contains(flagExcept, dbName)) || (flagExcludeAll && !slices.Contains(flagExcept, dbName)) {
|
||||||
fmt.Printf("Skipping %s\n", dbName)
|
fmt.Printf("Skipping %s\n", dbName)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if db, err = NewDb(dbName); err != nil {
|
fmt.Printf("Database %s\n", db.Name)
|
||||||
|
if flagList {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err = db.Open(); err != nil {
|
||||||
fmt.Printf("%s: %s\n", dbName, err)
|
fmt.Printf("%s: %s\n", dbName, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
@ -79,7 +86,7 @@ func main() {
|
|||||||
db.Write(line)
|
db.Write(line)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !flagList && dbDone.MatchString(line) {
|
if dbDone.MatchString(line) {
|
||||||
db.Completed = true
|
db.Completed = true
|
||||||
db.Close()
|
db.Close()
|
||||||
prevDb = db
|
prevDb = db
|
||||||
|
Loading…
Reference in New Issue
Block a user