package main import ( "fmt" "os" Ipam "utils/ipam" "utils/networks" "utils/routers" ) func main() { if len(os.Args) != 3 { _, _ = fmt.Fprintf(os.Stderr, "Usage: %s IPAM-FILE PICTURE\n", os.Args[0]) os.Exit(1) } ipam, err := loadIpam() if err != nil { return } if os.Args[1] == "networks" { err = networks.RunNetworks(ipam) } else if os.Args[1] == "routers" { err = routers.RunRouters(ipam) } else { _, _ = fmt.Fprintf(os.Stderr, "Unknown command: %s\n", os.Args[2]) os.Exit(1) } if err != nil { _, _ = fmt.Fprintf(os.Stderr, "%v\n", err) os.Exit(1) } } func loadIpam() (*Ipam.Ipam, error) { ipamYaml := os.Args[2] bs, err := os.ReadFile(ipamYaml) if err != nil { return nil, err } ipam, err := Ipam.LoadIpam(bs) if err != nil { return nil, err } return ipam, nil }