Exemple #1
0
// Run : Runs this command and returns some value
func addRun(args []string) (err error) {

	if len(args) == 0 || len(args) < 2 {
		// err = fmt.Errorf("Not enough arguments for command %q!", addCommandName)

		// TODO: Test Errorf(), and replace func here with Errorf() once its stable
		err = lib.Error("Not enough arguments for command " + addCommandName + "!")
		return
	}

	a := args[0]
	// Are these breaks needed ?
	switch {
	case a == "package":
		err = createPackage(args[1:])
		break
	case lib.CheckValidApexType(a):
		// add < type > <name> [-v=version] [-p=package] [-exists]
		// Assume default package
		err = createProjectFile(args[1], lib.FormalizeApexType(a), "default")

		break
	default:
		err = lib.Error("Unknown type is not supported: " + a + "!")

	}

	return
}
Exemple #2
0
// 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
}
Exemple #3
0
func initRun(args []string) (err error) {
	if len(args) == 0 {
		return lib.Error("A name is required!")
	}

	d, err := os.Getwd()

	if err != nil {
		return
	}

	err = lib.SetProjectDirectory(d + seperator + args[0])

	if err != nil {
		return
	}

	err = createAllProjectDirectories(args[0], d)

	// if there is an error, remove the created directories
	if err != nil {
		os.RemoveAll(d + seperator + args[0])
		return
	}

	return
}
Exemple #4
0
func createPackage(args []string) (err error) {

	if len(args) == 0 {
		err = lib.Error("No name for package!")
		return
	}

	p, err := lib.NewPackageFromName(args[0])

	if err != nil {
		return
	}

	err = p.ExportPackage()

	return
}
Exemple #5
0
// 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
}
Exemple #6
0
// 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
}
Exemple #7
0
func instanceRun(args []string) (err error) {

	if len(args) == 0 {
		return lib.Error("Not enough arguments in command!")
	}

	instanceName := args[0]

	err = instanceFlagSet.Parse(args[1:])

	if err != nil {
		return
	}

	var instance lib.Instance

	if !newFlag {
		instance, err = lib.GetInstanceByName(instanceName)

		if err != nil {
			return err
		}
	}

	instanceExists := lib.InstanceExists(instanceName)

	if removeFlag {
		err = lib.RemoveInstance(instanceName)

		if err == nil {
			fmt.Println("Instance has been removed!")
		}

		return
	}

	if newFlag && instanceExists {
		err = lib.Error("Instance already exists!")
		return
	} else if newFlag && !instanceExists {
		instance.Name = instanceName
		instance.UserInfo = *new(lib.UserInfo)

		instance.Sandbox = sandboxFlag
		instance.Version = strconv.FormatFloat(versionFlag, 'f', 1, 32)
	}

	if usernameFlag != "" {
		instance.UserInfo.Username = usernameFlag
	}

	if passwordFlag != "" {
		instance.UserInfo.Password = passwordFlag
	}

	if tokenFlag != "" {
		instance.UserInfo.Token = tokenFlag
	}

	if versionFlag != versionFlagDefault {
		instance.Version = strconv.FormatFloat(versionFlag, 'f', 1, 32)
	}

	err = instance.SaveInstance()

	if err != nil {
		return
	}

	return
}