func (e *Local) GetContext() string {
	return e.WorkspaceContext
}
GetContext returns the context of Local
package environment
import (
	"bytes"
	"errors"
	"fmt"
	"io/ioutil"
	"net"
	"os"
	"os/exec"
	"path/filepath"
	"github.com/konveyor/move2kube/filesystem"
	"github.com/konveyor/move2kube/types"
	environmenttypes "github.com/konveyor/move2kube/types/environment"
	"github.com/sirupsen/logrus"
)
type Local struct {
	EnvInfo
	WorkspaceSource  string
	WorkspaceContext string
	GRPCQAReceiver net.Addr
}
func NewLocal(envInfo EnvInfo, grpcQAReceiver net.Addr) (ei EnvironmentInstance, err error) {
	local := &Local{
		EnvInfo:        envInfo,
		GRPCQAReceiver: grpcQAReceiver,
	}
	local.WorkspaceContext, err = ioutil.TempDir(local.TempPath, types.AppNameShort)
	if err != nil {
		logrus.Errorf("Unable to create temp dir : %s", err)
		return local, err
	}
	local.WorkspaceSource, err = ioutil.TempDir(local.TempPath, workspaceDir)
	if err != nil {
		logrus.Errorf("Unable to create temp dir : %s", err)
	}
	local.Reset()
	return local, nil
}
func (e *Local) Reset() error {
	if err := filesystem.Replicate(e.Context, e.WorkspaceContext); err != nil {
		logrus.Errorf("Unable to copy contents to directory %s, %s : %s", e.Context, e.WorkspaceContext, err)
		return err
	}
	if err := filesystem.Replicate(e.Source, e.WorkspaceSource); err != nil {
		logrus.Errorf("Unable to copy contents to directory %s, %s : %s", e.Source, e.WorkspaceSource, err)
		return err
	}
	return nil
}
func (e *Local) Exec(cmd environmenttypes.Command) (stdout string, stderr string, exitcode int, err error) {
	var outb, errb bytes.Buffer
	var execcmd *exec.Cmd
	if len(cmd) > 0 {
		execcmd = exec.Command(cmd[0], cmd[1:]...)
	} else {
		err := fmt.Errorf("no command found to execute")
		logrus.Errorf("%s", err)
		return "", "", 0, err
	}
	execcmd.Dir = e.WorkspaceContext
	execcmd.Stdout = &outb
	execcmd.Stderr = &errb
	execcmd.Env = e.getEnv()
	err = execcmd.Run()
	if err != nil {
		var ee *exec.ExitError
		var pe *os.PathError
		if errors.As(err, &ee) {
			exitcode = ee.ExitCode()
			err = nil
		} else if errors.As(err, &pe) {
			logrus.Errorf("PathError during execution of command: %v", pe)
			err = pe
		} else {
			logrus.Errorf("Generic error during execution of command: %v", err)
		}
	}
	return outb.String(), errb.String(), exitcode, err
}
func (e *Local) Destroy() error {
	err := os.RemoveAll(e.WorkspaceSource)
	if err != nil {
		logrus.Errorf("Unable to remove directory %s : %s", e.WorkspaceSource, err)
	}
	err = os.RemoveAll(e.WorkspaceContext)
	if err != nil {
		logrus.Errorf("Unable to remove directory %s : %s", e.WorkspaceContext, err)
	}
	return nil
}
func (e *Local) Download(path string) (string, error) {
	output, err := ioutil.TempDir(e.TempPath, "*")
	if err != nil {
		logrus.Errorf("Unable to create temp dir : %s", err)
		return path, err
	}
	ps, err := os.Stat(path)
	if err != nil {
		logrus.Errorf("Unable to stat source : %s", path)
		return "", err
	}
	if ps.Mode().IsRegular() {
		output = filepath.Join(output, filepath.Base(path))
	}
	err = filesystem.Replicate(path, output)
	if err != nil {
		logrus.Errorf("Unable to replicate in syncoutput : %s", err)
		return path, err
	}
	return output, nil
}
func (e *Local) Upload(outpath string) (envpath string, err error) {
	envpath, err = ioutil.TempDir(e.TempPath, "*")
	if err != nil {
		logrus.Errorf("Unable to create temp dir : %s", err)
		return outpath, err
	}
	ps, err := os.Stat(outpath)
	if err != nil {
		logrus.Errorf("Unable to stat source : %s", outpath)
		return "", err
	}
	if ps.Mode().IsRegular() {
		envpath = filepath.Join(envpath, filepath.Base(outpath))
	}
	err = filesystem.Replicate(outpath, envpath)
	if err != nil {
		logrus.Errorf("Unable to replicate in syncoutput : %s", err)
		return outpath, err
	}
	return envpath, nil
}