Skip to content

Commit 204b7fe

Browse files
authored
feat(*): allow configuring config directory through LoadOptions (#1323)
1 parent 81d6685 commit 204b7fe

40 files changed

+1048
-534
lines changed

cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ odict = { path = "../lib", features = [
1919
"html",
2020
"tokenize",
2121
] }
22-
internal = { path = "../internal", features = ["load"] }
22+
internal = { path = "../internal" }
2323
clap = { version = "4.5.49", features = ["derive", "cargo"] }
2424
console = "0.16.1"
2525
indicatif = "0.18.0"

cli/src/alias/set.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clap::{arg, Args};
2-
use odict::alias::AliasManager;
2+
use odict::{alias::AliasManager, OpenDictionary};
33

44
#[derive(Debug, Args)]
55
#[command(args_conflicts_with_subcommands = true)]
@@ -13,7 +13,7 @@ pub struct SetArgs {
1313
}
1414

1515
pub async fn set<'a>(args: &SetArgs, overwrite: bool) -> anyhow::Result<()> {
16-
let dict = internal::load_dictionary(args.path.as_str()).await?;
16+
let dict = OpenDictionary::load(args.path.as_str()).await?;
1717

1818
if overwrite {
1919
anyhow::Ok(AliasManager::default().set(args.name.as_str(), &dict)?)

cli/src/download.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ pub async fn download(ctx: &mut CLIContext<'_>, args: &DownloadArgs) -> anyhow::
5252

5353
let downloader = DictionaryDownloader::default();
5454

55-
let mut options = DownloadOptions::default().caching(!no_cache);
55+
let mut options = DownloadOptions::default().with_caching(!no_cache);
5656

5757
if let Some(out_dir) = output {
58-
options = options.out_dir(out_dir);
58+
options = options.with_out_dir(out_dir);
5959
}
6060

6161
options = options.on_progress(|downloaded, total, _progress| {

cli/src/dump.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
use std::fs;
22

33
use clap::{arg, command, Args};
4-
use odict::format::{
5-
sql::{SQLDialect, ToSQL},
6-
xml::ToXML,
4+
use odict::{
5+
format::{
6+
sql::{SQLDialect, ToSQL},
7+
xml::ToXML,
8+
},
9+
OpenDictionary,
710
};
811

912
use crate::{enums::DumpFormat, CLIContext};
@@ -29,7 +32,7 @@ pub async fn dump<'a>(ctx: &mut CLIContext<'a>, args: &DumpArgs) -> anyhow::Resu
2932
output,
3033
} = args;
3134

32-
let dict = internal::load_dictionary(input)
35+
let dict = OpenDictionary::load(input)
3336
.await?
3437
.contents()?
3538
.deserialize()?;

cli/src/index.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ use std::path::PathBuf;
22

33
use clap::{arg, command, Args};
44
use indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle};
5-
use odict::index::{get_default_index_dir, IndexOptions};
5+
use odict::{
6+
index::{get_default_index_dir, IndexOptions},
7+
OpenDictionary,
8+
};
69

710
use crate::CLIContext;
811

@@ -30,7 +33,7 @@ pub struct IndexArgs {
3033
}
3134

3235
pub async fn index<'a>(ctx: &mut CLIContext<'a>, args: &IndexArgs) -> anyhow::Result<()> {
33-
let file = internal::load_dictionary(&args.dictionary).await?;
36+
let file = OpenDictionary::load(&args.dictionary).await?;
3437

3538
ctx.println("");
3639

cli/src/info.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use clap::{arg, command, Args};
33
use console::Style;
44
use indicatif::DecimalBytes;
55
use num_format::{Locale, ToFormattedString};
6+
use odict::OpenDictionary;
67

78
#[derive(Debug, Args)]
89
#[command(args_conflicts_with_subcommands = true)]
@@ -17,7 +18,7 @@ pub async fn info<'a>(ctx: &mut CLIContext<'a>, args: &InfoArgs) -> anyhow::Resu
1718
dictionary_path: path,
1819
} = args;
1920

20-
let file = internal::load_dictionary(path).await?;
21+
let file = OpenDictionary::load(path).await?;
2122

2223
let bold = Style::new().bold();
2324
let dict = file.contents()?;

cli/src/lexicon.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use clap::{arg, command, Args};
2+
use odict::OpenDictionary;
23

34
use crate::CLIContext;
45

@@ -11,7 +12,7 @@ pub struct LexiconArgs {
1112
}
1213

1314
pub async fn lexicon<'a>(ctx: &mut CLIContext<'a>, args: &LexiconArgs) -> anyhow::Result<()> {
14-
let file = internal::load_dictionary(&args.dictionary).await?;
15+
let file = OpenDictionary::load(&args.dictionary).await?;
1516

1617
let dict = file.contents()?;
1718
let lexicon = dict.lexicon();

cli/src/lookup.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::get_lookup_entries;
55
use crate::{context::CLIContext, print_entries};
66
use clap::{arg, command, Args};
77
use odict::lookup::{LookupOptions, LookupStrategy};
8+
use odict::OpenDictionary;
89

910
#[derive(Debug, Args)]
1011
#[command(args_conflicts_with_subcommands = true)]
@@ -63,7 +64,7 @@ pub async fn lookup<'a>(ctx: &mut CLIContext<'a>, args: &LookupArgs) -> anyhow::
6364

6465
spinner.enable_steady_tick(Duration::from_millis(100));
6566

66-
let file = internal::load_dictionary(path).await?;
67+
let file = OpenDictionary::load(path).await?;
6768

6869
let mut opts: LookupOptions = LookupOptions::default()
6970
.follow(*follow)

cli/src/merge.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use clap::{arg, command, Args};
2+
use odict::OpenDictionary;
23

34
#[derive(Debug, Args)]
45
#[command(args_conflicts_with_subcommands = true)]
@@ -18,13 +19,13 @@ pub struct MergeArgs {
1819
}
1920

2021
pub async fn merge<'a>(args: &MergeArgs) -> anyhow::Result<()> {
21-
let mut dict = internal::load_dictionary(&args.destination)
22+
let mut dict = OpenDictionary::load(&args.destination)
2223
.await?
2324
.contents()?
2425
.deserialize()?;
2526

2627
for source in &args.sources {
27-
let source_dict = internal::load_dictionary(source)
28+
let source_dict = OpenDictionary::load(source)
2829
.await?
2930
.contents()?
3031
.deserialize()?;

cli/src/search.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clap::{arg, command, Args};
2-
use odict::index::get_default_index_dir;
32
use odict::search::SearchOptions;
3+
use odict::{index::get_default_index_dir, OpenDictionary};
44

55
use crate::{enums::PrintFormat, print_entries, CLIContext, IndexArgs, DEFAULT_INDEX_MEMORY};
66

@@ -26,7 +26,7 @@ pub struct SearchArgs {
2626
}
2727

2828
pub async fn search<'a>(ctx: &mut CLIContext<'a>, args: &SearchArgs) -> anyhow::Result<()> {
29-
let file = internal::load_dictionary(&args.dictionary).await?;
29+
let file = OpenDictionary::load(&args.dictionary).await?;
3030

3131
let dict = file.contents()?;
3232

0 commit comments

Comments
 (0)