Skip to content

Commit e8b5d8e

Browse files
committed
odin
1 parent 4ddf853 commit e8b5d8e

12 files changed

Lines changed: 132 additions & 115 deletions

File tree

vuruV2/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/

vuruV2/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ A package manager frontend for the VUP (Void User Packages) repository, rewritte
66

77
### Requirements
88

9-
- Odin compiler (latest)
9+
- Odin compiler (latest)
10+
>Odin isn't on Void repo's but it does exist in VUP
11+
12+
```bash
13+
vuru -S odin
14+
```
1015
- POSIX-compatible system (Linux)
1116

1217
### Compile
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package vuru
1+
package common
22

33
import "core:fmt"
44
import "core:os"
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package vuru
1+
package common
22

33
import "core:encoding/json"
44
import "core:fmt"
@@ -61,8 +61,8 @@ fetch_url :: proc(url: string, allocator := context.allocator) -> (content: stri
6161
}
6262

6363
// Create pipe for reading curl output
64-
pipe_fds: [2]c.int
65-
if posix.pipe(&pipe_fds) != .SUCCESS {
64+
pipe_fds: [2]posix.FD
65+
if posix.pipe(&pipe_fds) != .OK {
6666
log_error("pipe() failed")
6767
return "", false
6868
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package vuru
1+
package common
22

33
import "core:fmt"
44
import "core:os"
@@ -44,8 +44,8 @@ is_tty :: proc() -> bool {
4444
return cached
4545
}
4646
result := posix.isatty(posix.STDOUT_FILENO)
47-
_is_tty = result
48-
return result
47+
_is_tty = bool(result)
48+
return bool(result)
4949
}
5050

5151
log_info :: proc(format: string, args: ..any) {

vuruV2/src/main.odin

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package vuru
22

3+
import "common"
34
import "core:fmt"
45
import "core:os"
56
import "core:strings"
@@ -84,7 +85,7 @@ parse_args :: proc(args: []string) -> (opts: Options, ok: bool) {
8485
print_help(args[0])
8586
os.exit(0)
8687
case:
87-
log_error("Unknown option: -%c", c)
88+
common.log_error("Unknown option: -%c", c)
8889
return {}, false
8990
}
9091
}
@@ -100,7 +101,7 @@ parse_args :: proc(args: []string) -> (opts: Options, ok: bool) {
100101
print_help(args[0])
101102
os.exit(0)
102103
case:
103-
log_error("Unknown option: %s", arg)
104+
common.log_error("Unknown option: %s", arg)
104105
return {}, false
105106
}
106107
}
@@ -137,85 +138,85 @@ main :: proc() {
137138

138139
// Handle -u flag without explicit command
139140
if opts.update && opts.command == .None {
140-
idx, idx_ok := index_load_or_fetch(INDEX_URL, opts.sync)
141+
idx, idx_ok := common.index_load_or_fetch(INDEX_URL, opts.sync)
141142
if !idx_ok {
142-
log_error("Failed to load package index")
143+
common.log_error("Failed to load package index")
143144
os.exit(1)
144145
}
145-
defer index_free(&idx)
146+
defer common.index_free(&idx)
146147

147148
xbps_upgrade_all(&idx, opts.yes)
148149
return
149150
}
150151

151152
// Just sync the index
152153
if opts.sync && opts.command == .None && len(opts.args) == 0 {
153-
idx, idx_ok := index_load_or_fetch(INDEX_URL, true)
154+
idx, idx_ok := common.index_load_or_fetch(INDEX_URL, true)
154155
if !idx_ok {
155-
log_error("Failed to load package index")
156+
common.log_error("Failed to load package index")
156157
os.exit(1)
157158
}
158-
defer index_free(&idx)
159+
defer common.index_free(&idx)
159160

160-
log_info("Package index synchronized")
161+
common.log_info("Package index synchronized")
161162
return
162163
}
163164

164165
// Execute command
165166
switch opts.command {
166167
case .Search:
167168
if len(opts.args) == 0 {
168-
log_error("search requires a query argument")
169+
common.log_error("search requires a query argument")
169170
os.exit(1)
170171
}
171-
idx, idx_ok := index_load_or_fetch(INDEX_URL, opts.sync)
172+
idx, idx_ok := common.index_load_or_fetch(INDEX_URL, opts.sync)
172173
if !idx_ok {
173-
log_error("Failed to load package index")
174+
common.log_error("Failed to load package index")
174175
os.exit(1)
175176
}
176-
defer index_free(&idx)
177+
defer common.index_free(&idx)
177178

178179
xbps_search(&idx, opts.args[0])
179180

180181
case .Install:
181182
if len(opts.args) == 0 {
182-
log_error("install requires at least one package name")
183+
common.log_error("install requires at least one package name")
183184
os.exit(1)
184185
}
185-
idx, idx_ok := index_load_or_fetch(INDEX_URL, opts.sync)
186+
idx, idx_ok := common.index_load_or_fetch(INDEX_URL, opts.sync)
186187
if !idx_ok {
187-
log_error("Failed to load package index")
188+
common.log_error("Failed to load package index")
188189
os.exit(1)
189190
}
190-
defer index_free(&idx)
191+
defer common.index_free(&idx)
191192

192193
for pkg in opts.args {
193194
xbps_install_pkg(&idx, pkg, opts.yes)
194195
}
195196

196197
case .Remove:
197198
if len(opts.args) == 0 {
198-
log_error("remove requires at least one package name")
199+
common.log_error("remove requires at least one package name")
199200
os.exit(1)
200201
}
201-
idx, idx_ok := index_load_or_fetch(INDEX_URL, opts.sync)
202+
idx, idx_ok := common.index_load_or_fetch(INDEX_URL, opts.sync)
202203
if !idx_ok {
203-
log_error("Failed to load package index")
204+
common.log_error("Failed to load package index")
204205
os.exit(1)
205206
}
206-
defer index_free(&idx)
207+
defer common.index_free(&idx)
207208

208209
for pkg in opts.args {
209210
xbps_remove_pkg(&idx, pkg, opts.yes)
210211
}
211212

212213
case .Update:
213-
idx, idx_ok := index_load_or_fetch(INDEX_URL, opts.sync)
214+
idx, idx_ok := common.index_load_or_fetch(INDEX_URL, opts.sync)
214215
if !idx_ok {
215-
log_error("Failed to load package index")
216+
common.log_error("Failed to load package index")
216217
os.exit(1)
217218
}
218-
defer index_free(&idx)
219+
defer common.index_free(&idx)
219220

220221
xbps_upgrade_all(&idx, opts.yes)
221222

vuruV2/src/xbps/common.odin

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
package xbps
22

3+
import common "../common"
4+
35
// Re-export functions under vuru-compatible names
4-
import vuru ".."
6+
57

68
// Wrapper functions that match the calling convention from main.odin
7-
xbps_install_pkg :: proc(idx: ^vuru.Index, pkg_name: string, yes: bool) -> bool {
9+
xbps_install_pkg :: proc(idx: ^common.Index, pkg_name: string, yes: bool) -> bool {
810
return install_pkg(idx, pkg_name, yes)
911
}
1012

11-
xbps_remove_pkg :: proc(idx: ^vuru.Index, pkg_name: string, yes: bool) -> bool {
13+
xbps_remove_pkg :: proc(idx: ^common.Index, pkg_name: string, yes: bool) -> bool {
1214
return remove_pkg(idx, pkg_name, yes)
1315
}
1416

15-
xbps_upgrade_all :: proc(idx: ^vuru.Index, yes: bool) -> bool {
17+
xbps_upgrade_all :: proc(idx: ^common.Index, yes: bool) -> bool {
1618
return upgrade_all(idx, yes)
1719
}
1820

19-
xbps_search :: proc(idx: ^vuru.Index, query: string) {
21+
xbps_search :: proc(idx: ^common.Index, query: string) {
2022
search(idx, query)
2123
}

vuruV2/src/xbps/diff.odin

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package xbps
22

3+
import common "../common"
4+
35
import "core:fmt"
46
import "core:strings"
5-
import vuru ".."
7+
68

79
// Show a simple diff between old and new content
810
show_diff :: proc(old_content: string, new_content: string) {
@@ -14,8 +16,8 @@ show_diff :: proc(old_content: string, new_content: string) {
1416
}
1517

1618
fmt.println()
17-
fmt.printf("%s--- old%s\n", vuru.color_code(.Red), vuru.color_code(.Reset))
18-
fmt.printf("%s+++ new%s\n", vuru.color_code(.Green), vuru.color_code(.Reset))
19+
fmt.printf("%s--- old%s\n", common.color_code(.Red), common.color_code(.Reset))
20+
fmt.printf("%s+++ new%s\n", common.color_code(.Green), common.color_code(.Reset))
1921
fmt.println()
2022

2123
// Simple line-by-line diff
@@ -65,17 +67,17 @@ show_diff :: proc(old_content: string, new_content: string) {
6567
// Changed line
6668
if i < len(old_lines) && len(old_line) > 0 {
6769
fmt.printf("%s-%4d | %s%s\n",
68-
vuru.color_code(.Red),
70+
common.color_code(.Red),
6971
i + 1,
7072
old_line,
71-
vuru.color_code(.Reset))
73+
common.color_code(.Reset))
7274
}
7375
if i < len(new_lines) && len(new_line) > 0 {
7476
fmt.printf("%s+%4d | %s%s\n",
75-
vuru.color_code(.Green),
77+
common.color_code(.Green),
7678
i + 1,
7779
new_line,
78-
vuru.color_code(.Reset))
80+
common.color_code(.Reset))
7981
}
8082
}
8183
}

vuruV2/src/xbps/install.odin

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,69 @@
11
package xbps
22

3-
import vuru ".."
3+
import common "../common"
4+
5+
import "core:fmt"
6+
import "core:strings"
7+
8+
49

510
// Install a package from the VUP index
6-
install_pkg :: proc(idx: ^vuru.Index, pkg_name: string, yes: bool) -> bool {
7-
if idx == nil || !vuru.is_valid_pkg_name(pkg_name) {
8-
vuru.log_error("Invalid arguments")
11+
install_pkg :: proc(idx: ^common.Index, pkg_name: string, yes: bool) -> bool {
12+
if idx == nil || !common.is_valid_pkg_name(pkg_name) {
13+
common.log_error("Invalid arguments")
914
return false
1015
}
1116

12-
pkg, found := vuru.index_get_package(idx, pkg_name)
17+
pkg, found := common.index_get_package(idx, pkg_name)
1318
if !found {
14-
vuru.log_error("Package '%s' not found in VUP index", pkg_name)
19+
common.log_error("Package '%s' not found in VUP index", pkg_name)
1520
return false
1621
}
1722

1823
if len(pkg.repo_url) == 0 || len(pkg.category) == 0 {
19-
vuru.log_error("Invalid package metadata for '%s'", pkg_name)
24+
common.log_error("Invalid package metadata for '%s'", pkg_name)
2025
return false
2126
}
2227

23-
vuru.log_info("Found %s in category '%s'", pkg_name, pkg.category)
28+
common.log_info("Found %s in category '%s'", pkg_name, pkg.category)
2429

2530
// Fetch template for review
26-
vuru.log_info("Fetching template for review...")
27-
new_tmpl, tmpl_ok := vuru.fetch_template(pkg.category, pkg_name)
31+
common.log_info("Fetching template for review...")
32+
new_tmpl, tmpl_ok := common.fetch_template(pkg.category, pkg_name)
2833
if !tmpl_ok {
29-
vuru.log_error("Failed to fetch template")
34+
common.log_error("Failed to fetch template")
3035
return false
3136
}
3237
defer delete(new_tmpl)
3338

3439
// Get cached template for diff
35-
cached_tmpl, cached_ok := vuru.cache_get_template(pkg_name)
40+
cached_tmpl, cached_ok := common.cache_get_template(pkg_name)
3641
defer if cached_ok do delete(cached_tmpl)
3742

3843
// Review unless --yes flag
3944
if !yes {
4045
if cached_ok {
4146
// Show diff if template changed
4247
if cached_tmpl != new_tmpl {
43-
vuru.log_warn("Template has changed since last install:")
48+
common.log_warn("Template has changed since last install:")
4449
show_diff(cached_tmpl, new_tmpl)
4550
} else {
46-
vuru.log_info("Template unchanged since last install")
51+
common.log_info("Template unchanged since last install")
4752
}
4853
} else {
4954
// Show full template for new packages
50-
vuru.log_info("Template for %s:", pkg_name)
55+
common.log_info("Template for %s:", pkg_name)
5156
print_template(new_tmpl)
5257
}
5358

54-
if !vuru.prompt_yes_no("Proceed with installation?") {
55-
vuru.log_info("Installation cancelled")
59+
if !common.prompt_yes_no("Proceed with installation?") {
60+
common.log_info("Installation cancelled")
5661
return false
5762
}
5863
}
5964

6065
// Run xbps-install
61-
vuru.log_info("Installing %s...", pkg_name)
66+
common.log_info("Installing %s...", pkg_name)
6267

6368
args: [dynamic]string
6469
defer delete(args)
@@ -71,23 +76,20 @@ install_pkg :: proc(idx: ^vuru.Index, pkg_name: string, yes: bool) -> bool {
7176
}
7277
append(&args, pkg_name)
7378

74-
if !vuru.exec_command(args[:], use_sudo = true) {
75-
vuru.log_error("Failed to install %s", pkg_name)
79+
if !common.exec_command(args[:], use_sudo = true) {
80+
common.log_error("Failed to install %s", pkg_name)
7681
return false
7782
}
7883

7984
// Cache the template
80-
vuru.cache_set_template(pkg_name, new_tmpl)
85+
common.cache_set_template(pkg_name, new_tmpl)
8186

82-
vuru.log_success("Successfully installed %s", pkg_name)
87+
common.log_success("Successfully installed %s", pkg_name)
8388
return true
8489
}
8590

8691
// Print template with line numbers
8792
print_template :: proc(content: string) {
88-
import "core:strings"
89-
import "core:fmt"
90-
9193
lines := strings.split_lines(content)
9294
defer delete(lines)
9395

0 commit comments

Comments
 (0)