improve command information

Signed-off-by: Nathan13888 <29968201+Nathan13888@users.noreply.github.com>
This commit is contained in:
Nathan Chung 2023-12-17 02:27:10 -05:00
parent 090b821096
commit d5bd33bb77
Signed by: n4chung
SSH Key Fingerprint: SHA256:/+NqYA5MfQIjjfwa4z16mw3Y+lxgY/Ml8wCeGnh6qBU
1 changed files with 52 additions and 11 deletions

63
main.go
View File

@ -72,12 +72,34 @@ func main() {
log.Info().Msg("Listing supported projects")
checkers := checkers.SupportedProjects
for _, c := range checkers {
projects := checkers.SupportedProjects
for _, proj := range projects {
status := "supported"
// TODO: check if enabled
// check if project is in enabled list
// TODO: ...
log.Info().Str("project", c.Name).Str("status", status).Msg("Supported project.")
// supported checkers
var checkers []string
for _, c := range proj.Checkers {
checkers = append(checkers, c.Name)
}
log.Info().Str("project", proj.Name).
Str("status", status).
Strs("checkers", checkers).
Msg("Supported project.")
// list configs
log.Info().
Str("project", proj.Name).
Int("num_checkers", proj.NumOfCheckers).
Time("out_of_sync_since", proj.Properties.OOSSince).
Int64("out_of_sync_interval", proj.Properties.OOSInterval).
Str("csc", proj.Properties.CSC).
Strs("mirrors", proj.Properties.Mirrors).
Str("upstream", proj.Properties.Upstream).
Str("file", proj.Properties.File).
Msg("Found project config.")
}
return nil
@ -87,15 +109,31 @@ func main() {
Name: "check",
Aliases: []string{"c"},
Usage: "checks particular mirror (once)",
// TODO: check --all flag
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "all",
Aliases: []string{"a"},
Usage: "check all (supported) mirrors",
Value: false,
},
},
Action: func(cCtx *cli.Context) error {
checkers.LoadDefaultProjects()
loadConfig()
// attempt to look up and check all projects
projects := cCtx.Args().Slice()
if len(projects) == 0 {
log.Fatal().Msg("No projects specified.")
var projects []string
if cCtx.Bool("all") {
// iterate through all supported projects and add names
for _, proj := range checkers.SupportedProjects {
projects = append(projects, proj.Name)
}
} else {
projects = cCtx.Args().Slice()
if len(projects) == 0 {
log.Fatal().Msg("No projects specified.")
}
}
checkers.StartWorkers()
@ -127,20 +165,23 @@ func main() {
// })
if err != nil {
// code is shit whoopsies
log.Fatal().Err(err).Msg("Failed to check project.")
}
status := <-*res.FinalStatus
if status == checkers.CHECKER_ERROR {
log.Fatal().Err(err).Msg("Failed to check project.")
log.Error().Err(err).
Str("project", arg).
Msg("Failed to check project.")
continue
}
if status == checkers.CHECKER_FAIL {
// exit with non-zero status
log.Error().Str("final_status", string(status)).
Str("project", arg).
Msg("Error found when checking project.")
os.Exit(1)
continue
}
log.Info().Str("final_status", string(status)).