Skip to content

Commit b141844

Browse files
committed
Implement essential commands
0 parents  commit b141844

File tree

16 files changed

+1844
-0
lines changed

16 files changed

+1844
-0
lines changed

.github/workflows/release.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Build Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
create_release:
10+
name: Create release
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
with:
16+
fetch-depth: 0
17+
- name: Read info
18+
id: tags
19+
shell: bash
20+
run: |
21+
echo ::set-output name=TAG::${GITHUB_REF/refs\/tags\//}
22+
- name: Create Release
23+
id: create_release
24+
uses: actions/create-release@master
25+
env:
26+
GITHUB_TOKEN: ${{ github.token }}
27+
with:
28+
tag_name: ${{ steps.tags.outputs.tag }}
29+
release_name: ${{ steps.tags.outputs.tag }}
30+
draft: false
31+
prerelease: false
32+
publish_binaries:
33+
name: Release Go Binary
34+
runs-on: ubuntu-latest
35+
strategy:
36+
matrix:
37+
goos: [linux, windows, darwin]
38+
goarch: [amd64, arm64]
39+
exclude:
40+
- goarch: arm64
41+
goos: windows
42+
steps:
43+
- name: Checkout
44+
uses: actions/checkout@v3
45+
- name: Read info
46+
id: tags
47+
shell: bash
48+
run: |
49+
echo ::set-output name=TAG::${GITHUB_REF/refs\/tags\//}
50+
- name: Build and Publish
51+
uses: wangyoucao577/go-release-action@v1.28
52+
with:
53+
github_token: ${{ secrets.GITHUB_TOKEN }}
54+
goos: ${{ matrix.goos }}
55+
goarch: ${{ matrix.goarch }}
56+
binary_name: codegame-java
57+
asset_name: codegame-cli-java-${{matrix.goos}}-${{matrix.goarch}}
58+
extra_files: LICENSE README.md
59+
release_tag: ${{ steps.tags.outputs.tag }}

LICENSE

Lines changed: 675 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# codegame-cli-java
2+
3+
The Java module for [codegame-cli](https://github.com/code-game-project/codegame-cli).
4+
5+
**This application is not intended for standalone use and should only ever be run by codegame-cli.**
6+
7+
## License
8+
9+
Copyright (c) 2022 Julian Hofmann
10+
11+
This program is free software: you can redistribute it and/or modify
12+
it under the terms of the GNU General Public License as published by
13+
the Free Software Foundation, either version 3 of the License, or
14+
(at your option) any later version.
15+
16+
This program is distributed in the hope that it will be useful,
17+
but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
GNU General Public License for more details.
20+
21+
You should have received a copy of the GNU General Public License
22+
along with this program. If not, see <http://www.gnu.org/licenses/>.

build.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package main
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
"os"
7+
"strings"
8+
9+
"github.com/Bananenpro/cli"
10+
"github.com/code-game-project/go-utils/cgfile"
11+
"github.com/code-game-project/go-utils/modules"
12+
)
13+
14+
func Build() error {
15+
config, err := cgfile.LoadCodeGameFile("")
16+
if err != nil {
17+
return err
18+
}
19+
20+
data, err := modules.ReadCommandConfig[modules.BuildData]()
21+
if err != nil {
22+
return err
23+
}
24+
25+
packageConf, ok := config.LangConfig["package"]
26+
if !ok {
27+
return errors.New("Missing language config field `package` in .codegame.json!")
28+
}
29+
packageName := packageConf.(string)
30+
if packageConf == "" {
31+
return errors.New("Empty language config field `package` in .codegame.json!")
32+
}
33+
34+
if data.OS != "" || data.Arch != "" {
35+
return errors.New("Cross compilation is not supported for Java applications.")
36+
}
37+
38+
switch config.Type {
39+
case "client":
40+
return buildClient(config.Game, packageName, data.Output, config.URL)
41+
default:
42+
return fmt.Errorf("Unknown project type: %s", config.Type)
43+
}
44+
}
45+
46+
func buildClient(gameName, packageName, output, url string) error {
47+
cli.BeginLoading("Building...")
48+
// TODO
49+
cli.FinishLoading()
50+
return nil
51+
}
52+
53+
func replaceInFile(filename, old, new string) error {
54+
content, err := os.ReadFile(filename)
55+
if err != nil {
56+
return fmt.Errorf("Failed to replace '%s' with '%s' in '%s': %s", old, new, filename, err)
57+
}
58+
content = []byte(strings.ReplaceAll(string(content), old, new))
59+
err = os.WriteFile(filename, content, 0o644)
60+
if err != nil {
61+
return fmt.Errorf("Failed to replace '%s' with '%s' in '%s': %s", old, new, filename, err)
62+
}
63+
return nil
64+
}

go.mod

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module github.com/code-game-project/codegame-cli-java
2+
3+
go 1.18
4+
5+
require (
6+
github.com/Bananenpro/cli v0.3.0
7+
github.com/code-game-project/go-utils v0.3.1
8+
)
9+
10+
require (
11+
github.com/AlecAivazis/survey/v2 v2.3.6 // indirect
12+
github.com/adrg/xdg v0.4.0 // indirect
13+
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
14+
github.com/mattn/go-colorable v0.1.13 // indirect
15+
github.com/mattn/go-isatty v0.0.16 // indirect
16+
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
17+
golang.org/x/sys v0.3.0 // indirect
18+
golang.org/x/term v0.3.0 // indirect
19+
golang.org/x/text v0.5.0 // indirect
20+
)

go.sum

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
github.com/AlecAivazis/survey/v2 v2.3.6 h1:NvTuVHISgTHEHeBFqt6BHOe4Ny/NwGZr7w+F8S9ziyw=
2+
github.com/AlecAivazis/survey/v2 v2.3.6/go.mod h1:4AuI9b7RjAR+G7v9+C4YSlX/YL3K3cWNXgWXOhllqvI=
3+
github.com/Bananenpro/cli v0.3.0 h1:gQOzc22yv+rePT0nRYva1ccdva3hTGyUwrGdcnXqchU=
4+
github.com/Bananenpro/cli v0.3.0/go.mod h1:JBXpIAXo/D0rlsfgCViQBicjcJY6UWUldmxvKM+ijRc=
5+
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
6+
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
7+
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
8+
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
9+
github.com/code-game-project/go-utils v0.3.1 h1:c1qKSPWbVVc4ygU3YBl0wNBu1yjMDoGzGLAWePK9sUo=
10+
github.com/code-game-project/go-utils v0.3.1/go.mod h1:/ws9iYkZCnZvS9g2aqdxKwSnU5AEeI7SE1mbB+x4ggg=
11+
github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
12+
github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
13+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
14+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
15+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
16+
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=
17+
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
18+
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
19+
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
20+
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
21+
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
22+
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
23+
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
24+
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
25+
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
26+
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
27+
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
28+
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
29+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
30+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
31+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
32+
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
33+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
34+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
35+
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
36+
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
37+
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
38+
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
39+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
40+
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
41+
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
42+
golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
43+
golang.org/x/term v0.3.0 h1:qoo4akIqOcDME5bhc/NgxUdovd6BSS2uMsVjB56q1xI=
44+
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
45+
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
46+
golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM=
47+
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
48+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
49+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
50+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
51+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

main.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"path/filepath"
7+
8+
"github.com/Bananenpro/cli"
9+
)
10+
11+
func main() {
12+
if len(os.Args) < 2 {
13+
fmt.Fprintf(os.Stderr, "USAGE: %s <command> [...]\n", os.Args[0])
14+
os.Exit(1)
15+
}
16+
17+
workingDir, err := os.Getwd()
18+
if err != nil {
19+
fmt.Fprintln(os.Stderr, err)
20+
}
21+
projectName := filepath.Base(workingDir)
22+
23+
switch os.Args[1] {
24+
case "new":
25+
if len(os.Args) < 3 {
26+
fmt.Fprintf(os.Stderr, "USAGE: %s new client\n", os.Args[0])
27+
os.Exit(1)
28+
}
29+
switch os.Args[2] {
30+
case "client":
31+
err = CreateNewClient(projectName)
32+
default:
33+
fmt.Fprintln(os.Stderr, "Unknown project type:", os.Args[2])
34+
os.Exit(1)
35+
}
36+
case "update":
37+
err = Update(projectName)
38+
case "run":
39+
err = Run()
40+
case "build":
41+
err = Build()
42+
default:
43+
fmt.Fprintln(os.Stderr, "Unknown command:", os.Args[1])
44+
os.Exit(1)
45+
}
46+
if err != nil {
47+
if err != cli.ErrCanceled {
48+
cli.Error(err.Error())
49+
}
50+
os.Exit(1)
51+
}
52+
}

0 commit comments

Comments
 (0)