コード例 #1
0
ファイル: add.go プロジェクト: massmep/env
func createProjectFile(name, fileType, packageName string) (err error) {

	p, err := lib.ImportPackage(packageName)

	if err != nil {
		return
	}

	// if either of these is null, delete all files created by this func

	err = lib.CreateBuildFile(name, fileType)

	if err != nil {
		return
	}

	err = lib.CreateMetadataFile(name, fileType)

	if err != nil {
		// remove build file
		return
	}

	err = p.AddMemeber(name, fileType)

	if err != nil {
		return
	}

	err = p.ExportPackage()

	return
}
コード例 #2
0
ファイル: package.go プロジェクト: massmep/env
// Full Commmand :
// dev package <name> < add | remove > <file> <type>
// Given to Run() :
// <name> < add | remove > <file> <type>
// TODO: add a flag value to also remove given files from disc (--erase)
func packageRun(arg []string) (err error) {

	if len(arg) < packageCommandMinArguments {

		// TODO: Fix conversion- converts into a rune with a byte of 4-> makes a weird star thing
		err = lib.Error("Command needs more arguments! Min arguments required: " + string(packageCommandMinArguments))
		return
	}

	packageName := arg[0]

	if len(packageName) == 0 {
		err = lib.Error("Name must be a valid, non-empty string!")
	}

	p, err := lib.ImportPackage(packageName)

	if err != nil {
		return
	}

	if arg[1] == "add" {
		err = p.AddMemeber(arg[2], arg[3])

		if err != nil {
			return
		}

		err = p.ExportPackage()

		if err != nil {
			return
		}
	} else if arg[1] == "remove" {
		err = p.RemoveMember(arg[2], arg[3])

		if err != nil {
			return
		}

		err = p.ExportPackage()

		if err != nil {
			return
		}
	} else {
		err = lib.Error("Unsupported package command!")
		return
	}

	return
}
コード例 #3
0
ファイル: deploy.go プロジェクト: massmep/env
// implemented as :
// dev deploy instance package
// TODO: Add flags for max time, etc
func deployRun(args []string) (err error) {

	if len(args) < 1 {
		err = lib.Error("Not enough arguments for deploy!")
		return
	}

	instanceName := args[0]
	packageName := ""

	if len(args) == 1 {
		packageName = "default"
	} else if len(args) == 2 {
		packageName = args[1]
	}

	instance, err := lib.GetInstanceByName(instanceName)

	if err != nil {
		return
	}

	pkg, err := lib.ImportPackage(packageName)

	if err != nil {
		return
	}

	contents, err := pkg.ZipPackageIntoBytes()

	if err != nil {
		return
	}

	err = lib.TryLogIn(&instance)

	if err != nil {
		return
	}

	id, err := lib.TryDeploy(contents, instance)

	if err != nil {
		return
	}

	finished := false
	maxTime := int(time.Minute * 5)
	currentTime := 0

	for !finished {
		sleepTime := int(3 * time.Second)
		currentTime += sleepTime

		if currentTime <= maxTime {
			time.Sleep(time.Duration(sleepTime))
			finished = lib.CheckAsyncDeploy(id, instance)
		} else {
			return lib.Error("Job exceeded maximum time!")
		}
	}

	return
}
コード例 #4
0
ファイル: pull.go プロジェクト: massmep/env
// pull <pkg> <instance>
// puull <instance>
func pullRun(args []string) (err error) {

	if len(args) < 1 {
		return lib.Error("Not enough arguments for pull!")
	}

	instance, err := lib.GetInstanceByName(args[0])

	if err != nil {
		return
	}

	var packageName string

	if len(args) == 1 {
		packageName = "default"
	} else {
		packageName = args[1]
	}

	pkg, err := lib.ImportPackage(packageName)

	if err != nil {
		return
	}

	err = lib.TryLogIn(&instance)

	if err != nil {
		return
	}

	id, err := lib.TryRetrieve(pkg, instance)

	if err != nil {
		return
	}

	finished := false
	contents := []byte("")
	maxTime := int(time.Minute * 5)
	currentTime := 0

	for !finished {
		sleepTime := int(3 * time.Second)
		currentTime += sleepTime

		if currentTime <= maxTime {
			time.Sleep(time.Duration(sleepTime))
			finished, contents = lib.CheckAsyncRetrieve(id, instance)
		} else {
			return lib.Error("Job exceeded maximum time!")
		}
	}

	err = writePulledFiles(contents)

	if err != nil {
		return
	}

	return
}