Skip to content

Commit 413a4bc

Browse files
committed
refact!: port to Jule v0.1.4
includes some other improvements aswell
1 parent de4700f commit 413a4bc

7 files changed

Lines changed: 53 additions & 35 deletions

File tree

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ all: build
1313

1414
build:
1515
mkdir -p build
16-
$(JULEC) $(JULECFLAGS) .
16+
$(JULEC) $(JULECFLAGS) src
1717

1818
run: build
1919
./build/$(BINARY)
2020

2121
test:
22-
$(JULEC) test .
22+
$(JULEC) test src
2323

2424
format:
25-
julefmt -w .
25+
julefmt -w src
2626

2727
clean:
28-
rm -rf bin dist
28+
rm -rf build bin dist
2929

3030
.PHONY: all build run test format clean

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ jpu is written in [Jule], a low-level, compiled, memory-safe fast programming la
55
The tool's main goal is to provide a **faster** [ProtonUp] implementation. The original project is written in Python, which is quite slow.
66

77
Supported Jule versions:
8-
- `0.1.2` \*
9-
- `0.1.3@master`
10-
11-
<sub>\* Some commands may not work or give unexpected results.</sub>
8+
- `0.1.4`
9+
- `0.1.5@master`
1210

1311
## Installation
1412

@@ -32,8 +30,8 @@ jpu
3230
```
3331

3432
Available arguments:
35-
- `--dir`: Set the target installation directory (default: `~/.steam/root/compatibilitytools.d/`)
36-
- `--help`: Display CLI information
33+
- `--dir` (`-d`): Set the target installation directory (default: `~/.steam/root/compatibilitytools.d/`)
34+
- `--help` (`-h`): Display CLI information
3735

3836
## Building from source
3937
To build jpu from source, you need to have the JuleC compiler (and [make]) installed. Please refer to [Jule's Manual][julec_installation].<br>

cliq

Submodule cliq deleted from 53f717a

snapbox

File renamed without changes.

jpu/jpu.jule renamed to src/jpu.jule

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct Proton {
3333

3434
impl Proton {
3535
fn Download(self)! {
36-
os::Dir.Create(tempDir) else {}
36+
os::Mkdir(tempDir) else {}
3737

3838
tempProtonFile := tempDir + "/" + self.tagName + ".tar.gz"
3939
tempChecksumFile := tempDir + "/" + self.tagName + ".sha512sum"
@@ -49,10 +49,10 @@ impl Proton {
4949
}
5050

5151
println(" Validating checksums...")
52-
tempProtonContent := os::File.Read(tempProtonFile) else {
52+
tempProtonContent := os::ReadFile(tempProtonFile) else {
5353
error("Failed to read `" + tempProtonFile + "`")
5454
}
55-
tempChecksumContent := os::File.Read(tempChecksumFile) else {
55+
tempChecksumContent := os::ReadFile(tempChecksumFile) else {
5656
error("Failed to read `" + tempChecksumFile + "`")
5757
}
5858

@@ -137,7 +137,7 @@ fn GetProton(tagRaw: str, urlRaw: str, mut installDir: str)!: Proton {
137137
error("Aborted")
138138
}
139139

140-
os::Dir.Read(protonDir) else {
140+
os::ReadDir(protonDir) else {
141141
ret Proton{tagName, downloadURLs, protonDir}
142142
}
143143

@@ -168,17 +168,14 @@ fn getJSONValueN(data: str, key: str, n: int)!: []str {
168168
}
169169

170170
fn extractTarGz(file: str, dir: str)! {
171-
os::Dir.Create(dir) else {
171+
os::Mkdir(dir) else {
172172
error(error)
173173
}
174174

175175
mut cmd := os::Cmd.New("tar")
176176
cmd.Args = ["-xzf", file, "-C", dir]
177177

178-
cmd.Spawn() else {
179-
error(error)
180-
}
181-
cmd.Wait() else {
178+
cmd.Run() else {
182179
error(error)
183180
}
184181
}
@@ -187,8 +184,8 @@ fn cleanup(additional: []str) {
187184
println(" Cleaning up...")
188185

189186
for _, f in additional {
190-
os::File.Remove(f) else {}
187+
os::Remove(f) else {}
191188
}
192189

193-
os::Dir.Remove(tempDir) else {}
190+
os::Rmdir(tempDir) else {}
194191
}

main.jule renamed to src/main.jule

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
// Use of this source code is governed by the BSD 3-Clause License.
44
// See the LICENSE file for details.
55

6-
use cq "cliq"
76
use cy "colorify"
8-
use "jpu"
7+
use "std/flag"
8+
use "std/os"
9+
use ss "std/strings"
910
use "std/sys"
1011

1112
const protonGeURL = "https://api.github.com/repos/GloriousEggroll/proton-ge-custom/releases"
@@ -26,24 +27,31 @@ static errorMessage = cy::Colorify("!", cy::Style{
2627
})
2728

2829
fn main() {
29-
mut cq := cq::Builder{
30-
Args: {
31-
"dir": defaultInstallDir,
32-
},
33-
}.Help().Build()
30+
mut fs := flag::FlagSet.New()
3431

35-
cq.GetCLI()
36-
cq.Parse()
32+
let mut dir: str
33+
let mut help: bool
3734

38-
mut dir := str(cq.Get("dir"))
35+
fs.AddVar[str](unsafe { (&str)(&dir) }, "dir", 'd', "Set target installation directory")
36+
fs.AddVar[bool](unsafe { (&bool)(&help) }, "help", 'h', "Show this help message")
3937

40-
println(infoMessage + " No arguments provided. Assuming you want to update.")
38+
fs.Parse(os::Args()[1:]) else {
39+
handleErr("Failed to parse flags")
40+
ret
41+
}
42+
43+
if help {
44+
println(autoHelp(fs))
45+
ret
46+
}
47+
48+
println(infoMessage + " No arguments provided. Assuming an update.")
4149
update(dir)
4250
}
4351

4452
fn update(mut installDir: str) {
4553
println(infoMessage + " Getting the latest Proton-GE release...")
46-
proton := jpu::GetProton("", protonGeURL, installDir) else {
54+
proton := GetProton("", protonGeURL, installDir) else {
4755
handleErr(error)
4856
ret
4957
}
@@ -62,4 +70,20 @@ fn handleErr(err: any) {
6270
print(errorMessage + " ")
6371
println(err)
6472
sys::Exit(1)
73+
}
74+
75+
fn autoHelp(mut flags: &flag::FlagSet): (res: str) {
76+
mut maxWidth := 0
77+
for _, f in flags.Flags() {
78+
if len(f.Name()) > maxWidth {
79+
maxWidth = len(f.Name())
80+
}
81+
}
82+
83+
res = "Usage: jpu [flags]\n\nFlags:\n"
84+
for _, f in flags.Flags() {
85+
res += " --" + f.Name() + ss::Repeat(" ", maxWidth-len(f.Name())) + " " + f.What() + "\n"
86+
}
87+
88+
ret res
6589
}

0 commit comments

Comments
 (0)