func NewFromDir(dir string) (*Instance, error) {
	manifestToml, err := ioutil.ReadFile("./minepkg.toml")
	if err != nil {
		return nil, ErrNoInstance
	}
	manifest := manifest.Manifest{}
	if err = toml.Unmarshal(manifestToml, &manifest); err != nil {
		return nil, err
	}
	if manifest.Requirements.Minecraft == "" {
		return nil, ErrMissingRequirementMinecraft
	}
	userConfig, err := os.UserConfigDir()
	if err != nil {
		return nil, err
	}
	userCache, err := os.UserCacheDir()
	if err != nil {
		return nil, err
	}
	instance := &Instance{
		Manifest:  &manifest,
		Directory: dir,
		GlobalDir: filepath.Join(userConfig, "minepkg"),
		CacheDir:  filepath.Join(userCache, "minepkg"),
		isFromWd:  true,
	}
	if err := instance.initLockfile(); err != nil {
		return nil, err
	}
	if err := instance.migrate(); err != nil {
		return nil, err
	}
	return instance, nil
}
NewFromDir tries to detect a instance in the given directory
package instances
import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
	"github.com/jwalton/gchalk"
	"github.com/minepkg/minepkg/internals/commands"
	"github.com/minepkg/minepkg/internals/api"
	"github.com/minepkg/minepkg/internals/mojang"
	"github.com/minepkg/minepkg/pkg/manifest"
	"github.com/pelletier/go-toml"
)
var (
	PlatformVanilla uint8 = 1
	PlatformFabric uint8 = 2
	PlatformForge uint8 = 3
	ErrNoInstance = &commands.CliError{
		Text: "no minepkg.toml file was found in this directory",
		Suggestions: []string{
			fmt.Sprintf("Create it with %s", gchalk.Bold("minepkg init")),
			"Move into a folder containing a minepkg.toml file",
		},
	}
	ErrMissingRequirementMinecraft = &commands.CliError{
		Text: "the manifest is missing the required requirements.minecraft field",
		Suggestions: []string{
			"Add the field as documented here https://preview.minepkg.io/docs/manifest#requirements",
		},
	}
)
type Instance struct {
	GlobalDir string
	CacheDir string
	Directory         string
	Manifest          *manifest.Manifest
	Lockfile          *manifest.Lockfile
	MojangCredentials *mojang.AuthResponse
	MinepkgAPI        *api.MinepkgAPI
	isFromWd                     bool
	launchCmd                    string
	lockfileNeedsRenameMigration bool
}
func (i *Instance) LaunchCmd() string {
	return i.launchCmd
}
func (i *Instance) VersionsDir() string {
	return filepath.Join(i.CacheDir, "versions")
}
func (i *Instance) AssetsDir() string {
	return filepath.Join(i.CacheDir, "assets")
}
func (i *Instance) LibrariesDir() string {
	return filepath.Join(i.CacheDir, "libraries")
}
func (i *Instance) InstancesDir() string {
	return filepath.Join(i.GlobalDir, "instances")
}
func (i *Instance) PackageCacheDir() string {
	return filepath.Join(i.CacheDir, "cache")
}
func (i *Instance) JavaDir() string {
	return filepath.Join(i.CacheDir, "java")
}
func (i *Instance) McDir() string {
	return filepath.Join(i.Directory, "minecraft")
}
func (i *Instance) ModsDir() string {
	return filepath.Join(i.Directory, "minecraft/mods")
}
func (i *Instance) OverwritesDir() string {
	return filepath.Join(i.Directory, "overwrites")
}
func (i *Instance) ManifestPath() string {
	return filepath.Join(i.Directory, "minepkg.toml")
}
func (i *Instance) LockfilePath() string {
	return filepath.Join(i.Directory, ".minepkg-lock.toml")
}
func (i *Instance) legacyLockfilePath() string {
	return filepath.Join(i.Directory, "minepkg-lock.toml")
}
func (i *Instance) Platform() uint8 {
	switch {
	case i.Manifest.Requirements.FabricLoader != "":
		return PlatformFabric
	case i.Manifest.Requirements.ForgeLoader != "":
		return PlatformForge
	default:
		return PlatformVanilla
	}
}
func (i *Instance) Desc() string {
	manifest := i.Manifest
	depCount := fmt.Sprintf(" %d deps ", len(manifest.Dependencies))
	name := fmt.Sprintf(" 📦 %s ", manifest.Package.Name)
	build := []string{
		gchalk.BgBlue(name),
		gchalk.BgGray(depCount),
	}
	return strings.Join(build, "")
}
func New() *Instance {
	userConfig, err := os.UserConfigDir()
	if err != nil {
		panic(err)
	}
	userCache, err := os.UserCacheDir()
	if err != nil {
		panic(err)
	}
	return &Instance{
		GlobalDir: filepath.Join(userConfig, "minepkg"),
		CacheDir:  filepath.Join(userCache, "minepkg"),
	}
}