Compare commits
No commits in common. "master" and "v0.1.0" have entirely different histories.
8
Makefile
8
Makefile
@ -8,7 +8,7 @@ endif
|
|||||||
DESTDIR:=
|
DESTDIR:=
|
||||||
PREFIX:=/usr/local
|
PREFIX:=/usr/local
|
||||||
|
|
||||||
VERSION=0.1.2
|
VERSION=0.1.0
|
||||||
|
|
||||||
FLAGS:=-buildmode=pie -modcacherw -mod=readonly -trimpath
|
FLAGS:=-buildmode=pie -modcacherw -mod=readonly -trimpath
|
||||||
LDFLAGS:= -ldflags "-s -w -X main.programVersion=${VERSION}"
|
LDFLAGS:= -ldflags "-s -w -X main.programVersion=${VERSION}"
|
||||||
@ -23,16 +23,10 @@ else
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
install:
|
install:
|
||||||
ifeq ($(shell go env GOOS),windows)
|
|
||||||
else
|
|
||||||
install -Dm 0755 bin/${EXEC_NAME} ${DESTDIR}${PREFIX}/bin/${EXEC_NAME}
|
install -Dm 0755 bin/${EXEC_NAME} ${DESTDIR}${PREFIX}/bin/${EXEC_NAME}
|
||||||
endif
|
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
ifeq ($(shell go env GOOS),windows)
|
|
||||||
else
|
|
||||||
rm ${DESTDIR}${PREFIX}/bin/${EXEC_NAME}
|
rm ${DESTDIR}${PREFIX}/bin/${EXEC_NAME}
|
||||||
endif
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f bin/*
|
rm -f bin/*
|
@ -1,6 +1,6 @@
|
|||||||
# Maintainer: Alexander "Arav" Andreev <me@arav.su>
|
# Maintainer: Alexander "Arav" Andreev <me@arav.su>
|
||||||
pkgname=mccl
|
pkgname=mccl
|
||||||
pkgver=0.1.2
|
pkgver=0.1.0
|
||||||
pkgrel=1
|
pkgrel=1
|
||||||
pkgdesc="Console Minecraft launcher"
|
pkgdesc="Console Minecraft launcher"
|
||||||
arch=('i686' 'x86_64' 'arm' 'armv6h' 'armv7h' 'aarch64')
|
arch=('i686' 'x86_64' 'arm' 'armv6h' 'armv7h' 'aarch64')
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"mccl/internal/manifest"
|
"mccl/internal/manifest"
|
||||||
@ -31,11 +30,9 @@ func (rc *RunCommand) Run() error {
|
|||||||
if rc.Id == "" {
|
if rc.Id == "" {
|
||||||
return errors.New("an empty Minecraft version was provided")
|
return errors.New("an empty Minecraft version was provided")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.Chdir(rc.GameDir); err != nil {
|
if err := os.Chdir(rc.GameDir); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if rc.UseProfile {
|
if rc.UseProfile {
|
||||||
if util.IsFileExist(path.Join(rc.GameDir, mcclprofile.ProfileFileName)) {
|
if util.IsFileExist(path.Join(rc.GameDir, mcclprofile.ProfileFileName)) {
|
||||||
p, err := mcclprofile.Load(rc.GameDir)
|
p, err := mcclprofile.Load(rc.GameDir)
|
||||||
@ -55,7 +52,6 @@ func (rc *RunCommand) Run() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc.run_client()
|
return rc.run_client()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,23 +139,22 @@ func (rc *RunCommand) run_client() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.Command(path.Join(javaHome, "bin", "java"), cl...)
|
cmd := exec.Command(path.Join(javaHome, "bin", "java"), cl...)
|
||||||
stdout, err := cmd.StdoutPipe()
|
// stdout, err := cmd.StdoutPipe()
|
||||||
cmd.Stderr = cmd.Stdout
|
// cmd.Stderr = cmd.Stdout
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
defer stdout.Close()
|
// defer stdout.Close()
|
||||||
|
|
||||||
scanner := bufio.NewScanner(stdout)
|
// scanner := bufio.NewScanner(stdout)
|
||||||
go func() {
|
// go func() {
|
||||||
for scanner.Scan() {
|
// for scanner.Scan() {
|
||||||
fmt.Println(scanner.Text())
|
// fmt.Println(scanner.Text())
|
||||||
}
|
// }
|
||||||
}()
|
// }()
|
||||||
|
|
||||||
fmt.Printf("Minecraft version %s is started with username %s and player's UUID %s.\n",
|
fmt.Printf("Minecraft version %s is started with usename %s and player's UUID %s.\n",
|
||||||
manifst.Id, rc.Username, rc.AuthUuid)
|
manifst.Id, rc.Username, rc.AuthUuid)
|
||||||
|
|
||||||
if err := cmd.Run(); err != nil && (err.Error() != "exec: already started") {
|
if err := cmd.Run(); err != nil && (err.Error() != "exec: already started") {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
138
cmd/mccl/main.go
138
cmd/mccl/main.go
@ -31,7 +31,7 @@ func main() {
|
|||||||
|
|
||||||
if len(os.Args) < 2 {
|
if len(os.Args) < 2 {
|
||||||
usage()
|
usage()
|
||||||
os.Exit(1)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmd commands.Command
|
var cmd commands.Command
|
||||||
@ -72,7 +72,6 @@ func main() {
|
|||||||
|
|
||||||
func version() {
|
func version() {
|
||||||
fmt.Fprintf(os.Stderr, "mccl ver. %s\nCopyright (c) 2023 Alexander \"Arav\" Andreev <me@arav.su>\n", programVersion)
|
fmt.Fprintf(os.Stderr, "mccl ver. %s\nCopyright (c) 2023 Alexander \"Arav\" Andreev <me@arav.su>\n", programVersion)
|
||||||
fmt.Fprintln(os.Stderr, "URL: https://git.arav.su/Arav/mccl")
|
|
||||||
fmt.Fprintln(os.Stderr, "License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.")
|
fmt.Fprintln(os.Stderr, "License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,8 +90,8 @@ func usage() {
|
|||||||
" \033[1mlist|l\033[0m directory\n"+
|
" \033[1mlist|l\033[0m directory\n"+
|
||||||
" List all installed versions in directory\n"+
|
" List all installed versions in directory\n"+
|
||||||
"Explanation of arguments and options for commands:\n"+
|
"Explanation of arguments and options for commands:\n"+
|
||||||
" version version of a game (name of a dir inside versions dir)\n"+
|
" version minecraft's version \n"+
|
||||||
" directory a path to where Minecraft will be installed / or will be runned from\n"+
|
" directory a path to where Minecraft will be installed\n"+
|
||||||
" -u,--username username\n"+
|
" -u,--username username\n"+
|
||||||
" player's username (Anonymous by default)\n"+
|
" player's username (Anonymous by default)\n"+
|
||||||
" -U,--uuid UUID\n"+
|
" -U,--uuid UUID\n"+
|
||||||
@ -102,7 +101,7 @@ func usage() {
|
|||||||
" --profile\n"+
|
" --profile\n"+
|
||||||
" load/save username, UUID, and -Xmx from/to a file.\n"+
|
" load/save username, UUID, and -Xmx from/to a file.\n"+
|
||||||
" Once saved, you can ommit -u,-U and --java-Xmx,\n"+
|
" Once saved, you can ommit -u,-U and --java-Xmx,\n"+
|
||||||
" since they will be stored in", mcclprofile.ProfileFileName)
|
" since they are stored in", mcclprofile.ProfileFileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
type arguments struct {
|
type arguments struct {
|
||||||
@ -132,15 +131,74 @@ func parseArguments(args []string) (parsed arguments, err error) {
|
|||||||
parsed.Username = "Anonymous"
|
parsed.Username = "Anonymous"
|
||||||
parsed.Directory = "."
|
parsed.Directory = "."
|
||||||
parsed.Uuid = "00000000-0000-0000-0000-000000000000"
|
parsed.Uuid = "00000000-0000-0000-0000-000000000000"
|
||||||
|
|
||||||
for i := 0; i < len(args); i++ {
|
for i := 0; i < len(args); i++ {
|
||||||
if args[i][0] != '-' {
|
if len(args[i]) > 2 && args[i][0] == '-' && args[i][1] == '-' {
|
||||||
if parsed.Command != "" {
|
switch args[i][2:] {
|
||||||
return parsed, fmt.Errorf("there is already a command %s, but a second one (%s) was provided",
|
case "version":
|
||||||
parsed.Command, args[i])
|
parsed.ShowVersion = true
|
||||||
|
case "help":
|
||||||
|
parsed.ShowHelp = true
|
||||||
|
case "demand-press-enter":
|
||||||
|
parsed.DemandPressEnter = true
|
||||||
|
case "username":
|
||||||
|
if len(args) == i+1 || args[i+1][0] == '-' {
|
||||||
|
err = errNoOptArg{ArgName: args[i]}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
parsed.Username = args[i+1]
|
||||||
|
i++
|
||||||
|
case "uuid":
|
||||||
|
if len(args) == i+1 || args[i+1][0] == '-' {
|
||||||
|
err = errNoOptArg{ArgName: args[i]}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
parsed.Uuid = args[i+1]
|
||||||
|
i++
|
||||||
|
case "java-Xmx":
|
||||||
|
if len(args) == i+1 || args[i+1][0] == '-' {
|
||||||
|
err = errNoOptArg{ArgName: args[i]}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
parsed.JavaXmx = args[i+1]
|
||||||
|
i++
|
||||||
|
case "profile":
|
||||||
|
parsed.UseProfile = true
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("an unknown option %s was provided", args[i])
|
||||||
|
return
|
||||||
}
|
}
|
||||||
parsed.Command = args[i]
|
} else if args[i][0] == '-' && len(args[i]) > 1 {
|
||||||
switch parsed.Command {
|
for _, option := range args[i][1:] {
|
||||||
|
switch option {
|
||||||
|
case 'v':
|
||||||
|
parsed.ShowVersion = true
|
||||||
|
case 'h':
|
||||||
|
parsed.ShowHelp = true
|
||||||
|
case 'u':
|
||||||
|
if len(args) == i+1 || args[i+1][0] == '-' {
|
||||||
|
err = errNoOptArg{ArgName: args[i]}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
parsed.Username = args[i+1]
|
||||||
|
i++
|
||||||
|
case 'U':
|
||||||
|
if len(args) == i+1 || args[i+1][0] == '-' {
|
||||||
|
err = errNoOptArg{ArgName: args[i]}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
parsed.Uuid = args[i+1]
|
||||||
|
i++
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("an unknown option %c was provided", option)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if parsed.Command != "" {
|
||||||
|
err = fmt.Errorf("only one command should present")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch parsed.Command = args[i]; parsed.Command {
|
||||||
case "i":
|
case "i":
|
||||||
fallthrough
|
fallthrough
|
||||||
case "install":
|
case "install":
|
||||||
@ -148,9 +206,9 @@ func parseArguments(args []string) (parsed arguments, err error) {
|
|||||||
case "r":
|
case "r":
|
||||||
fallthrough
|
fallthrough
|
||||||
case "run":
|
case "run":
|
||||||
if i+3 > len(args) || args[i+1][0] == '-' {
|
if len(args) <= i+3 || args[i+1][0] == '-' || args[i+2][0] == '-' {
|
||||||
return parsed, fmt.Errorf("a command %s is missing its version and directory arguments",
|
err = fmt.Errorf("not enough arguments was provided")
|
||||||
parsed.Command)
|
return
|
||||||
}
|
}
|
||||||
parsed.GameVersion = args[i+1]
|
parsed.GameVersion = args[i+1]
|
||||||
parsed.Directory = args[i+2]
|
parsed.Directory = args[i+2]
|
||||||
@ -158,56 +216,16 @@ func parseArguments(args []string) (parsed arguments, err error) {
|
|||||||
case "l":
|
case "l":
|
||||||
fallthrough
|
fallthrough
|
||||||
case "list":
|
case "list":
|
||||||
if i+1 >= len(args) || args[i+1][0] == '-' {
|
if len(args) <= i+2 || args[i+1][0] == '-' {
|
||||||
return parsed, fmt.Errorf("a command list is missing its directory argument")
|
err = fmt.Errorf("not enough arguments was provided")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
parsed.Directory = args[i+1]
|
parsed.Directory = args[i+1]
|
||||||
i++
|
i++
|
||||||
}
|
default:
|
||||||
continue
|
err = fmt.Errorf("an unknown command %s was provided", parsed.Command)
|
||||||
}
|
|
||||||
|
|
||||||
switch args[i] {
|
|
||||||
case "-v":
|
|
||||||
fallthrough
|
|
||||||
case "--version":
|
|
||||||
parsed.ShowVersion = true
|
|
||||||
case "-h":
|
|
||||||
fallthrough
|
|
||||||
case "--help":
|
|
||||||
parsed.ShowHelp = true
|
|
||||||
case "--demand-press-enter":
|
|
||||||
parsed.DemandPressEnter = true
|
|
||||||
case "-u":
|
|
||||||
fallthrough
|
|
||||||
case "--username":
|
|
||||||
if len(args) == i+1 || args[i+1][0] == '-' {
|
|
||||||
err = errNoOptArg{ArgName: args[i]}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
parsed.Username = args[i+1]
|
|
||||||
i++
|
|
||||||
case "-U":
|
|
||||||
fallthrough
|
|
||||||
case "--uuid":
|
|
||||||
if len(args) == i+1 || args[i+1][0] == '-' {
|
|
||||||
err = errNoOptArg{ArgName: args[i]}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
parsed.Uuid = args[i+1]
|
|
||||||
i++
|
|
||||||
case "--java-Xmx":
|
|
||||||
if len(args) == i+1 || args[i+1][0] == '-' {
|
|
||||||
err = errNoOptArg{ArgName: args[i]}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
parsed.JavaXmx = args[i+1]
|
|
||||||
i++
|
|
||||||
case "--profile":
|
|
||||||
parsed.UseProfile = true
|
|
||||||
default:
|
|
||||||
err = fmt.Errorf("an unknown option %s was provided", args[i])
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
//go:build unix
|
|
||||||
// +build unix
|
|
||||||
|
|
||||||
package util
|
package util
|
||||||
|
|
||||||
func LocateJavaHome(component string, majorVersion int) (string, error) {
|
func LocateJavaHome(component string, majorVersion int) (string, error) {
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
//go:build windows
|
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
//go:build unix
|
|
||||||
// +build unix
|
|
||||||
|
|
||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
//go:build windows
|
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
Loading…
Reference in New Issue
Block a user