11package commands
22
3+ import " core:fmt"
4+ import " core:strings"
5+
36import errors " ../core/errors"
47import xbps " ../core/xbps"
58import utils " ../utils"
6- import " core:fmt"
79
810// Remove command implementation
911remove_run :: proc (args: []string , config: ^Config) -> int {
@@ -25,52 +27,53 @@ remove_run :: proc(args: []string, config: ^Config) -> int {
2527 return 1
2628 }
2729
28- exit_code := 0
29- for pkg in args {
30- if xbps_uninstall (pkg, config) != 0 {
31- exit_code = 1
32- }
33- }
34-
35- return exit_code
36- }
37-
38- // Remove orphan packages (xbps-remove -o)
39- remove_orphans :: proc (config: ^Config) -> int {
40- cmd := make ([dynamic ]string , context .temp_allocator)
30+ cmd: [dynamic ; 64 ]string
4131
42- // Need sudo for system operations (unless dry-run)
4332 if !config.dry_run {
4433 append (&cmd, " sudo" )
4534 }
46- append (&cmd, " xbps-remove" , " -o " )
35+ append (&cmd, " xbps-remove" )
4736
4837 if config.dry_run {
4938 append (&cmd, " -n" )
5039 }
5140 if config.yes {
5241 append (&cmd, " -y" )
5342 }
43+ if config.recursive {
44+ append (&cmd, " -R" )
45+ }
5446 if config.verbose {
5547 append (&cmd, " -v" )
5648 }
5749 if len (config.rootdir) > 0 {
5850 append (&cmd, " -r" , config.rootdir)
5951 }
6052
61- errors.log_info (" Removing orphan packages..." )
62- return xbps.remove_orphans (config.yes, utils.run_command)
53+ for pkg in args {
54+ append (&cmd, pkg)
55+ }
56+
57+ errors.log_info (" Removing %s..." , strings.join (args[:], " , " , context .temp_allocator))
58+
59+ if utils.run_command (cmd[:]) == 0 {
60+ errors.log_info (" Successfully removed package(s)" )
61+ return 0
62+ }
63+
64+ errors.log_error (" xbps-remove failed" )
65+ return 1
6366}
6467
65- // Clean package cache (xbps-remove -O )
66- remove_cache :: proc (config: ^Config) -> int {
67- cmd := make ( [dynamic ]string , context .temp_allocator)
68+ // Remove orphan packages (xbps-remove -o )
69+ remove_orphans :: proc (config: ^Config) -> int {
70+ cmd: [dynamic ; 16 ]string
6871
69- // Need sudo for cache operations (unless dry-run)
72+ // Need sudo for system operations (unless dry-run)
7073 if !config.dry_run {
7174 append (&cmd, " sudo" )
7275 }
73- append (&cmd, " xbps-remove" , " -O " )
76+ append (&cmd, " xbps-remove" , " -o " )
7477
7578 if config.dry_run {
7679 append (&cmd, " -n" )
@@ -85,48 +88,33 @@ remove_cache :: proc(config: ^Config) -> int {
8588 append (&cmd, " -r" , config.rootdir)
8689 }
8790
88- errors.log_info (" Cleaning package cache ..." )
89- return xbps.clean_cache ( utils.run_command)
91+ errors.log_info (" Removing orphan packages ..." )
92+ return xbps.remove_orphans (config.yes, utils.run_command)
9093}
9194
92- // Remove a package using xbps-remove
93- xbps_uninstall :: proc (pkg_name: string , config: ^Config) -> int {
94- if len (pkg_name) == 0 {
95- errors.log_error (" Invalid package name" )
96- return -1
97- }
98-
99- errors.log_info (" Removing %s..." , pkg_name)
100-
101- cmd := make ([dynamic ]string , context .temp_allocator)
95+ // Clean package cache (xbps-remove -O)
96+ remove_cache :: proc (config: ^Config) -> int {
97+ cmd: [dynamic ; 16 ]string
10298
103- // Need sudo for package removal (unless dry-run)
99+ // Need sudo for cache operations (unless dry-run)
104100 if !config.dry_run {
105101 append (&cmd, " sudo" )
106102 }
107- append (&cmd, " xbps-remove" , pkg_name )
103+ append (&cmd, " xbps-remove" , " -O " )
108104
109105 if config.dry_run {
110106 append (&cmd, " -n" )
111107 }
112108 if config.yes {
113109 append (&cmd, " -y" )
114110 }
115- if config.recursive {
116- append (&cmd, " -R" )
117- }
118111 if config.verbose {
119112 append (&cmd, " -v" )
120113 }
121114 if len (config.rootdir) > 0 {
122115 append (&cmd, " -r" , config.rootdir)
123116 }
124117
125- if utils.run_command (cmd[:]) == 0 {
126- errors.log_info (" Successfully removed %s" , pkg_name)
127- return 0
128- }
129-
130- errors.log_error (" xbps-remove failed for %s" , pkg_name)
131- return -1
118+ errors.log_info (" Cleaning package cache..." )
119+ return xbps.clean_cache (utils.run_command)
132120}
0 commit comments