11use clap:: Parser ;
22use rb_cli:: {
33 Cli , Commands , environment_command, exec_command, init_command, init_logger,
4- resolve_search_dir, run_command, runtime_command, sync_command,
4+ resolve_search_dir, run_command, runtime_command, shell_integration_command , sync_command,
55} ;
66use rb_core:: butler:: { ButlerError , ButlerRuntime } ;
77
@@ -53,8 +53,11 @@ fn main() {
5353
5454 let cli = Cli :: parse ( ) ;
5555
56- // Initialize logger early with the effective log level (considering -v/-vv flags)
57- // This allows us to see config file loading and merging logs
56+ if let Some ( Commands :: BashComplete { line, point } ) = & cli. command {
57+ rb_cli:: completion:: generate_completions ( line, point, cli. config . rubies_dir . clone ( ) ) ;
58+ return ;
59+ }
60+
5861 init_logger ( cli. effective_log_level ( ) ) ;
5962
6063 // Merge config file defaults with CLI arguments
@@ -66,8 +69,15 @@ fn main() {
6669 }
6770 } ;
6871
69- // Handle init command early - doesn't require Ruby environment
70- if let Commands :: Init = cli. command {
72+ let Some ( command) = cli. command else {
73+ use clap:: CommandFactory ;
74+ let mut cmd = Cli :: command ( ) ;
75+ let _ = cmd. print_help ( ) ;
76+ println ! ( ) ;
77+ std:: process:: exit ( 0 ) ;
78+ } ;
79+
80+ if let Commands :: Init = command {
7181 let current_dir = std:: env:: current_dir ( ) . unwrap_or_else ( |_| std:: path:: PathBuf :: from ( "." ) ) ;
7282 if let Err ( e) = init_command ( & current_dir) {
7383 eprintln ! ( "{}" , e) ;
@@ -76,8 +86,23 @@ fn main() {
7686 return ;
7787 }
7888
89+ if let Commands :: ShellIntegration { shell } = command {
90+ match shell {
91+ Some ( s) => {
92+ if let Err ( e) = shell_integration_command ( s) {
93+ eprintln ! ( "Shell integration error: {}" , e) ;
94+ std:: process:: exit ( 1 ) ;
95+ }
96+ }
97+ None => {
98+ rb_cli:: commands:: shell_integration:: show_available_integrations ( ) ;
99+ }
100+ }
101+ return ;
102+ }
103+
79104 // Handle sync command differently since it doesn't use ButlerRuntime in the same way
80- if let Commands :: Sync = cli . command {
105+ if let Commands :: Sync = command {
81106 if let Err ( e) = sync_command (
82107 cli. config . rubies_dir . clone ( ) ,
83108 cli. config . ruby_version . clone ( ) ,
@@ -126,7 +151,7 @@ fn main() {
126151 } ,
127152 } ;
128153
129- match cli . command {
154+ match command {
130155 Commands :: Runtime => {
131156 runtime_command ( & butler_runtime) ;
132157 }
@@ -147,5 +172,7 @@ fn main() {
147172 // Already handled above
148173 unreachable ! ( )
149174 }
175+ Commands :: ShellIntegration { .. } => unreachable ! ( ) ,
176+ Commands :: BashComplete { .. } => unreachable ! ( ) ,
150177 }
151178}
0 commit comments