@@ -53,13 +53,11 @@ fn main() {
5353
5454 let cli = Cli :: parse ( ) ;
5555
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 ;
56+ // Skip logging for bash completion (must be silent)
57+ if ! matches ! ( cli . command , Some ( Commands :: BashComplete { .. } ) ) {
58+ init_logger ( cli . effective_log_level ( ) ) ;
5959 }
6060
61- init_logger ( cli. effective_log_level ( ) ) ;
62-
6361 // Merge config file defaults with CLI arguments
6462 let cli = match cli. with_config_defaults ( ) {
6563 Ok ( cli) => cli,
@@ -101,54 +99,72 @@ fn main() {
10199 return ;
102100 }
103101
104- // Handle sync command differently since it doesn't use ButlerRuntime in the same way
105- if let Commands :: Sync = command {
106- if let Err ( e) = sync_command (
107- cli. config . rubies_dir . clone ( ) ,
108- cli. config . ruby_version . clone ( ) ,
109- cli. config . gem_home . clone ( ) ,
110- cli. config . no_bundler . unwrap_or ( false ) ,
111- ) {
112- eprintln ! ( "Sync failed: {}" , e) ;
113- std:: process:: exit ( 1 ) ;
114- }
115- return ;
116- }
117-
118102 // Resolve search directory for Ruby installations
119- let rubies_dir = resolve_search_dir ( cli. config . rubies_dir ) ;
103+ let rubies_dir = resolve_search_dir ( cli. config . rubies_dir . clone ( ) ) ;
120104
121105 // Perform comprehensive environment discovery once
106+ let is_completion = matches ! ( command, Commands :: BashComplete { .. } ) ;
107+
122108 let butler_runtime = match ButlerRuntime :: discover_and_compose_with_gem_base (
123- rubies_dir,
124- cli. config . ruby_version ,
125- cli. config . gem_home ,
109+ rubies_dir. clone ( ) ,
110+ cli. config . ruby_version . clone ( ) ,
111+ cli. config . gem_home . clone ( ) ,
126112 cli. config . no_bundler . unwrap_or ( false ) ,
127113 ) {
128114 Ok ( runtime) => runtime,
129- Err ( e) => match e {
130- ButlerError :: RubiesDirectoryNotFound ( path) => {
131- eprintln ! ( "🎩 My sincerest apologies, but the designated Ruby estate directory" ) ;
132- eprintln ! (
133- " '{}' appears to be absent from your system." ,
134- path. display( )
135- ) ;
136- eprintln ! ( ) ;
137- eprintln ! ( "Without access to a properly established Ruby estate, I'm afraid" ) ;
138- eprintln ! (
139- "there's precious little this humble Butler can accomplish on your behalf."
140- ) ;
141- eprintln ! ( ) ;
142- eprintln ! ( "May I suggest installing Ruby using ruby-install or a similar" ) ;
143- eprintln ! ( "distinguished tool to establish your Ruby installations at the" ) ;
144- eprintln ! ( "expected location, then we shall proceed with appropriate ceremony." ) ;
145- std:: process:: exit ( 1 ) ;
146- }
147- _ => {
148- eprintln ! ( "Error: {}" , e) ;
149- std:: process:: exit ( 1 ) ;
115+ Err ( e) => {
116+ if is_completion {
117+ // Completion: exit silently with no suggestions when no Ruby found
118+ std:: process:: exit ( 0 ) ;
119+ } else {
120+ // Interactive commands: show helpful error with search details
121+ match e {
122+ ButlerError :: RubiesDirectoryNotFound ( path) => {
123+ eprintln ! (
124+ "The designated Ruby estate directory appears to be absent from your system."
125+ ) ;
126+ eprintln ! ( ) ;
127+ eprintln ! ( "Searched in:" ) ;
128+ eprintln ! ( " • {}" , path. display( ) ) ;
129+
130+ // Show why this path was used
131+ if let Some ( ref config_rubies) = cli. config . rubies_dir {
132+ eprintln ! ( " (from config: {})" , config_rubies. display( ) ) ;
133+ } else {
134+ eprintln ! ( " (default location)" ) ;
135+ }
136+
137+ if let Some ( ref requested_version) = cli. config . ruby_version {
138+ eprintln ! ( ) ;
139+ eprintln ! ( "Requested version: {}" , requested_version) ;
140+ }
141+
142+ eprintln ! ( ) ;
143+ eprintln ! (
144+ "May I suggest installing Ruby using ruby-install or a similar distinguished tool?"
145+ ) ;
146+ std:: process:: exit ( 1 ) ;
147+ }
148+ ButlerError :: NoSuitableRuby ( msg) => {
149+ eprintln ! ( "No suitable Ruby installation found: {}" , msg) ;
150+ eprintln ! ( ) ;
151+ eprintln ! ( "Searched in: {}" , rubies_dir. display( ) ) ;
152+
153+ if let Some ( ref requested_version) = cli. config . ruby_version {
154+ eprintln ! ( "Requested version: {}" , requested_version) ;
155+ }
156+
157+ eprintln ! ( ) ;
158+ eprintln ! ( "May I suggest installing a suitable Ruby version?" ) ;
159+ std:: process:: exit ( 1 ) ;
160+ }
161+ _ => {
162+ eprintln ! ( "Ruby detection encountered an unexpected difficulty: {}" , e) ;
163+ std:: process:: exit ( 1 ) ;
164+ }
165+ }
150166 }
151- } ,
167+ }
152168 } ;
153169
154170 match command {
@@ -169,10 +185,14 @@ fn main() {
169185 unreachable ! ( )
170186 }
171187 Commands :: Sync => {
172- // Already handled above
173- unreachable ! ( )
188+ if let Err ( e) = sync_command ( butler_runtime) {
189+ eprintln ! ( "Sync failed: {}" , e) ;
190+ std:: process:: exit ( 1 ) ;
191+ }
174192 }
175193 Commands :: ShellIntegration { .. } => unreachable ! ( ) ,
176- Commands :: BashComplete { .. } => unreachable ! ( ) ,
194+ Commands :: BashComplete { line, point } => {
195+ rb_cli:: completion:: generate_completions ( & line, & point, & butler_runtime) ;
196+ }
177197 }
178198}
0 commit comments