func printJSONStepList(stepLibURI string, stepLib models.StepCollectionModel, isShort bool) error { stepList := models.StepListModel{ StepLib: stepLibURI, } for stepID := range stepLib.Steps { stepList.Steps = append(stepList.Steps, stepID) } bytes, err := json.Marshal(stepList) if err != nil { return err } fmt.Println(string(bytes)) return nil }
func listSteps(stepLibURI, format string) error { // Check if setup was done for collection if exist, err := stepman.RootExistForCollection(stepLibURI); err != nil { return err } else if !exist { if err := setupSteplib(stepLibURI, format != OutputFormatRaw); err != nil { log.Fatal("Failed to setup steplib") } } stepLib, err := stepman.ReadStepSpec(stepLibURI) if err != nil { return err } // List stepList := models.StepListModel{ StepLib: stepLibURI, } for stepID := range stepLib.Steps { stepList.Steps = append(stepList.Steps, stepID) } switch format { case OutputFormatRaw: printRawStepList(stepList, false) break case OutputFormatJSON: if err := printJSONStepList(stepList, false); err != nil { return err } break default: return fmt.Errorf("Invalid format: %s", format) } return nil }