feat: implemented many commands
- added register command - added reset command - added users command - added agg command - added feeds command
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/StevanFreeborn/gator/internal/command"
|
||||
"github.com/StevanFreeborn/gator/internal/config"
|
||||
"github.com/StevanFreeborn/gator/internal/database"
|
||||
"github.com/StevanFreeborn/gator/internal/state"
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -19,19 +22,28 @@ func main() {
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Error reading config file: %s", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
db, err := sql.Open("postgres", c.DbUrl)
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Error connecting to database: %s", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
cmd := os.Args[1]
|
||||
args := os.Args[2:]
|
||||
|
||||
s := state.NewState(c, args)
|
||||
dbQueries := database.New(db)
|
||||
s := state.NewState(dbQueries, c, args)
|
||||
|
||||
registry := command.NewRegistry()
|
||||
err = registry.RunCommand(cmd, s)
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Error running '%s' command: %s\n", cmd, err)
|
||||
os.Exit(2)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
|
||||
Reference in New Issue
Block a user