File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change 1
1
use std:: io:: ErrorKind ;
2
2
use std:: path:: Path ;
3
3
4
+ use clap:: CommandFactory ;
4
5
use clap:: { Parser , Subcommand , ValueEnum } ;
5
6
use hnsw:: Hnsw ;
6
7
use indexer:: serialize_index;
@@ -94,8 +95,15 @@ enum DistanceVariant {
94
95
}
95
96
96
97
fn key_or_env ( k : Option < String > ) -> String {
97
- k. or_else ( || std:: env:: var ( "OPENAI_KEY" ) . ok ( ) )
98
- . expect ( "No OpenAI key given" )
98
+ let result = k. or_else ( || std:: env:: var ( "OPENAI_KEY" ) . ok ( ) ) ;
99
+ if result. is_none ( ) {
100
+ let mut app = Args :: command ( ) ;
101
+ eprintln ! ( "Error: no OpenAI key given. Configure it with the OPENAI_KEY environment variable, or by passing in the --key argument" ) ;
102
+ app. print_help ( ) . unwrap ( ) ;
103
+ std:: process:: exit ( 2 ) ;
104
+ }
105
+
106
+ result. unwrap ( )
99
107
}
100
108
101
109
#[ tokio:: main]
You can’t perform that action at this time.
0 commit comments