func usageForCommandGroup(commandGroup common.CommandGroup, includeFlags bool) { say.Fprintln(os.Stderr, 0, "%s - %s", say.Cyan(commandGroup.Name), say.LightGray(commandGroup.Description)) say.Fprintln(os.Stderr, 0, strings.Repeat("-", len(commandGroup.Name)+3+len(commandGroup.Description))) for _, command := range commandGroup.Commands { usageForCommand(1, command, includeFlags) } }
func usage(commandGroups []common.CommandGroup) { if len(os.Args) > 2 { matcher := strings.ToLower(os.Args[2]) for _, commandGroup := range commandGroups { if strings.HasPrefix(strings.ToLower(commandGroup.Name), matcher) { usageForCommandGroup(commandGroup, true) return } for _, command := range commandGroup.Commands { if strings.HasPrefix(strings.ToLower(command.Name), matcher) { usageForCommand(0, command, true) return } } } say.Fprintln(os.Stderr, 0, say.Red("Unkown command: %s", os.Args[2])) } say.Fprintln(os.Stderr, 0, "%s", say.Cyan("Help and Autocompletion")) say.Fprintln(os.Stderr, 0, strings.Repeat("-", len("Help and Autocompletion"))) say.Fprintln(os.Stderr, 1, "%s %s", say.Green("help"), say.LightGray("[command] - Show this help, or detailed help for the passed in command")) say.Fprintln(os.Stderr, 1, "%s %s", say.Green("completions"), say.LightGray("Generate BASH Completions for veritas")) say.Fprintln(os.Stderr, 0, "") for _, commandGroup := range commandGroups { usageForCommandGroup(commandGroup, false) say.Println(0, "") } }
func RepState(out io.Writer) (err error) { client := rep.NewClient(&http.Client{ Timeout: 5 * time.Second, }, "http://localhost:1800") t := time.Now() state, err := client.State() dt := time.Since(t) if err != nil { say.Println(0, "Cell State [%s] - Error:%s", dt, say.Red(err.Error())) return err } name := say.Green("Cell State") if state.Evacuating { name = say.Red("Cell State - EVAC -") } rootFSes := []string{} for key := range state.RootFSProviders { if key != "preloaded" { rootFSes = append(rootFSes, say.Yellow(key)) } } for key := range state.RootFSProviders["preloaded"].(rep.FixedSetRootFSProvider).FixedSet { rootFSes = append(rootFSes, say.Green("preloaded:%s", key)) } say.Println(0, "%s [%s] - Zone:%s | %s Tasks, %s LRPs | C:%d/%d M:%d/%d D:%d/%d | %s", name, dt, say.Cyan(state.Zone), say.Cyan("%d", len(state.Tasks)), say.Cyan("%d", len(state.LRPs)), state.AvailableResources.Containers, state.TotalResources.Containers, state.AvailableResources.MemoryMB, state.TotalResources.MemoryMB, state.AvailableResources.DiskMB, state.TotalResources.DiskMB, strings.Join(rootFSes, ", "), ) return nil }
func printTask(task *models.Task) { privileged := "" if task.Privileged { privileged = say.Red(" PRIVILEGED") } say.Println(1, "%s [%s on %s %s%s] U:%s C:%s (%d MB, %d MB, %d CPU)", taskState(task), task.TaskGuid, task.CellId, say.Cyan(task.RootFs), privileged, time.Since(time.Unix(0, task.UpdatedAt)).String(), time.Since(time.Unix(0, task.CreatedAt)).String(), task.MemoryMb, task.DiskMb, task.CpuWeight, ) }
func printLRP(lrp *veritas_models.VeritasLRP) { say.Println(1, say.Green(lrp.ProcessGuid)) if lrp.DesiredLRP.GetProcessGuid() != "" { privileged := "" if lrp.DesiredLRP.Privileged { privileged = say.Red(" PRIVILEGED") } routesString := routes(lrp.DesiredLRP.Routes) if routesString != "" { routesString = "\n" + say.Indent(1, routesString) } say.Println( 2, "%s %s%s (%d MB, %d MB, %d CPU)%s", say.Green("%d", lrp.DesiredLRP.Instances), say.Cyan(lrp.DesiredLRP.RootFs), privileged, lrp.DesiredLRP.MemoryMb, lrp.DesiredLRP.DiskMb, lrp.DesiredLRP.CpuWeight, routesString, ) } else { say.Println(2, say.Red("UNDESIRED")) } orderedActualIndices := lrp.OrderedActualLRPIndices() for _, index := range orderedActualIndices { actualLRPGroup := lrp.ActualLRPGroupsByIndex[index] if instance := actualLRPGroup.Instance; instance != nil { if instance.State == models.ActualLRPStateUnclaimed || instance.State == models.ActualLRPStateCrashed { say.Println( 3, "%2s: [%s for %s]", index, actualState(instance), time.Since(time.Unix(0, instance.Since)), ) } else { say.Println( 3, "%2s: %s %s [%s for %s]", index, instance.InstanceGuid, say.Yellow(instance.CellId), actualState(instance), time.Since(time.Unix(0, instance.Since)), ) } } if evacuating := actualLRPGroup.Evacuating; evacuating != nil { say.Println( 3, "%s: %s %s [%s for %s] - %s", say.Red("%2s", index), say.Red(evacuating.InstanceGuid), say.Yellow(evacuating.CellId), actualState(evacuating), time.Since(time.Unix(0, evacuating.Since)), say.Red("EVACUATING"), ) } } }