This repository was archived by the owner on Sep 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathdatabase.rs
More file actions
40 lines (36 loc) · 1.39 KB
/
database.rs
File metadata and controls
40 lines (36 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// -*- coding: utf-8 -*-
// ------------------------------------------------------------------------------------------------
// Copyright © 2021, stack-graphs authors.
// Licensed under either of Apache License, Version 2.0, or MIT license, at your option.
// Please see the LICENSE-APACHE or LICENSE-MIT files in this distribution for license details.
// ------------------------------------------------------------------------------------------------
use anyhow::anyhow;
use clap::Args;
use clap::ValueHint;
use std::path::PathBuf;
#[derive(Args)]
pub struct DatabaseArgs {
/// Path of the indexing database to use.
#[clap(
long,
short = 'D',
value_name = "DATABASE_PATH",
value_hint = ValueHint::AnyPath,
)]
pub database: Option<PathBuf>,
}
impl DatabaseArgs {
pub fn get_or(self, default_path: PathBuf) -> PathBuf {
self.database.clone().unwrap_or_else(|| default_path)
}
}
/// Returns the default database path in the current user's local data directory for the
/// given crate name. Distinct crate names will have distinct database paths.
pub fn default_user_database_path_for_crate(crate_name: &str) -> anyhow::Result<PathBuf> {
match dirs::data_local_dir() {
Some(dir) => Ok(dir.join(format!("{}.sqlite", crate_name))),
None => Err(anyhow!(
"unable to determine data local directory for database"
)),
}
}