11package 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
8792print_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