Skip to content

Commit

Permalink
add version subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxkad committed May 24, 2023
1 parent e72fcbf commit 79e046b
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 16 deletions.
15 changes: 12 additions & 3 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ minecraft_installer -name minecraft_server -version 1.19.2 -server fabric -path

```sh
# Install the modpack from local to the current directory
minecraft_installer -name modpack_server modpack /path/to/modrinch-modpack.mrpack
# Hint: Only support modrinch modpack for now, curseforge is in progress
minecraft_installer -name modpack_server modpack /path/to/modrinth-modpack.mrpack
# Hint: Only support modrinth modpack for now, curseforge is in progress
```

```sh
Expand All @@ -95,9 +95,18 @@ minecraft_installer -name modpack_server modpack 'https://cdn-raw.modrinth.com/d
# you must add the prefixs [https://, http://]
```

### List server avaliable versions

```sh
minecraft_installer versions
```

```sh
minecraft_installer -version snapshot versions
```

## TODO

- [ ] PaperMC
- [ ] Search modpacks from modrinth
- [ ] List server versions
- [ ] Configurable proxy
22 changes: 16 additions & 6 deletions README_zh.MD
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,24 @@ minecraft_installer -name minecraft_server -version 1.19.2 -server fabric -path
### 安装整合包

```sh
# Install the modpack from local to the current directory
minecraft_installer -name modpack_server modpack /path/to/modrinch-modpack.mrpack
# Hint: Only support modrinch modpack for now, curseforge is in progress
# 从本地文件安装整合包
minecraft_installer -name modpack_server modpack /path/to/modrinth-modpack.mrpack
# 提示: 目前仅支持modrinth的整合包
```

```sh
# Install the modpack from internet to the current directory
# 从网络下载整合包并安装
minecraft_installer -name modpack_server modpack 'https://cdn-raw.modrinth.com/data/sl6XzkCP/versions/i4agaPF2/Automation%20v3.3.mrpack'
# Hint: if you want to install modpack from the internet,
# you must add the prefixs [https://, http://]
# 提示: 如果想要从网络安装,
# 则必须添加前缀 [https://, http://]
```

### 列出服务端可用版本

```sh
minecraft_installer versions
```

```sh
minecraft_installer -version snapshot versions
```
8 changes: 8 additions & 0 deletions changelogs/v1.2.3.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

#### Adds

- Subcommand `versions` to list all avaliable versions

#### Changes

*None*
24 changes: 22 additions & 2 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var (

func parseArgs(){
flag.StringVar(&TargetVersion, "version", TargetVersion,
"the version of the server need to be installed, could be [latest latest-snapshot]")
"the version of the server need to be installed, could be [latest snapshot latest-snapshot]")
flag.StringVar(&InstallPath, "output", InstallPath,
"the path need to be installed")
flag.StringVar(&ExecutableName, "name", ExecutableName,
Expand All @@ -51,7 +51,7 @@ func parseArgs(){
flag.PrintDefaults()
fmt.Fprintln(out, "Args:")
fmt.Fprintln(out, " <server_type> string")
fmt.Fprintf (out, " type of the server %v (default %q )\n", installer.GetInstallerNames(), ServerType)
fmt.Fprintf (out, " type of the server %v (default \"vanilla\" for `versions`)", installer.GetInstallerNames())
fmt.Fprintln(out, " <modpack_file> filepath | URL")
fmt.Fprintln(out, " the modpack's local path or an URL. If it's an URL, installer will download the modpack first")
}
Expand Down Expand Up @@ -116,6 +116,26 @@ func main(){
loger.Infof("installed: %s", installed)
fmt.Println("\nServer executable file installed to:")
fmt.Println(installed)
case "versions":
if flag.NArg() > 1 {
ServerType = flag.Arg(1)
}else{
ServerType = "vanilla"
}
snapshot := TargetVersion == "snapshot"
loger.Infof("Getting version list for %s server", ServerType)
ir, ok := installer.Get(ServerType)
if !ok {
loger.Fatalf("Could not found installer for server %q", ServerType)
}
versions, err := ir.ListVersions(snapshot)
if err != nil {
loger.Fatalf("Couldn't get versions: %v", err)
}
fmt.Println("Total versions count:", len(versions))
for _, v := range versions {
fmt.Println(v)
}
default:
loger.Infof("Getting version %q for %s server", TargetVersion, ServerType)
loger.Infof("Install into %q with name %q", InstallPath, ExecutableName)
Expand Down
10 changes: 8 additions & 2 deletions cli/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package main
const UsageText = `
minecraft_installer [...flags] <server_type>
minecraft_installer [...flags] modpack <modpack_file>
minecraft_installer [...flags] versions [<server_type>]
Example:
Install servers:
Expand All @@ -16,11 +17,16 @@ Example:
minecraft_installer -name minecraft_server -version 1.19.2 -output server fabric
Install minecraft 1.19.2 fabric server into server/minecraft_server.jar
Install modpacks:
minecraft_installer -name modpack_server modpack /path/to/modrinch-modpack.mrpack
minecraft_installer -name modpack_server modpack /path/to/modrinth-modpack.mrpack
Install the modpack from local to the current directory
Hint: Only support modrinch modpack for now, curseforge is in progress
Hint: Only support modrinth modpack for now, curseforge is in progress
minecraft_installer -name modpack_server modpack 'https://cdn-raw.modrinth.com/data/sl6XzkCP/versions/i4agaPF2/Automation%20v3.3.mrpack'
Install the modpack from internet to the current directory
Hint: if you want to install modpack from the internet,
you must add the prefixs [https://, http://]
List Versions:
minecraft_installer versions
List all vanilla versions but without snapshots
minecraft_installer -version snapshot versions
List all vanilla versions include snapshots
`
13 changes: 13 additions & 0 deletions fabric_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ func (r *FabricInstaller)InstallWithLoader(path, name string, target string, loa
return installed, nil
}

func (r *FabricInstaller)ListVersions(snapshot bool)(versions []string, err error){
vs, err := r.GetInstallers()
if err != nil {
return
}
for _, v := range vs {
if v.Stable || snapshot {
versions = append(versions, v.Version)
}
}
return
}

func (r *FabricInstaller)GetInstallers()(res []FabricInstallerVersion, err error){
tg, err := url.JoinPath(r.MetaUrl, "v2", "versions", "installer")
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions forge_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ func (r *ForgeInstaller)InstallWithLoader(path, name string, target string, load
return
}

func (r *ForgeInstaller)ListVersions(snapshot bool)(versions []string, err error){
data, err := r.GetInstallerVersions()
if err != nil {
return
}
for _, v := range data.Versioning.Versions {
i := strings.IndexByte(v, '-')
versions = append(versions, v[i + 1:])
}
return
}

func (r *ForgeInstaller)GetInstallerVersions()(data MavenMetadata, err error){
link, err := url.JoinPath(r.MavenUrl, "net/minecraftforge/forge")
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
type Installer interface {
// target == "" means latest
Install(path, name string, target string)(installed string, err error)
ListVersions(snapshot bool)(versions []string, err error)
}

var Installers = make(map[string]Installer, 10)
Expand Down
11 changes: 11 additions & 0 deletions quilt_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ func (r *QuiltInstaller)InstallWithLoader(path, name string, target string, load
return
}

func (r *QuiltInstaller)ListVersions(snapshot bool)(versions []string, err error){
data, err := r.GetInstallerVersions()
if err != nil {
return
}
for _, v := range data.Versioning.Versions {
versions = append(versions, v)
}
return
}

func (r *QuiltInstaller)GetInstallerVersions()(data MavenMetadata, err error){
link, err := url.JoinPath(r.MavenUrl, "org/quiltmc/quilt-installer")
if err != nil {
Expand Down
11 changes: 8 additions & 3 deletions spigot_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ func (*SpigotInstaller)Install(path, name string, target string)(installed strin

foundVersion := target
if target == "" || target == "latest" || target == "latest-snapshot" {
if target == "latest-snapshot" {
loger.Info("Warn: spigot do not support snapshot version")
}
var versions VanillaVersions
loger.Info("Getting minecraft version manifest...")
if versions, err = VanillaIns.GetVersions(); err != nil {
return
}
if target == "latest-snapshot" {
loger.Info("Warn: spigot do not support snapshot version")
}
target = versions.Latest.Release
foundVersion += "(" + target + ")"
}
Expand Down Expand Up @@ -77,3 +77,8 @@ func (*SpigotInstaller)Install(path, name string, target string)(installed strin
}
return
}

func (r *SpigotInstaller)ListVersions(snapshot bool)(versions []string, err error){
versions = []string{"latest"}
return
}
13 changes: 13 additions & 0 deletions vanilla_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ func (r *VanillaInstaller)Install(path, name string, target string)(installed st
return "", &VersionNotFoundErr{ foundVersion }
}

func (r *VanillaInstaller)ListVersions(snapshot bool)(versions []string, err error){
vs, err := r.GetVersions()
if err != nil {
return
}
for _, v := range vs.Versions {
if v.Type == "release" || snapshot {
versions = append(versions, v.Id)
}
}
return
}

func (r *VanillaInstaller)GetVersions()(res VanillaVersions, err error){
if err = DefaultHTTPClient.GetJson(r.ManifestUrl, &res); err != nil {
return
Expand Down

0 comments on commit 79e046b

Please sign in to comment.