fix panic with '.' as dir arg

This commit is contained in:
JMARyA 2024-03-08 13:35:03 +01:00
parent 38ff163eff
commit 7be5c026b0
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
2 changed files with 19 additions and 12 deletions

View file

@ -7,7 +7,7 @@ Usage: `mdq [OPTIONS] <dir>`
### Options
| Option | Description |
|---|---|
| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `-j, --json` | Output result as JSON |
| `-l, --limit <LIMIT>` | Limit number of results returned [default: 0] |
| `--offset <OFFSET>` | Offset results by a factor. Useful when used with `--limit` [default: 0] |

View file

@ -13,7 +13,14 @@ fn main() {
env_logger::init();
let args = args::get_args();
let mut i = Index::new(&args.root_dir, args.ignoretags);
let root_dir = if args.root_dir == "." {
let cwd = std::env::current_dir().unwrap();
cwd.to_str().unwrap().to_string()
} else {
args.root_dir
};
let mut i = Index::new(&root_dir, args.ignoretags);
if !args.filters.is_null() {
i = i.filter_documents(&args.filters);
}