39 lines
667 B
Go
39 lines
667 B
Go
package main
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"os"
|
||
|
|
|
||
|
|
"github.com/StevanFreeborn/gator/internal/command"
|
||
|
|
"github.com/StevanFreeborn/gator/internal/config"
|
||
|
|
"github.com/StevanFreeborn/gator/internal/state"
|
||
|
|
)
|
||
|
|
|
||
|
|
func main() {
|
||
|
|
if len(os.Args) < 2 {
|
||
|
|
fmt.Println("Not enough arguments provided. Usage: <command> <args>")
|
||
|
|
os.Exit(1)
|
||
|
|
}
|
||
|
|
|
||
|
|
c, err := config.Read()
|
||
|
|
|
||
|
|
if err != nil {
|
||
|
|
fmt.Printf("Error reading config file: %s", err)
|
||
|
|
}
|
||
|
|
|
||
|
|
cmd := os.Args[1]
|
||
|
|
args := os.Args[2:]
|
||
|
|
|
||
|
|
s := state.NewState(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(0)
|
||
|
|
}
|