Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
a7cf5b0ec8 | |||
87a787da84 | |||
eb4d1525a2 | |||
4ed0931ece | |||
1f8b0acd6a | |||
ed493b012a | |||
7cb5d35e6a | |||
3d492e26ae | |||
32dba480ee | |||
7e4f845821 | |||
5efbc5a82c |
8
Makefile
8
Makefile
@ -8,7 +8,7 @@ endif
|
|||||||
DESTDIR:=
|
DESTDIR:=
|
||||||
PREFIX:=/usr/local
|
PREFIX:=/usr/local
|
||||||
|
|
||||||
VERSION=0.1.0
|
VERSION=0.1.2
|
||||||
|
|
||||||
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,10 +23,16 @@ 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.0
|
pkgver=0.1.2
|
||||||
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,6 +1,7 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"mccl/internal/manifest"
|
"mccl/internal/manifest"
|
||||||
@ -30,9 +31,11 @@ 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)
|
||||||
@ -52,6 +55,7 @@ func (rc *RunCommand) Run() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc.run_client()
|
return rc.run_client()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,22 +143,23 @@ 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 usename %s and player's UUID %s.\n",
|
fmt.Printf("Minecraft version %s is started with username %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
|
||||||
}
|
}
|
||||||
|
136
cmd/mccl/main.go
136
cmd/mccl/main.go
@ -31,7 +31,7 @@ func main() {
|
|||||||
|
|
||||||
if len(os.Args) < 2 {
|
if len(os.Args) < 2 {
|
||||||
usage()
|
usage()
|
||||||
os.Exit(0)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmd commands.Command
|
var cmd commands.Command
|
||||||
@ -72,6 +72,7 @@ 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>.")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,8 +91,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 minecraft's version \n"+
|
" version version of a game (name of a dir inside versions dir)\n"+
|
||||||
" directory a path to where Minecraft will be installed\n"+
|
" directory a path to where Minecraft will be installed / or will be runned from\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"+
|
||||||
@ -101,7 +102,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 are stored in", mcclprofile.ProfileFileName)
|
" since they will be stored in", mcclprofile.ProfileFileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
type arguments struct {
|
type arguments struct {
|
||||||
@ -131,74 +132,15 @@ 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 len(args[i]) > 2 && args[i][0] == '-' && args[i][1] == '-' {
|
if args[i][0] != '-' {
|
||||||
switch args[i][2:] {
|
|
||||||
case "version":
|
|
||||||
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
|
|
||||||
}
|
|
||||||
} else if args[i][0] == '-' && len(args[i]) > 1 {
|
|
||||||
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 != "" {
|
if parsed.Command != "" {
|
||||||
err = fmt.Errorf("only one command should present")
|
return parsed, fmt.Errorf("there is already a command %s, but a second one (%s) was provided",
|
||||||
return
|
parsed.Command, args[i])
|
||||||
}
|
}
|
||||||
switch parsed.Command = args[i]; parsed.Command {
|
parsed.Command = args[i]
|
||||||
|
switch parsed.Command {
|
||||||
case "i":
|
case "i":
|
||||||
fallthrough
|
fallthrough
|
||||||
case "install":
|
case "install":
|
||||||
@ -206,9 +148,9 @@ func parseArguments(args []string) (parsed arguments, err error) {
|
|||||||
case "r":
|
case "r":
|
||||||
fallthrough
|
fallthrough
|
||||||
case "run":
|
case "run":
|
||||||
if len(args) <= i+3 || args[i+1][0] == '-' || args[i+2][0] == '-' {
|
if i+3 > len(args) || args[i+1][0] == '-' {
|
||||||
err = fmt.Errorf("not enough arguments was provided")
|
return parsed, fmt.Errorf("a command %s is missing its version and directory arguments",
|
||||||
return
|
parsed.Command)
|
||||||
}
|
}
|
||||||
parsed.GameVersion = args[i+1]
|
parsed.GameVersion = args[i+1]
|
||||||
parsed.Directory = args[i+2]
|
parsed.Directory = args[i+2]
|
||||||
@ -216,17 +158,57 @@ func parseArguments(args []string) (parsed arguments, err error) {
|
|||||||
case "l":
|
case "l":
|
||||||
fallthrough
|
fallthrough
|
||||||
case "list":
|
case "list":
|
||||||
if len(args) <= i+2 || args[i+1][0] == '-' {
|
if i+1 >= len(args) || args[i+1][0] == '-' {
|
||||||
err = fmt.Errorf("not enough arguments was provided")
|
return parsed, fmt.Errorf("a command list is missing its directory argument")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
parsed.Directory = args[i+1]
|
parsed.Directory = args[i+1]
|
||||||
i++
|
i++
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
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:
|
default:
|
||||||
err = fmt.Errorf("an unknown command %s was provided", parsed.Command)
|
err = fmt.Errorf("an unknown option %s was provided", args[i])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
//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,3 +1,6 @@
|
|||||||
|
//go:build windows
|
||||||
|
// +build windows
|
||||||
|
|
||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
//go:build unix
|
||||||
|
// +build unix
|
||||||
|
|
||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
//go:build windows
|
||||||
|
// +build windows
|
||||||
|
|
||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
Loading…
Reference in New Issue
Block a user