@@ -4,19 +4,18 @@ mod cli;
44mod engine;
55
66use anyhow:: { Context , Result } ;
7- use owo_colors:: OwoColorize ;
87
98fn main ( ) -> Result < ( ) > {
109 // Parse arguments
1110 use lexopt:: prelude:: * ;
1211 let mut parser = lexopt:: Parser :: from_env ( ) ;
1312 let mut cmd = None ;
14- let mut arg = None ;
13+ let mut args : Vec < String > = Vec :: new ( ) ;
1514
1615 while let Some ( arg_val) = parser. next ( ) ? {
1716 match arg_val {
1817 Value ( v) if cmd. is_none ( ) => cmd = Some ( v. string ( ) ?) ,
19- Value ( v) if arg . is_none ( ) => arg = Some ( v. string ( ) ?) ,
18+ Value ( v) => args . push ( v. string ( ) ?) ,
2019 Long ( "help" ) | Short ( 'h' ) => {
2120 cli:: print_help ( ) ;
2221 return Ok ( ( ) ) ;
@@ -36,57 +35,64 @@ fn main() -> Result<()> {
3635
3736 let command = cmd. unwrap ( ) ;
3837
39- // Show banner only for interactive commands, not plumbing
38+ // Show banner only for interactive commands
4039 if command != "help" && command != "version" {
4140 cli:: print_header ( ) ;
4241 }
4342
44- let mut app = engine:: App :: new ( ) . context ( "Engine initialization failed" ) ?;
43+ // Determine lock requirement
44+ let needs_lock = match command. as_str ( ) {
45+ "install" | "remove" | "update" | "clean" | "upgrade" | "full-upgrade" | "autoremove" | "add-repo" => true ,
46+ _ => false ,
47+ } ;
48+
49+ let mut app = engine:: App :: new ( needs_lock) . context ( "Engine initialization failed" ) ?;
4550
4651 match command. as_str ( ) {
4752 "install" => {
48- if let Some ( pkg ) = arg {
49- app . install ( pkg ) ? ;
53+ if args . is_empty ( ) {
54+ cli :: log_error ( "Usage: legend install <package1> [package2] ..." . to_string ( ) ) ;
5055 } else {
51- cli :: log_error ( "Usage: legend install <package>" . to_string ( ) ) ;
56+ app . install ( args ) ? ;
5257 }
5358 }
5459 "remove" => {
55- if let Some ( pkg ) = arg {
56- app . remove ( pkg ) ? ;
60+ if args . is_empty ( ) {
61+ cli :: log_error ( "Usage: legend remove <package1> ..." . to_string ( ) ) ;
5762 } else {
58- cli :: log_error ( "Usage: legend remove <package>" . to_string ( ) ) ;
63+ app . remove ( args ) ? ;
5964 }
6065 }
61- "list" => {
62- app. list ( ) ?;
63- }
64- "update" => {
65- app. update ( ) ?;
66- }
66+ "update" => app. update ( ) ?,
67+ "upgrade" => app. upgrade ( false ) ?,
68+ "full-upgrade" => app. upgrade ( true ) ?,
69+ "autoremove" => app. autoremove ( ) ?,
70+ "list" => app. list ( ) ?,
6771 "search" => {
68- if let Some ( term) = arg {
69- app. search ( term) ?;
70- } else {
72+ if args. is_empty ( ) {
7173 cli:: log_error ( "Usage: legend search <term>" . to_string ( ) ) ;
74+ } else {
75+ app. search ( args[ 0 ] . clone ( ) ) ?;
7276 }
7377 }
7478 "show" => {
75- if let Some ( pkg) = arg {
76- app. show ( pkg) ?;
77- } else {
79+ if args. is_empty ( ) {
7880 cli:: log_error ( "Usage: legend show <package>" . to_string ( ) ) ;
81+ } else {
82+ app. show ( args[ 0 ] . clone ( ) ) ?;
7983 }
8084 }
81- "clean" => {
82- app. clean ( ) ?;
83- }
84- "help" => {
85- cli:: print_help ( ) ;
86- }
87- _ => {
88- cli :: log_error ( format ! ( "Unknown command '{}'" , command ) ) ;
85+ "clean" => app . clean ( ) ? ,
86+ "list-repos" => app. list_repos ( ) ?,
87+ "add-repo" => {
88+ if args . is_empty ( ) {
89+ cli:: log_error ( "Usage: legend add-repo \" deb http://... \" " . to_string ( ) ) ;
90+ } else {
91+ app . add_repo ( args . join ( " " ) ) ? ;
92+ }
8993 }
94+ "help" => cli:: print_help ( ) ,
95+ _ => cli:: log_error ( format ! ( "Unknown command '{}'" , command) ) ,
9096 }
9197
9298 Ok ( ( ) )
0 commit comments