This repository was archived by the owner on Apr 21, 2025. It is now read-only.
File tree 1 file changed +25
-7
lines changed
1 file changed +25
-7
lines changed Original file line number Diff line number Diff line change 2
2
Query module
3
3
"""
4
4
5
+ import argparse
5
6
import os
6
7
import os .path
7
8
import sqlite3
8
- import sys
9
9
10
10
import html2text
11
11
import mdv
@@ -182,14 +182,33 @@ def close(db):
182
182
db .close ()
183
183
184
184
@staticmethod
185
- def run ( query ):
185
+ def args ( ):
186
186
"""
187
- Executes a query against a codequestion index .
187
+ Parses command line arguments .
188
188
189
- Args :
190
- query: input query
189
+ Returns :
190
+ command line arguments
191
191
"""
192
192
193
+ parser = argparse .ArgumentParser (description = "codequestion query" )
194
+
195
+ parser .add_argument ("-l" , "--lang" , help = "Sets default language" )
196
+ parser .add_argument ("-q" , "--query" , required = True , help = "Query to execute" )
197
+
198
+ return parser .parse_args ()
199
+
200
+ @staticmethod
201
+ def run ():
202
+ """
203
+ Executes a query against a codequestion index.
204
+ """
205
+
206
+ # Parse command line arguments
207
+ args = Query .args ()
208
+
209
+ # Build query
210
+ query = "%s %s" % (args .lang , args .query ) if args .lang else args .query
211
+
193
212
# Load model
194
213
embeddings , db = Query .load ()
195
214
@@ -200,5 +219,4 @@ def run(query):
200
219
Query .close (db )
201
220
202
221
if __name__ == "__main__" :
203
- if len (sys .argv ) > 1 :
204
- Query .run (sys .argv [1 ])
222
+ Query .run ()
You can’t perform that action at this time.
0 commit comments