Пример #1
0
func prepare(t *testing.T) config.Berks {
	opts := config.DefaultOption()
	if err := config.Create("/tmp", opts); err != nil {
		t.Errorf("cannot create Berksfile with %d", err)
	}
	berks := config.Parse("/tmp", opts)
	return berks
}
Пример #2
0
func TestNewGather(t *testing.T) {
	opts := config.DefaultOption()
	if err := config.Create("/tmp", opts); err != nil {
		t.Errorf("cannot create Berksfile with %d", err)
	}
	berks := config.Parse("/tmp", opts)
	err := Gather("/tmp", berks)
	if err != nil {
		t.Errorf("%d", err)
	}

	removeTmpFile(t)
}
Пример #3
0
func Command(argv []string) int {
	command, args, options := parseArgs(argv)

	configOptions := config.DefaultOption()
	if options["config"] != "" {
		configOptions.ConfigFileName = options["config"]
	}
	path := "./"
	if len(args) > 0 {
		path = args[0]
	}

	switch command {
	case "version":
		fmt.Printf("ey-berks version is: %s", Version)
	case "help":
		fmt.Print(usage())
		return 0
	case "clear":
		fmt.Println("remove cookbooks and %s at %s ? [y, yes|n, no]", configOptions.ConfigFileName, path)
		if askForConfirmation() {
			fmt.Println("removing cookbooks/ and %s", configOptions.ConfigFileName)
			removeDirs(
				filepath.Join(path, configOptions.ConfigFileName),
				filepath.Join(path, configOptions.TargetDirName),
			)
			fmt.Println("removed")
		}
		return 0
	case "config":
		fmt.Printf("Creating a sample configuration file, %s at %s\n", configOptions.ConfigFileName, path)

		if config.IsExistConfigFile(path, configOptions) {
			fmt.Println("Error: The configration file alrady exists")
			return 1
		}

		if err := config.Create(path, configOptions); err != nil {
			fmt.Println(err)
			return 1
		}
	case "update-cache":
		fmt.Println("Updatint cookbook caches")
		berks := config.Parse(path, configOptions)
		if err := gather.Gather(path, berks); err != nil {
			fmt.Println(err)
		}
	case "create-main-recipe":
		berks := config.Parse(path, configOptions)
		list := author.CreateMainRecipe(berks)
		if err := author.CreateFile(path, list); err != nil {
			fmt.Printf("error: %v\n", err)
		}
	case "copy-recipes":
		berks := config.Parse(path, configOptions)
		if err := gather.Copy(path, berks); err != nil {
			fmt.Printf("error: %v\n", err)
		}
	case "compile":
		berks := config.Parse(path, configOptions)

		if err := gather.Gather(path, berks); err != nil {
			fmt.Println(err)
		}

		list := author.CreateMainRecipe(berks)
		if err := author.CreateFile(path, list); err != nil {
			fmt.Printf("error: %v\n", err)
		}

		if err := gather.Copy(path, berks); err != nil {
			fmt.Printf("error: %v\n", err)
		}
	case "apply-attr":
		if _, ok := options["from"]; !ok {
			fmt.Println("require --from=directory path")
			return 1
		}
		attrOptions := attribute.DefaultOptions()
		if err := attribute.Apply(path, options["from"], attrOptions); err != nil {
			fmt.Printf("error: %v\n", err)
		}
	case "gather-attr":
		if _, ok := options["from"]; !ok {
			fmt.Println("require --from=directory path")
			return 1
		}
		attrOptions := attribute.DefaultOptions()
		if err := attribute.Gather(options["from"], path, attrOptions); err != nil {
			fmt.Printf("error: %v\n", err)
		}
	default:
		fmt.Println("The command doesn't exist.Please check ey-berks help.")
		return 0
	}
	return 0
}