|
25 | 25 | from wdoc.utils.env import env, is_out_piped
|
26 | 26 | from wdoc.utils.typechecker import optional_typecheck
|
27 | 27 | from wdoc.utils.misc import get_piped_input, tasks_list
|
| 28 | +from wdoc.utils.batch_file_loader import infer_filetype, NoInferrableFiletype |
28 | 29 | from typing import Tuple, List, Dict, Any
|
29 | 30 | import io
|
30 | 31 |
|
@@ -251,22 +252,36 @@ def cli_launcher() -> None:
|
251 | 252 | args.append(new_arg)
|
252 | 253 | sys.argv.append(new_arg) # Append the new argument
|
253 | 254 |
|
254 |
| - # if no --path but an arg: use it as path arg |
255 |
| - if not ("path" in args or "path" in kwargs): |
256 |
| - if len(args) == 1: |
257 |
| - sys.argv.remove(args[0]) |
258 |
| - sys.argv.append(f"--path={args[0]}") |
259 |
| - logger.debug(f"Set the argument '{args[0]}' to a --path argument") |
| 255 | + # if there are remaining args, use the infer_filetype function to see if they are the missing path or the query |
| 256 | + if args: |
| 257 | + candidates = [] |
| 258 | + for arg in args: |
| 259 | + # if we can't infer the filetype then it's probably the implicit --query of the user |
| 260 | + infered = None |
| 261 | + try: |
| 262 | + infered = infer_filetype(arg) |
| 263 | + except NoInferrableFiletype: |
| 264 | + if "query" in kwargs["task"]: |
| 265 | + infered = "user_query" |
| 266 | + candidates.append(infered) |
| 267 | + |
| 268 | + if "query" in kwargs["task"] and ( |
| 269 | + "query" not in kwargs or not isinstance(kwargs["query"], str) |
| 270 | + ): |
| 271 | + if len([c for c in candidates if c == "user_query"]) == 1: |
| 272 | + query_index = candidates.index("user_query") |
| 273 | + kwargs["query"] = args.pop(query_index) |
| 274 | + sys.argv.append(f"--query='{kwargs['query']}'") |
| 275 | + candidates.pop(query_index) |
| 276 | + |
| 277 | + if ( |
| 278 | + args |
| 279 | + and not ("path" in args or "path" in kwargs) |
| 280 | + and len(candidates) == 1 |
| 281 | + and candidates[0] |
| 282 | + ): |
260 | 283 | kwargs["path"] = args.pop(0)
|
261 |
| - |
262 |
| - # if --path is empty give it the remaining arg |
263 |
| - if ("path" not in kwargs or isinstance(kwargs["path"], (bool, type(None)))) and len( |
264 |
| - args |
265 |
| - ) == 1: |
266 |
| - sys.argv.remove(args[0]) |
267 |
| - sys.argv.append(f"--path={args[0]}") |
268 |
| - logger.debug(f"Set the argument '{args[0]}' to a --path argument") |
269 |
| - kwargs["path"] = args.pop(0) |
| 284 | + sys.argv.append(f"--path='{kwargs['path']}'") |
270 | 285 |
|
271 | 286 | # if args is not empty, we have not succesfully parsed everything
|
272 | 287 | if args:
|
|
0 commit comments