Skip to content

Commit

Permalink
chore(style): rustfmt configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
wangl-cc committed Sep 23, 2024
1 parent 940e554 commit 1f31e65
Show file tree
Hide file tree
Showing 43 changed files with 782 additions and 859 deletions.
8 changes: 4 additions & 4 deletions maa-cli/src/activity.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::{config::task::ClientType, dirs};

use std::{io::Write, path::Path, sync::OnceLock};

use anyhow::{bail, Context, Result};
Expand All @@ -8,6 +6,8 @@ use log::warn;
use serde::Deserialize;
use serde_json::Value as JsonValue;

use crate::{config::task::ClientType, dirs};

fn stage_activity() -> Option<&'static StageActivityJson> {
static STAGE_ACTIVITY: OnceLock<Option<StageActivityJson>> = OnceLock::new();

Expand Down Expand Up @@ -210,10 +210,10 @@ impl<T, E: std::fmt::Display> WarnError<T> for std::result::Result<T, E> {

#[cfg(test)]
mod tests {
use super::*;

use std::env::var_os;

use super::*;

#[test]
fn parse_time_from_activity_info() {
use chrono::{TimeZone, Utc};
Expand Down
24 changes: 12 additions & 12 deletions maa-cli/src/cleanup.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
use crate::{
dirs::{cache, log, state},
value::userinput::{BoolInput, UserInput},
};

use std::{
borrow::Cow,
fs::{read_dir, DirEntry},
Expand All @@ -12,14 +7,19 @@ use std::{

use anyhow::{bail, Result};

use crate::{
dirs::{cache, log, state},
value::userinput::{BoolInput, UserInput},
};

pub trait PathProvider {
/// Path to a directory to be cleaned up
fn target_dir(&self) -> Cow<Path>;

/// Determine whether an entry in the directory should be deleted
///
/// Default implementation always returns true, meaning all files and directories will be deleted.
/// This method and `should_keep` determine whether an entry should be deleted.
/// Default implementation always returns true, meaning all files and directories will be
/// deleted. This method and `should_keep` determine whether an entry should be deleted.
/// If this method returns true and `should_keep` returns false, the entry will be deleted.
/// Otherwise, the entry will not be deleted.
#[allow(unused_variables)]
Expand Down Expand Up @@ -180,15 +180,14 @@ fn del_item(path: &Path) -> Result<(), std::io::Error> {

#[cfg(test)]
mod tests {
use super::*;

use crate::dirs::Ensure;

use std::{
collections::BTreeSet,
env::{temp_dir, var_os},
};

use super::*;
use crate::dirs::Ensure;

mod cleanup_target {
use super::*;

Expand Down Expand Up @@ -409,9 +408,10 @@ mod tests {

#[cfg(feature = "core_installer")]
{
use crate::installer::maa_core;
use semver::Version;

use crate::installer::maa_core;

std::fs::File::create(join!(
cache(),
maa_core::name(&Version::new(0, 0, 1)).unwrap()
Expand Down
110 changes: 43 additions & 67 deletions maa-cli/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{cleanup, config, log, run};

use std::path::PathBuf;

use clap::{Parser, Subcommand, ValueEnum};
use clap_complete::Shell;

use crate::{cleanup, config, log, run};

#[derive(Parser)]
#[command(name = "maa", author, version = env!("MAA_VERSION"), about = "A tool for Arknights.")]
#[allow(clippy::upper_case_acronyms)]
Expand Down Expand Up @@ -176,8 +176,8 @@ pub(crate) enum Command {
output: Option<PathBuf>,
/// Format of the output file, can be one of "toml", "yaml" and "json"
///
/// If not specified, the format will be guessed from the file extension of the output file.
/// If output file is not specified, the output will be default to "json".
/// If not specified, the format will be guessed from the file extension of the output
/// file. If output file is not specified, the output will be default to "json".
#[arg(short, long)]
format: Option<config::Filetype>,
},
Expand Down Expand Up @@ -223,8 +223,8 @@ pub(crate) enum Command {
/// - `resource`: user resource files.
///
/// Other values are supported, but not recommended.
/// It will be treated as a subdirectory of the config directory and show a warning message.
/// If you think it is correct, please open an issue to let us know.
/// It will be treated as a subdirectory of the config directory and show a warning
/// message. If you think it is correct, please open an issue to let us know.
#[arg(short = 't', long, default_value = "task", verbatim_doc_comment)]
config_type: String,
},
Expand Down Expand Up @@ -311,7 +311,6 @@ where
#[cfg(test)]
mod test {
use super::*;

use crate::config::cli::Channel;

#[macro_export]
Expand All @@ -330,13 +329,10 @@ mod test {
#[cfg(feature = "core_installer")]
#[test]
fn install() {
assert_matches!(
parse_from(["maa", "install"]).command,
Command::Install {
common: config::cli::maa_core::CommonArgs { .. },
force: false,
}
);
assert_matches!(parse_from(["maa", "install"]).command, Command::Install {
common: config::cli::maa_core::CommonArgs { .. },
force: false,
});

assert_matches!(
parse_from(["maa", "install", "beta"]).command,
Expand Down Expand Up @@ -402,12 +398,9 @@ mod test {
#[cfg(feature = "core_installer")]
#[test]
fn update() {
assert_matches!(
parse_from(["maa", "update"]).command,
Command::Update {
common: config::cli::maa_core::CommonArgs { .. },
}
);
assert_matches!(parse_from(["maa", "update"]).command, Command::Update {
common: config::cli::maa_core::CommonArgs { .. },
});
}

#[cfg(feature = "cli_installer")]
Expand Down Expand Up @@ -443,26 +436,22 @@ mod test {

#[test]
fn dir() {
assert_matches!(
parse_from(["maa", "dir", "data"]).command,
Command::Dir { dir: Dir::Data }
);
assert_matches!(parse_from(["maa", "dir", "data"]).command, Command::Dir {
dir: Dir::Data
});
assert_matches!(
parse_from(["maa", "dir", "library"]).command,
Command::Dir { dir: Dir::Library }
);
assert_matches!(
parse_from(["maa", "dir", "lib"]).command,
Command::Dir { dir: Dir::Library }
);
assert_matches!(
parse_from(["maa", "dir", "config"]).command,
Command::Dir { dir: Dir::Config }
);
assert_matches!(
parse_from(["maa", "dir", "cache"]).command,
Command::Dir { dir: Dir::Cache }
);
assert_matches!(parse_from(["maa", "dir", "lib"]).command, Command::Dir {
dir: Dir::Library
});
assert_matches!(parse_from(["maa", "dir", "config"]).command, Command::Dir {
dir: Dir::Config
});
assert_matches!(parse_from(["maa", "dir", "cache"]).command, Command::Dir {
dir: Dir::Cache
});
assert_matches!(
parse_from(["maa", "dir", "resource"]).command,
Command::Dir { dir: Dir::Resource }
Expand All @@ -473,20 +462,16 @@ mod test {
dir: Dir::HotUpdate
}
);
assert_matches!(
parse_from(["maa", "dir", "log"]).command,
Command::Dir { dir: Dir::Log }
);
assert_matches!(parse_from(["maa", "dir", "log"]).command, Command::Dir {
dir: Dir::Log
});
}

#[test]
fn version() {
assert_matches!(
parse_from(["maa", "version"]).command,
Command::Version {
component: Component::All
}
);
assert_matches!(parse_from(["maa", "version"]).command, Command::Version {
component: Component::All
});
assert_matches!(
parse_from(["maa", "version", "all"]).command,
Command::Version {
Expand Down Expand Up @@ -604,12 +589,9 @@ mod test {

#[test]
fn activity() {
assert_matches!(
parse_from(["maa", "activity"]).command,
Command::Activity {
client: config::task::ClientType::Official,
}
);
assert_matches!(parse_from(["maa", "activity"]).command, Command::Activity {
client: config::task::ClientType::Official,
});

assert_matches!(
parse_from(["maa", "activity", "YoStarEN"]).command,
Expand Down Expand Up @@ -689,14 +671,11 @@ mod test {

#[test]
fn init() {
assert_matches!(
parse_from(["maa", "init"]).command,
Command::Init {
name: None,
format: None,
force: false,
}
);
assert_matches!(parse_from(["maa", "init"]).command, Command::Init {
name: None,
format: None,
force: false,
});

assert_matches!(
parse_from(["maa", "init", "--name", "name"]).command,
Expand All @@ -714,13 +693,10 @@ mod test {
}
);

assert_matches!(
parse_from(["maa", "init", "-ft"]).command,
Command::Init {
format: Some(config::Filetype::Toml),
..
}
);
assert_matches!(parse_from(["maa", "init", "-ft"]).command, Command::Init {
format: Some(config::Filetype::Toml),
..
});

assert_matches!(
parse_from(["maa", "init", "--force"]).command,
Expand Down
Loading

0 comments on commit 1f31e65

Please sign in to comment.