Exemplo n.º 1
0
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
}
Exemplo n.º 2
0
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)
}
Exemplo n.º 3
0
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)
	}
}
Exemplo n.º 4
0
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
}
Exemplo n.º 5
0
func setupSteplib(steplibURI string, silent bool) error {
	logger := output.NewLogger(silent)

	if exist, err := stepman.RootExistForCollection(steplibURI); err != nil {
		return fmt.Errorf("Failed to check if routing exist for steplib (%s), error: %s", steplibURI, err)
	} else if exist {

		logger.Debugf("Steplib (%s) already initialized, ready to use", steplibURI)
		return nil
	}

	alias := stepman.GenerateFolderAlias()
	route := stepman.SteplibRoute{
		SteplibURI:  steplibURI,
		FolderAlias: alias,
	}

	// Cleanup
	isSuccess := false
	defer func() {
		if !isSuccess {
			if err := stepman.CleanupRoute(route); err != nil {
				logger.Errorf("Failed to cleanup routing for steplib (%s), error: %s", steplibURI, err)
			}
		}
	}()

	// Setup
	isLocalSteplib := strings.HasPrefix(steplibURI, "file://")

	pth := stepman.GetCollectionBaseDirPath(route)
	if !isLocalSteplib {
		if out, err := gitClone(steplibURI, pth); err != nil {
			return fmt.Errorf("Failed to setup steplib (%s), output: %s, error: %s", steplibURI, out, err)
		}
	} else {
		// Local spec path
		logger.Warn("Using local steplib")
		logger.Infof("Creating steplib dir: %s", pth)

		if err := os.MkdirAll(pth, 0777); err != nil {
			return fmt.Errorf("Failed to create steplib dir (%s), error: %s", pth, err)
		}

		logger.Info("Collection dir created - OK")
		if err := cmdex.CopyDir(steplibURI, pth, true); err != nil {
			return fmt.Errorf("Failed to setup local step spec:", err)
		}
	}

	if err := stepman.ReGenerateStepSpec(route); err != nil {
		return fmt.Errorf("Failed to re-generate steplib (%s), error: %s", steplibURI, err)
	}

	if err := stepman.AddRoute(route); err != nil {
		return fmt.Errorf("Failed to setup routing: %s", err)
	}

	isSuccess = true

	return nil
}