ARO-RP/cmd/aro/main.go

72 строки
1.2 KiB
Go
Исходник Обычный вид История

2019-12-22 20:47:29 +03:00
package main
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
import (
"context"
2020-01-21 05:57:53 +03:00
"flag"
"fmt"
"math/rand"
2019-12-22 20:47:29 +03:00
"os"
"strings"
"time"
2019-12-22 20:47:29 +03:00
utillog "github.com/Azure/ARO-RP/pkg/util/log"
)
var (
gitCommit = "unknown"
)
2020-01-21 05:57:53 +03:00
func usage() {
2020-03-22 07:35:17 +03:00
fmt.Fprint(flag.CommandLine.Output(), "usage:\n")
fmt.Fprintf(flag.CommandLine.Output(), " %s deploy config.yaml location\n", os.Args[0])
fmt.Fprintf(flag.CommandLine.Output(), " %s mirror\n", os.Args[0])
fmt.Fprintf(flag.CommandLine.Output(), " %s monitor\n", os.Args[0])
fmt.Fprintf(flag.CommandLine.Output(), " %s rp\n", os.Args[0])
2020-01-21 05:57:53 +03:00
flag.PrintDefaults()
}
2019-12-22 20:47:29 +03:00
func main() {
rand.Seed(time.Now().UnixNano())
2020-01-21 05:57:53 +03:00
flag.Usage = usage
flag.Parse()
2020-01-19 02:46:58 +03:00
ctx := context.Background()
2019-12-22 20:47:29 +03:00
log := utillog.GetLogger()
log.Printf("starting, git commit %s", gitCommit)
var err error
2020-03-05 05:02:28 +03:00
switch strings.ToLower(flag.Arg(0)) {
2019-12-22 20:47:29 +03:00
case "mirror":
2020-03-06 13:28:05 +03:00
checkArgs(1)
2020-01-19 02:46:58 +03:00
err = mirror(ctx, log)
case "monitor":
2020-03-06 13:28:05 +03:00
checkArgs(1)
2020-01-19 02:46:58 +03:00
err = monitor(ctx, log)
2019-12-22 20:47:29 +03:00
case "rp":
2020-03-06 13:28:05 +03:00
checkArgs(1)
2020-01-19 02:46:58 +03:00
err = rp(ctx, log)
2020-03-02 16:10:46 +03:00
case "deploy":
2020-03-06 13:28:05 +03:00
checkArgs(3)
2020-03-02 16:10:46 +03:00
err = deploy(ctx, log)
2020-01-19 02:46:58 +03:00
default:
usage()
os.Exit(2)
2019-12-22 20:47:29 +03:00
}
if err != nil {
log.Fatal(err)
}
}
2020-03-06 13:28:05 +03:00
func checkArgs(required int) {
if len(flag.Args()) != required {
usage()
os.Exit(2)
}
}