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