Пример #1
0
func stepList(c *cli.Context) error {
	// Input validation
	stepLibURIs := []string{}
	stepLibURI := c.String(CollectionKey)
	if stepLibURI == "" {
		stepLibURIs = stepman.GetAllStepCollectionPath()
	} else {
		stepLibURIs = []string{stepLibURI}
	}

	format := c.String(FormatKey)
	if format == "" {
		format = OutputFormatRaw
	} else if !(format == OutputFormatRaw || format == OutputFormatJSON) {
		log.Fatalf("Invalid format: %s", format)
	}

	for _, URI := range stepLibURIs {
		if err := listSteps(URI, format); err != nil {
			log.Errorf("Failed to list steps in StepLib (%s), err: %s", URI, err)
		}
	}

	return nil
}
Пример #2
0
func update(c *cli.Context) error {
	collectionURIs := []string{}

	// StepSpec collection path
	collectionURI := c.String(CollectionKey)
	if collectionURI == "" {
		log.Info("No StepLib specified, update all...")
		collectionURIs = stepman.GetAllStepCollectionPath()
	} else {
		collectionURIs = []string{collectionURI}
	}

	if len(collectionURIs) == 0 {
		log.Info("No local StepLib found, nothing to update...")
	}

	for _, URI := range collectionURIs {
		log.Infof("Update StepLib (%s)...", URI)
		if _, err := updateCollection(URI); err != nil {
			return fmt.Errorf("Failed to update StepLib (%s), error: %s", URI, err)
		}
	}

	return nil
}
Пример #3
0
func update(c *cli.Context) {
	log.Info("[STEPMAN] - Update")

	collectionURIs := []string{}

	// StepSpec collection path
	collectionURI := c.String(CollectionKey)
	if collectionURI == "" {
		log.Info("[STEPMAN] - No step collection specified, update all")
		collectionURIs = stepman.GetAllStepCollectionPath()
	} else {
		collectionURIs = []string{collectionURI}
	}

	for _, URI := range collectionURIs {
		if _, err := updateCollection(URI); err != nil {
			log.Fatalf("Failed to update collection (%s), err: %s", collectionURI, err)
		}
	}

	log.Info("[STEPMAN] - Updated")
}
Пример #4
0
func stepInfo(c *cli.Context) {
	// Input validation
	format := c.String(FormatKey)
	collectionURI := c.String(CollectionKey)
	YMLPath := c.String(StepYMLKey)
	isShort := c.Bool(ShortKey)
	id := c.String(IDKey)
	version := c.String(VersionKey)

	if format == "" {
		format = OutputFormatRaw
	} else if !(format == OutputFormatRaw || format == OutputFormatJSON) {
		log.Fatalf("Invalid format: %s", format)
	}

	if YMLPath != "" {
		//
		// Local step info
		step, err := stepman.ParseStepYml(YMLPath, false)
		if err != nil {
			log.Fatalf("Failed to parse step.yml (path:%s), err: %s", YMLPath, err)
		}

		inputs, err := getEnvInfos(step.Inputs)
		if err != nil {
			log.Fatalf("Failed to get step (path:%s) input infos, err: %s", YMLPath, err)
		}

		outputs, err := getEnvInfos(step.Outputs)
		if err != nil {
			log.Fatalf("Failed to get step (path:%s) output infos, err: %s", YMLPath, err)
		}

		stepInfo := models.StepInfoModel{
			StepLib:     YMLPath,
			Description: *step.Description,
			Source:      *step.SourceCodeURL,
			Inputs:      inputs,
			Outputs:     outputs,
		}

		if err := printStepInfo(stepInfo, format, isShort, true); err != nil {
			log.Fatalf("Failed to print step info, err: %s", err)
		}
	} else {
		//
		// StepLib step info

		// Input validation
		collectionURIs := []string{}
		if collectionURI == "" {
			collectionURIs = stepman.GetAllStepCollectionPath()
		} else {
			collectionURIs = []string{collectionURI}
		}

		if id == "" {
			log.Fatal("Missing step id")
		}

		for _, collectionURI := range collectionURIs {
			// Check if setup was done for collection
			if exist, err := stepman.RootExistForCollection(collectionURI); err != nil {
				log.Fatalf("Failed to check if setup was done for steplib (%s), error: %s", collectionURI, err)
			} else if !exist {
				if err := setupSteplib(collectionURI, format != OutputFormatRaw); err != nil {
					log.Fatal("Failed to setup steplib")
				}
			}

			// Check if step exist in collection
			collection, err := stepman.ReadStepSpec(collectionURI)
			if err != nil {
				log.Fatalf("Failed to read steps spec (spec.json), err: %s", err)
			}

			step, stepFound := collection.GetStep(id, version)
			if !stepFound {
				if version == "" {
					log.Fatalf("Collection doesn't contain any version of step (id:%s)", id)
				} else {
					log.Fatalf("Collection doesn't contain step (id:%s) (version:%s)", id, version)
				}
			}

			latest, err := collection.GetLatestStepVersion(id)
			if err != nil {
				log.Fatalf("Failed to get latest version of step (id:%s)", id)
			}

			if version == "" {
				version = latest
			}

			inputs, err := getEnvInfos(step.Inputs)
			if err != nil {
				log.Fatalf("Failed to get step (id:%s) input infos, err: %s", id, err)
			}

			outputs, err := getEnvInfos(step.Outputs)
			if err != nil {
				log.Fatalf("Failed to get step (id:%s) output infos, err: %s", id, err)
			}

			stepInfo := models.StepInfoModel{
				ID:          id,
				Version:     version,
				Latest:      latest,
				Description: *step.Description,
				StepLib:     collectionURI,
				Source:      *step.SourceCodeURL,
				Inputs:      inputs,
				Outputs:     outputs,
			}

			route, found := stepman.ReadRoute(collectionURI)
			if !found {
				log.Fatalf("No route found for collection: %s", collectionURI)
			}
			globalStepInfoPth := stepman.GetStepGlobalInfoPath(route, id)
			if globalStepInfoPth != "" {
				globalInfo, found, err := stepman.ParseGlobalStepInfoYML(globalStepInfoPth)
				if err != nil {
					log.Fatalf("Failed to get step (path:%s) output infos, err: %s", YMLPath, err)
				}

				if found {
					stepInfo.GlobalInfo = globalInfo
				}
			}

			if err := printStepInfo(stepInfo, format, isShort, false); err != nil {
				log.Fatalf("Failed to print step info, err: %s", err)
			}
		}
	}
}