@@ -7,6 +7,7 @@ mod proto_info;
77mod template;
88
99use crate :: code_gen:: util:: path_string_with_component;
10+ use itertools:: Itertools ;
1011use log:: info;
1112pub use proto_gen:: * ;
1213pub use proto_info:: * ;
@@ -132,7 +133,7 @@ fn generate_dart_protobuf_files(
132133 }
133134}
134135
135- fn check_pb_dart_plugin ( ) {
136+ pub fn check_pb_dart_plugin ( ) {
136137 if cfg ! ( target_os = "windows" ) {
137138 //Command::new("cmd")
138139 // .arg("/C")
@@ -141,15 +142,39 @@ fn check_pb_dart_plugin() {
141142 // .expect("failed to execute process");
142143 //panic!("{}", format!("\n❌ The protoc-gen-dart was not installed correctly."))
143144 } else {
144- let is_success = Command :: new ( "sh" )
145+ let exit_result = Command :: new ( "sh" )
145146 . arg ( "-c" )
146147 . arg ( "command -v protoc-gen-dart" )
147148 . status ( )
148- . expect ( "failed to execute process" )
149- . success ( ) ;
149+ . expect ( "failed to execute process" ) ;
150+
151+ if !exit_result. success ( ) {
152+ let mut msg = "\n ❌ Can't find protoc-gen-dart in $PATH:\n " . to_string ( ) ;
153+ let output = Command :: new ( "sh" ) . arg ( "-c" ) . arg ( "echo $PATH" ) . output ( ) ;
154+ let paths = String :: from_utf8 ( output. unwrap ( ) . stdout )
155+ . unwrap ( )
156+ . split ( ":" )
157+ . map ( |s| s. to_string ( ) )
158+ . collect :: < Vec < String > > ( ) ;
159+
160+ paths. iter ( ) . for_each ( |s| msg. push_str ( & format ! ( "{}\n " , s) ) ) ;
161+
162+ match Command :: new ( "sh" ) . arg ( "-c" ) . arg ( "which protoc-gen-dart" ) . output ( ) {
163+ Ok ( output) => {
164+ msg. push_str ( & format ! (
165+ "Installed protoc-gen-dart path: {:?}\n " ,
166+ String :: from_utf8( output. stdout) . unwrap( )
167+ ) ) ;
168+ }
169+ Err ( _) => { }
170+ }
150171
151- if !is_success {
152- panic ! ( "{}" , format!( "\n ❌ The protoc-gen-dart was not installed correctly. \n ✅ You can fix that by adding \" {}\" to your shell's config file.(.bashrc, .bash, etc.)" , "dart pub global activate protoc_plugin" ) )
172+ msg. push_str ( & format ! ( "✅ You can fix that by adding:" ) ) ;
173+ msg. push_str ( & format ! ( "\n \t export PATH=\" $PATH\" :\" $HOME/.pub-cache/bin\" \n " , ) ) ;
174+ msg. push_str ( & format ! (
175+ "to your shell's config file.(.bashrc, .bash, .profile, .zshrc etc.)"
176+ ) ) ;
177+ panic ! ( "{}" , msg)
153178 }
154179 }
155180}
0 commit comments