func deleteStepLib(c *cli.Context) error { // Input validation collectionURI := c.String(CollectionKey) if collectionURI == "" { return fmt.Errorf("Missing required input: collection") } log.Infof("Delete StepLib: %s", collectionURI) route, found := stepman.ReadRoute(collectionURI) if !found { log.Warnf("No route found for collection: %s, cleaning up routing..", collectionURI) if err := stepman.CleanupDanglingLib(collectionURI); err != nil { log.Errorf("Error cleaning up lib: %s", collectionURI) } log.Infof("Call 'stepman setup -c %s' for a clean setup", collectionURI) return nil } if err := stepman.CleanupRoute(route); err != nil { return fmt.Errorf("Failed to cleanup route for StepLib: %s", collectionURI) } return nil }
func download(c *cli.Context) error { // Input validation collectionURI := c.String(CollectionKey) if collectionURI == "" { log.Fatalln("[STEPMAN] - No step collection specified") } route, found := stepman.ReadRoute(collectionURI) if !found { log.Fatal("No route found for lib: " + collectionURI) } id := c.String(IDKey) if id == "" { log.Fatal("[STEPMAN] - Missing step id") } collection, err := stepman.ReadStepSpec(collectionURI) if err != nil { log.Fatal("[STEPMAN] - Failed to read step spec:", err) } version := c.String(VersionKey) if version == "" { log.Debug("[STEPMAN] - Missing step version -- Use latest version") latest, err := collection.GetLatestStepVersion(id) if err != nil { log.Fatal("[STEPMAN] - Failed to get step latest version: ", err) } log.Debug("[STEPMAN] - Latest version of step: ", latest) version = latest } update := c.Bool(UpdateKey) // Check step exist in collection step, found := collection.GetStep(id, version) if !found { if update { log.Infof("[STEPMAN] - Collection doesn't contain step (id:%s) (version:%s) -- Updating collection", id, version) if err := stepman.ReGenerateStepSpec(route); err != nil { log.Fatalf("[STEPMAN] - Failed to update collection:%s error:%v", collectionURI, err) } if _, found := collection.GetStep(id, version); !found { log.Fatalf("[STEPMAN] - Even the updated collection doesn't contain step (id:%s) (version:%s)", id, version) } } else { log.Fatalf("[STEPMAN] - Collection doesn't contain step (id:%s) (version:%s)", id, version) } } if err := stepman.DownloadStep(collectionURI, collection, id, version, step.Source.Commit); err != nil { log.Fatal("[STEPMAN] - Failed to download step") } return nil }
func setup(c *cli.Context) error { log.Debug("Setup") // Input validation steplibURI := c.String(CollectionKey) if steplibURI == "" { log.Fatal("No step collection specified") } copySpecJSONPath := c.String(CopySpecJSONKey) if c.IsSet(LocalCollectionKey) { log.Warn("'local' flag is deprecated") log.Warn("use 'file://' prefix in steplib path instead") fmt.Println() } if c.Bool(LocalCollectionKey) { if !strings.HasPrefix(steplibURI, "file://") { log.Warnf("Appending file path prefix (file://) to StepLib (%s)", steplibURI) steplibURI = "file://" + steplibURI log.Warnf("From now you can refer to this StepLib with URI: %s", steplibURI) log.Warnf("For example, to delete StepLib call: `stepman delete --collection %s`", steplibURI) } } // Setup if err := setupSteplib(steplibURI, false); err != nil { log.Fatalf("Setup failed, error: %s", err) } // Copy spec.json if copySpecJSONPath != "" { log.Infof("Copying spec YML to path: %s", copySpecJSONPath) route, found := stepman.ReadRoute(steplibURI) if !found { log.Fatalf("No route found for steplib (%s)", steplibURI) } sourceSpecJSONPth := stepman.GetStepSpecPath(route) if err := cmdex.CopyFile(sourceSpecJSONPth, copySpecJSONPath); err != nil { log.Fatalf("Failed to copy spec.json from (%s) to (%s), error: %s", sourceSpecJSONPth, copySpecJSONPath, err) } } return nil }
func updateCollection(steplibSource string) (models.StepCollectionModel, error) { route, found := stepman.ReadRoute(steplibSource) if !found { log.Warnf("No route found for collection: %s, cleaning up routing..", steplibSource) if err := stepman.CleanupDanglingLib(steplibSource); err != nil { log.Errorf("Error cleaning up lib: %s", steplibSource) } log.Infof("Call 'stepman setup -c %s' for a clean setup", steplibSource) return models.StepCollectionModel{}, fmt.Errorf("No route found for StepLib: %s", steplibSource) } isLocalSteplib := strings.HasPrefix(steplibSource, "file://") if isLocalSteplib { if err := stepman.CleanupRoute(route); err != nil { return models.StepCollectionModel{}, fmt.Errorf("Failed to cleanup route for StepLib: %s", steplibSource) } if err := setupSteplib(steplibSource, false); err != nil { return models.StepCollectionModel{}, fmt.Errorf("Failed to setup StepLib: %s", steplibSource) } } else { pth := stepman.GetCollectionBaseDirPath(route) if exists, err := pathutil.IsPathExists(pth); err != nil { return models.StepCollectionModel{}, err } else if !exists { return models.StepCollectionModel{}, errors.New("Not initialized") } gitPullErr := retry.Times(2).Wait(3 * time.Second).Try(func(attempt uint) error { if attempt > 0 { log.Infoln("Retrying ...") } return cmdex.GitPull(pth) }) if gitPullErr != nil { return models.StepCollectionModel{}, fmt.Errorf("Failed to update StepLib git repository, error: %s", gitPullErr) } if err := stepman.ReGenerateStepSpec(route); err != nil { return models.StepCollectionModel{}, err } } return stepman.ReadStepSpec(steplibSource) }
func setup(c *cli.Context) { log.Debug("Setup") // Input validation steplibURI := c.String(CollectionKey) if steplibURI == "" { log.Fatal("No step collection specified") } copySpecJSONPath := c.String(CopySpecJSONKey) if c.IsSet(LocalCollectionKey) { log.Warn("'local' flag is deprecated") log.Warn("use 'file://' suffix in steplib path instead") fmt.Println() } if c.Bool(LocalCollectionKey) { if !strings.HasPrefix(steplibURI, "file://") { steplibURI = "file://" + steplibURI } } // Setup if err := setupSteplib(steplibURI, false); err != nil { log.Fatalf("Steup failed, error: %s", err) } // Copy spec.json if copySpecJSONPath != "" { log.Infof("Copying spec YML to path: %s", copySpecJSONPath) route, found := stepman.ReadRoute(steplibURI) if !found { log.Fatalf("No route found for steplib (%s)", steplibURI) } sourceSpecJSONPth := stepman.GetStepSpecPath(route) if err := cmdex.CopyFile(sourceSpecJSONPth, copySpecJSONPath); err != nil { log.Fatalf("Failed to copy spec.json from (%s) to (%s), error: %s", sourceSpecJSONPth, copySpecJSONPath, err) } } }
func shareAudit(c *cli.Context) { toolMode := c.Bool(ToolMode) share, err := ReadShareSteplibFromFile() if err != nil { log.Error(err) log.Fatal("You have to start sharing with `stepman share start`, or you can read instructions with `stepman share`") } _, found := stepman.ReadRoute(share.Collection) if !found { log.Fatalln("No route found for collectionURI (%s)", share.Collection) } if err := auditStepLibBeforeSharePullRequest(share.Collection); err != nil { log.Fatalf("Audit Step Collection failed, err: %s", err) } printFinishAudit(share, toolMode) }
func finish(c *cli.Context) error { share, err := ReadShareSteplibFromFile() if err != nil { log.Error(err) log.Fatal("You have to start sharing with `stepman share start`, or you can read instructions with `stepman share`") } route, found := stepman.ReadRoute(share.Collection) if !found { log.Fatalln("No route found for collectionURI (%s)", share.Collection) } collectionDir := stepman.GetCollectionBaseDirPath(route) if err := cmdex.GitCheckIsNoChanges(collectionDir); err == nil { log.Warn("No git changes!") printFinishShare() return nil } stepDirInSteplib := stepman.GetStepCollectionDirPath(route, share.StepID, share.StepTag) stepYMLPathInSteplib := stepDirInSteplib + "/step.yml" log.Info("New step.yml:", stepYMLPathInSteplib) if err := cmdex.GitAddFile(collectionDir, stepYMLPathInSteplib); err != nil { log.Fatal(err) } log.Info("Do commit") msg := share.StepID + " " + share.StepTag if err := cmdex.GitCommit(collectionDir, msg); err != nil { log.Fatal(err) } log.Info("Pushing to your fork: ", share.Collection) if err := cmdex.GitPushToOrigin(collectionDir, share.StepID); err != nil { log.Fatal(err) } printFinishShare() return nil }
func deleteCollection(c *cli.Context) { log.Debugln("[STEPMAN] - Delete collection") // Input validation collectionURI := c.String(CollectionKey) if collectionURI == "" { log.Fatalln("[STEPMAN] - No step collection specified") } route, found := stepman.ReadRoute(collectionURI) if !found { log.Warnf("No route found for collection: %s, cleaning up routing..", collectionURI) if err := stepman.CleanupDanglingLib(collectionURI); err != nil { log.Errorf("Error cleaning up lib: %s", collectionURI) } log.Infof("Call 'stepman setup -c %s' for a clean setup", collectionURI) return } if err := stepman.CleanupRoute(route); err != nil { log.Errorf("Failed to cleanup route for uri: %s", collectionURI) } }
func updateCollection(steplibSource string) (models.StepCollectionModel, error) { route, found := stepman.ReadRoute(steplibSource) if !found { return models.StepCollectionModel{}, fmt.Errorf("No collection found for lib, call 'stepman delete -c %s' for cleanup", steplibSource) } pth := stepman.GetCollectionBaseDirPath(route) if exists, err := pathutil.IsPathExists(pth); err != nil { return models.StepCollectionModel{}, err } else if !exists { return models.StepCollectionModel{}, errors.New("Not initialized") } if err := cmdex.GitPull(pth); err != nil { return models.StepCollectionModel{}, err } if err := stepman.ReGenerateStepSpec(route); err != nil { return models.StepCollectionModel{}, err } return stepman.ReadStepSpec(steplibSource) }
func stepInfo(c *cli.Context) error { // 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) { return fmt.Errorf("Invalid output format: %s", format) } if YMLPath == "" && collectionURI == "" { return fmt.Errorf("Missing required input: no StepLib, nor step.yml path defined as step info source") } if YMLPath != "" { // // Local step info step, err := stepman.ParseStepYml(YMLPath, false) if err != nil { return fmt.Errorf("Failed to parse step.yml (path:%s), err: %s", YMLPath, err) } inputs, err := getEnvInfos(step.Inputs) if err != nil { return fmt.Errorf("Failed to get step (path:%s) input infos, err: %s", YMLPath, err) } outputs, err := getEnvInfos(step.Outputs) if err != nil { return fmt.Errorf("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 { return fmt.Errorf("Failed to print step info, err: %s", err) } } else { // // StepLib step info // Input validation if id == "" { return errors.New("Missing required input: step id") } // Check if setup was done for collection if exist, err := stepman.RootExistForCollection(collectionURI); err != nil { return fmt.Errorf("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 { return errors.New("Failed to setup steplib") } } // Check if step exist in collection collection, err := stepman.ReadStepSpec(collectionURI) if err != nil { return fmt.Errorf("Failed to read steps spec (spec.json), err: %s", err) } step, stepFound := collection.GetStep(id, version) if !stepFound { if version == "" { return fmt.Errorf("Collection doesn't contain any version of step (id:%s)", id) } return fmt.Errorf("Collection doesn't contain step (id:%s) (version:%s)", id, version) } latest, err := collection.GetLatestStepVersion(id) if err != nil { return fmt.Errorf("Failed to get latest version of step (id:%s)", id) } if version == "" { version = latest } inputs, err := getEnvInfos(step.Inputs) if err != nil { return fmt.Errorf("Failed to get step (id:%s) input infos, err: %s", id, err) } outputs, err := getEnvInfos(step.Outputs) if err != nil { return fmt.Errorf("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 { return fmt.Errorf("No route found for collection: %s", collectionURI) } globalStepInfoPth := stepman.GetStepGlobalInfoPath(route, id) if globalStepInfoPth != "" { globalInfo, found, err := stepman.ParseGlobalStepInfoYML(globalStepInfoPth) if err != nil { return fmt.Errorf("Failed to get step (path:%s) output infos, err: %s", globalStepInfoPth, err) } if found { stepInfo.GlobalInfo = globalInfo } } if err := printStepInfo(stepInfo, format, isShort, false); err != nil { return fmt.Errorf("Failed to print step info, err: %s", err) } } return nil }
func create(c *cli.Context) error { toolMode := c.Bool(ToolMode) share, err := ReadShareSteplibFromFile() if err != nil { log.Error(err) log.Fatalln("You have to start sharing with `stepman share start`, or you can read instructions with `stepman share`") } // Input validation tag := c.String(TagKey) if tag == "" { log.Fatalln("No Step tag specified") } gitURI := c.String(GitKey) if gitURI == "" { log.Fatalln("No Step url specified") } stepID := c.String(StepIDKEy) if stepID == "" { stepID = getStepIDFromGit(gitURI) } if stepID == "" { log.Fatalln("No Step id specified") } r := regexp.MustCompile(`[a-z0-9-]+`) if find := r.FindString(stepID); find != stepID { log.Fatalln("StepID doesn't conforms to: [a-z0-9-]") } route, found := stepman.ReadRoute(share.Collection) if !found { log.Fatalf("No route found for collectionURI (%s)", share.Collection) } stepDirInSteplib := stepman.GetStepCollectionDirPath(route, stepID, tag) stepYMLPathInSteplib := path.Join(stepDirInSteplib, "step.yml") if exist, err := pathutil.IsPathExists(stepYMLPathInSteplib); err != nil { log.Fatalf("Failed to check step.yml path in steplib, err: %s", err) } else if exist { log.Warnf("Step already exist in path: %s.", stepDirInSteplib) if val, err := goinp.AskForBool("Would you like to overwrite local version of Step?"); err != nil { log.Fatalf("Failed to get bool, err: %s", err) } else { if !val { log.Errorln("Unfortunately we can't continue with sharing without an overwrite exist step.yml.") log.Fatalln("Please finish your changes, run this command again and allow it to overwrite the exist step.yml!") } } } // Clone Step to tmp dir tmp, err := pathutil.NormalizedOSTempDirPath("") if err != nil { log.Fatalf("Failed to get temp directory, err: %s", err) } log.Infof("Cloning Step from (%s) with tag (%s) to temporary path (%s)", gitURI, tag, tmp) if err := cmdex.GitCloneTag(gitURI, tmp, tag); err != nil { log.Fatalf("Git clone failed, err: %s", err) } // Update step.yml tmpStepYMLPath := path.Join(tmp, "step.yml") bytes, err := fileutil.ReadBytesFromFile(tmpStepYMLPath) if err != nil { log.Fatalf("Failed to read Step from file, err: %s", err) } var stepModel models.StepModel if err := yaml.Unmarshal(bytes, &stepModel); err != nil { log.Fatalf("Failed to unmarchal Step, err: %s", err) } commit, err := cmdex.GitGetCommitHashOfHEAD(tmp) if err != nil { log.Fatalf("Failed to get commit hash, err: %s", err) } stepModel.Source = &models.StepSourceModel{ Git: gitURI, Commit: commit, } stepModel.PublishedAt = pointers.NewTimePtr(time.Now()) // Validate step-yml if err := stepModel.Audit(); err != nil { log.Fatalf("Failed to validate Step, err: %s", err) } for _, input := range stepModel.Inputs { key, value, err := input.GetKeyValuePair() if err != nil { log.Fatalf("Failed to get Step input key-value pair, err: %s", err) } options, err := input.GetOptions() if err != nil { log.Fatalf("Failed to get Step input (%s) options, err: %s", key, err) } if len(options.ValueOptions) > 0 && value == "" { log.Warn("Step input with 'value_options', should contain default value!") log.Fatalf("Missing default value for Step input (%s).", key) } } if strings.Contains(*stepModel.Summary, "\n") { log.Warningln("Step summary should be one line!") } if utf8.RuneCountInString(*stepModel.Summary) > maxSummaryLength { log.Warningf("Step summary should contains maximum (%d) characters, actual: (%d)!", maxSummaryLength, utf8.RuneCountInString(*stepModel.Summary)) } // Copy step.yml to steplib share.StepID = stepID share.StepTag = tag if err := WriteShareSteplibToFile(share); err != nil { log.Fatalf("Failed to save share steplib to file, err: %s", err) } log.Info("Step dir in collection:", stepDirInSteplib) if exist, err := pathutil.IsPathExists(stepDirInSteplib); err != nil { log.Fatalf("Failed to check path (%s), err: %s", stepDirInSteplib, err) } else if !exist { if err := os.MkdirAll(stepDirInSteplib, 0777); err != nil { log.Fatalf("Failed to create path (%s), err: %s", stepDirInSteplib, err) } } log.Infof("Checkout branch: %s", share.ShareBranchName()) collectionDir := stepman.GetCollectionBaseDirPath(route) if err := cmdex.GitCheckout(collectionDir, share.ShareBranchName()); err != nil { if err := cmdex.GitCreateAndCheckoutBranch(collectionDir, share.ShareBranchName()); err != nil { log.Fatalf("Git failed to create and checkout branch, err: %s", err) } } stepBytes, err := yaml.Marshal(stepModel) if err != nil { log.Fatalf("Failed to marcshal Step model, err: %s", err) } if err := fileutil.WriteBytesToFile(stepYMLPathInSteplib, stepBytes); err != nil { log.Fatalf("Failed to write Step to file, err: %s", err) } // Update spec.json if err := stepman.ReGenerateStepSpec(route); err != nil { log.Fatalf("Failed to re-create steplib, err: %s", err) } printFinishCreate(share, stepDirInSteplib, toolMode) return nil }
func start(c *cli.Context) error { // Input validation toolMode := c.Bool(ToolMode) collectionURI := c.String(CollectionKey) if collectionURI == "" { log.Fatalln("[STEPMAN] - No step collection specified") } if route, found := stepman.ReadRoute(collectionURI); found { collLocalPth := stepman.GetCollectionBaseDirPath(route) log.Warnf("StepLib found locally at: %s", collLocalPth) log.Info("For sharing it's required to work with a clean StepLib repository.") if val, err := goinp.AskForBool("Would you like to remove the local version (your forked StepLib repository) and re-clone it?"); err != nil { log.Fatalln(err) } else { if !val { log.Errorln("Unfortunately we can't continue with sharing without a clean StepLib repository.") log.Fatalln("Please finish your changes, run this command again and allow it to remove the local StepLib folder!") } if err := stepman.CleanupRoute(route); err != nil { log.Errorf("Failed to cleanup route for uri: %s", collectionURI) } } } // cleanup if err := DeleteShareSteplibFile(); err != nil { log.Fatal(err) } var route stepman.SteplibRoute isSuccess := false defer func() { if !isSuccess { if err := stepman.CleanupRoute(route); err != nil { log.Errorf("Failed to cleanup route for uri: %s", collectionURI) } if err := DeleteShareSteplibFile(); err != nil { log.Fatal(err) } } }() // Preparing steplib alias := stepman.GenerateFolderAlias() route = stepman.SteplibRoute{ SteplibURI: collectionURI, FolderAlias: alias, } pth := stepman.GetCollectionBaseDirPath(route) if err := cmdex.GitClone(collectionURI, pth); err != nil { log.Fatal("[STEPMAN] - Failed to setup step spec:", err) } specPth := pth + "/steplib.yml" collection, err := stepman.ParseStepCollection(specPth) if err != nil { log.Fatal("[STEPMAN] - Failed to read step spec:", err) } if err := stepman.WriteStepSpecToFile(collection, route); err != nil { log.Fatal("[STEPMAN] - Failed to save step spec:", err) } if err := stepman.AddRoute(route); err != nil { log.Fatal("[STEPMAN] - Failed to setup routing:", err) } share := ShareModel{ Collection: collectionURI, } if err := WriteShareSteplibToFile(share); err != nil { log.Fatal("[STEPMAN] - Failed to save share steplib to file:", err) } isSuccess = true printFinishStart(pth, toolMode) return nil }
func activate(c *cli.Context) error { // Input validation collectionURI := c.String(CollectionKey) if collectionURI == "" { log.Fatalln("[STEPMAN] - No step collection specified") } id := c.String(IDKey) if id == "" { log.Fatal("[STEPMAN] - Missing step id") } path := c.String(PathKey) if path == "" { log.Fatal("[STEPMAN] - Missing destination path") } version := c.String(VersionKey) copyYML := c.String(CopyYMLKey) update := c.Bool(UpdateKey) // Check if step exist in collection collection, err := stepman.ReadStepSpec(collectionURI) if err != nil { log.Fatalln("[STEPMAN] - Failed to read steps spec (spec.json)") } _, stepFound := collection.GetStep(id, version) if !stepFound { if !update { if version == "" { log.Fatalf("[STEPMAN] - Collection doesn't contain any version of step (id:%s)", id) } else { log.Fatalf("[STEPMAN] - Collection doesn't contain step (id:%s) (version:%s)", id, version) } } if version == "" { log.Infof("[STEPMAN] - Collection doesn't contain any version of step (id:%s) -- Updating StepLib", id) } else { log.Infof("[STEPMAN] - Collection doesn't contain step (id:%s) (version:%s) -- Updating StepLib", id, version) } collection, err = updateCollection(collectionURI) if err != nil { log.Fatalf("Failed to update collection (%s), err: %s", collectionURI, err) } _, stepFound := collection.GetStep(id, version) if !stepFound { if version != "" { log.Fatalf("[STEPMAN] - Even the updated collection doesn't contain step (id:%s) (version:%s)", id, version) } else { log.Fatalf("[STEPMAN] - Even the updated collection doesn't contain any version of step (id:%s)", id) } } } // If version doesn't provided use latest if version == "" { log.Debug("[STEPMAN] - Missing step version -- Use latest version") latest, err := collection.GetLatestStepVersion(id) if err != nil { log.Fatal("[STEPMAN] - Failed to get step latest version: ", err) } log.Debug("[STEPMAN] - Latest version of step: ", latest) version = latest } // Check step exist in local cache step, found := collection.GetStep(id, version) if !found { log.Fatalf("[STEPMAN] - Collection doesn't contain step (id:%s) (version:%s)", id, version) } if step.Source == nil { log.Fatal("Invalid step, missing Source property") } route, found := stepman.ReadRoute(collectionURI) if !found { log.Fatalf("No route found for lib: %s", collectionURI) } stepCacheDir := stepman.GetStepCacheDirPath(route, id, version) if exist, err := pathutil.IsPathExists(stepCacheDir); err != nil { log.Fatal("[STEPMAN] - Failed to check path:", err) } else if !exist { log.Debug("[STEPMAN] - Step does not exist, download it") if err := stepman.DownloadStep(collectionURI, collection, id, version, step.Source.Commit); err != nil { log.Fatal("[STEPMAN] - Failed to download step:", err) } } // Copy to specified path srcFolder := stepCacheDir destFolder := path if exist, err := pathutil.IsPathExists(destFolder); err != nil { log.Fatalln("[STEPMAN] - Failed to check path:", err) } else if !exist { if err := os.MkdirAll(destFolder, 0777); err != nil { log.Fatalln("[STEPMAN] - Failed to create path:", err) } } if err = cmdex.CopyDir(srcFolder+"/", destFolder, true); err != nil { log.Fatalln("[STEPMAN] - Failed to copy step:", err) } // Copy step.yml to specified path if copyYML != "" { if exist, err := pathutil.IsPathExists(copyYML); err != nil { log.Fatalln("[STEPMAN] - Failed to check path:", err) } else if exist { log.Fatalln("[STEPMAN] - Copy yml destination path exist") } stepCollectionDir := stepman.GetStepCollectionDirPath(route, id, version) stepYMLSrc := stepCollectionDir + "/step.yml" if err = cmdex.CopyFile(stepYMLSrc, copyYML); err != nil { log.Fatalln("[STEPMAN] - Failed to copy step.yml:", err) } } return nil }
func stepInfo(c *cli.Context) error { // 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) { return fmt.Errorf("Invalid output format: %s", format) } if YMLPath == "" && collectionURI == "" { return fmt.Errorf("Missing required input: no StepLib, nor step.yml path defined as step info source") } if YMLPath != "" { // // Local step info step, err := stepman.ParseStepYml(YMLPath, false) if err != nil { return fmt.Errorf("Failed to parse step.yml (path:%s), err: %s", YMLPath, err) } inputs, err := getEnvInfos(step.Inputs) if err != nil { return fmt.Errorf("Failed to get step (path:%s) input infos, err: %s", YMLPath, err) } outputs, err := getEnvInfos(step.Outputs) if err != nil { return fmt.Errorf("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 { return fmt.Errorf("Failed to print step info, err: %s", err) } } else { // // StepLib step info stepVersion, err := ReadStepInfo(collectionURI, id, version, true, format != OutputFormatRaw) if err != nil { return fmt.Errorf("Failed to read Step information, error: %s", err) } if version == "" { version = stepVersion.Version } step := stepVersion.Step inputs, err := getEnvInfos(step.Inputs) if err != nil { return fmt.Errorf("Failed to get step (id:%s) input infos, err: %s", id, err) } outputs, err := getEnvInfos(step.Outputs) if err != nil { return fmt.Errorf("Failed to get step (id:%s) output infos, err: %s", id, err) } stepInfo := models.StepInfoModel{ ID: id, Version: version, Latest: stepVersion.LatestAvailableVersion, Description: *step.Description, StepLib: collectionURI, Source: *step.SourceCodeURL, Inputs: inputs, Outputs: outputs, } route, found := stepman.ReadRoute(collectionURI) if !found { return fmt.Errorf("No route found for collection: %s", collectionURI) } globalStepInfoPth := stepman.GetStepGlobalInfoPath(route, id) if globalStepInfoPth != "" { globalInfo, found, err := stepman.ParseGlobalStepInfoYML(globalStepInfoPth) if err != nil { return fmt.Errorf("Failed to get step (path:%s) output infos, err: %s", globalStepInfoPth, err) } if found { stepInfo.GlobalInfo = globalInfo } } if err := printStepInfo(stepInfo, format, isShort, false); err != nil { return fmt.Errorf("Failed to print step info, err: %s", err) } } return nil }