Skip to content

Commit

Permalink
refactor: split dirs module into a separate crate
Browse files Browse the repository at this point in the history
  • Loading branch information
wangl-cc committed Sep 8, 2024
1 parent dcea6df commit bf3ec67
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 5 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["maa-cli", "maa-sys"]
members = ["maa-cli", "maa-dirs", "maa-sys"]

[workspace.package]
license = "AGPL-3.0-only"
Expand Down
1 change: 1 addition & 0 deletions maa-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ maa-sys = { path = "../maa-sys", version = "0.3.1", features = [
"runtime",
"serde",
] }
maa-dirs = { path = "../maa-dirs", version = "0.1.0" }

directories = "5"
anyhow = "1"
Expand Down
1 change: 1 addition & 0 deletions maa-cli/src/activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{io::Write, path::Path, sync::OnceLock};
use anyhow::{bail, Context, Result};
use chrono::{DateTime, FixedOffset, NaiveDateTime};
use log::warn;
use maa_dirs::join;
use serde::Deserialize;
use serde_json::Value as JsonValue;

Expand Down
1 change: 1 addition & 0 deletions maa-cli/src/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::{
};

use anyhow::{bail, Result};
use maa_dirs::join;

pub trait PathProvider {
/// Path to a directory to be cleaned up
Expand Down
1 change: 1 addition & 0 deletions maa-cli/src/config/asst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{borrow::Cow, path::PathBuf};

use anyhow::{Context, Result};
use log::{debug, info, warn};
use maa_dirs::join;
use maa_sys::{Assistant, InstanceOptionKey, StaticOptionKey, TouchMode};
use serde::Deserialize;

Expand Down
1 change: 1 addition & 0 deletions maa-cli/src/config/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
use std::path::PathBuf;

use anyhow::{bail, Result};
use maa_dirs::join;

fn asst_config_template() -> MAAValue {
object!(
Expand Down
1 change: 1 addition & 0 deletions maa-cli/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ mod tests {

use crate::assert_matches;

use maa_dirs::join;
use serde::Deserialize;
use serde_json::{json, Value as JsonValue};

Expand Down
4 changes: 1 addition & 3 deletions maa-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#[macro_use]
mod dirs;

mod log;

mod activity;
Expand All @@ -15,6 +12,7 @@ use crate::command::{Command, Component, Dir, CLI};

use anyhow::{Context, Result};
use clap::{CommandFactory, Parser};
use maa_dirs as dirs;

fn main() -> Result<()> {
let cli = command::CLI::parse();
Expand Down
1 change: 1 addition & 0 deletions maa-cli/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use std::{
use anyhow::{bail, Context, Result};
use clap::Args;
use log::{debug, warn};
use maa_dirs::join;
use maa_sys::Assistant;
use signal_hook::consts::TERM_SIGNALS;

Expand Down
12 changes: 12 additions & 0 deletions maa-dirs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "maa-dirs"
version = "0.1.0"
edition = "2021"
license.workspace = true
homepage.workspace = true
repository.workspace = true

[dependencies]
directories = "5"
dunce = "1.0.4"
log = "0.4.20"
3 changes: 2 additions & 1 deletion maa-cli/src/dirs.rs → maa-dirs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ pub fn maa_lib_name() -> &'static str {
/// The expression after `;` is optional, which is used to set the extension of the final path.
///
/// Note: Because we reuse the first path, the first path will be consumed.
/// Thus, if you want to reuse the first path, you should pass a Path instead of a PathBuf.
/// Thus, if you want to reuse the first path, you should pass a Path instead of a PathBuf
#[macro_export]
macro_rules! join {
($path:expr, $($paths:expr),+ $(; $ext:expr)?) => {{
let mut path: ::std::path::PathBuf = $path.into();
Expand Down

0 comments on commit bf3ec67

Please sign in to comment.