move state inspector for sled store into corresponding crate

This commit is contained in:
Benjamin Kampmann
2022-02-21 12:08:45 +01:00
parent 87cd9a3afc
commit 6aeb382706
6 changed files with 33 additions and 48 deletions

View File

@@ -58,19 +58,4 @@ features = ["client-api-c"]
[dev-dependencies]
futures = { version = "0.3.15", default-features = false, features = ["executor"] }
http = "0.2.4"
matrix-sdk-test = { version = "0.4.0", path = "../matrix-sdk-test" }
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
atty = "0.2.14"
clap = "3.0.13"
rustyline = "9.0.0"
rustyline-derive = "0.6.0"
syntect = "4.5.0"
tokio = { version = "1.7.1", default-features = false, features = [
"rt-multi-thread",
"macros",
] }
tempfile = "3.2.0"
[[example]]
name = "state_inspector"
matrix-sdk-test = { version = "0.4.0", path = "../matrix-sdk-test" }

View File

@@ -43,8 +43,8 @@ mod utilities;
mod verification;
#[cfg(feature = "testing")]
pub mod testing {
/// Testing facilities and helpers for crypto tests
pub mod testing {
pub use crate::identities::{
device::testing::get_device,
user::testing::{get_other_identity, get_own_identity},

View File

@@ -3,10 +3,23 @@ name = "matrix-sdk-sled"
version = "0.1.0"
edition = "2021"
[[bin]]
name = "state-inspector"
path = "bin/state_inspector.rs"
required-features = ["binary-build"]
[features]
default = ["encryption"]
encryption = ["matrix-sdk-crypto"]
binary-build = [
"atty",
"clap",
"futures",
"rustyline",
"rustyline-derive",
"syntect",
]
[dependencies]
futures-core = "0.3.15"
@@ -23,6 +36,14 @@ tracing = "0.1.26"
anyhow = "1"
dashmap = "4.0.2"
# binary-build only
atty = { version = "0.2.14", optional = true }
clap = { version = "3.1.0", optional = true }
futures = { version = "0.3.15", default-features = false, features = ["executor"], optional = true}
rustyline = { version = "9.0.0", optional = true }
rustyline-derive = { version = "0.6.0", optional = true }
syntect = { version = "4.5.0", optional = true }
[dev-dependencies]
lazy_static = "1.4"
tempfile = "3.2.0"

View File

@@ -1,13 +1,11 @@
use std::{convert::TryFrom, fmt::Debug, sync::Arc};
#[cfg(not(target_arch = "wasm32"))]
use atty::Stream;
#[cfg(not(target_arch = "wasm32"))]
use clap::{App as Argparse, AppSettings as ArgParseSettings, Arg, ArgMatches};
use clap::{Command as Argparse, Arg, ArgMatches};
use futures::executor::block_on;
use matrix_sdk_base::{RoomInfo, Store};
use ruma::{events::EventType, RoomId, UserId};
#[cfg(not(target_arch = "wasm32"))]
use matrix_sdk_sled::{StateStore};
use matrix_sdk_common::ruma::{events::EventType, RoomId, UserId};
use rustyline::{
completion::{Completer, Pair},
error::ReadlineError,
@@ -16,10 +14,8 @@ use rustyline::{
validate::{MatchingBracketValidator, Validator},
CompletionType, Config, Context, EditMode, Editor, OutputStreamType,
};
#[cfg(not(target_arch = "wasm32"))]
use rustyline_derive::Helper;
use serde::Serialize;
#[cfg(not(target_arch = "wasm32"))]
use syntect::{
dumps::from_binary,
easy::HighlightLines,
@@ -29,14 +25,12 @@ use syntect::{
};
#[derive(Clone)]
#[cfg(not(target_arch = "wasm32"))]
struct Inspector {
store: Store,
printer: Printer,
}
#[derive(Helper)]
#[cfg(not(target_arch = "wasm32"))]
struct InspectorHelper {
store: Store,
_highlighter: MatchingBracketHighlighter,
@@ -44,7 +38,6 @@ struct InspectorHelper {
_hinter: HistoryHinter,
}
#[cfg(not(target_arch = "wasm32"))]
impl InspectorHelper {
const EVENT_TYPES: &'static [&'static str] = &[
"m.room.aliases",
@@ -92,7 +85,6 @@ impl InspectorHelper {
}
}
#[cfg(not(target_arch = "wasm32"))]
impl Completer for InspectorHelper {
type Candidate = Pair;
@@ -151,19 +143,15 @@ impl Completer for InspectorHelper {
}
}
#[cfg(not(target_arch = "wasm32"))]
impl Hinter for InspectorHelper {
type Hint = String;
}
#[cfg(not(target_arch = "wasm32"))]
impl Highlighter for InspectorHelper {}
#[cfg(not(target_arch = "wasm32"))]
impl Validator for InspectorHelper {}
#[derive(Clone, Debug)]
#[cfg(not(target_arch = "wasm32"))]
struct Printer {
ps: Arc<SyntaxSet>,
ts: Arc<ThemeSet>,
@@ -171,7 +159,6 @@ struct Printer {
color: bool,
}
#[cfg(not(target_arch = "wasm32"))]
impl Printer {
fn new(json: bool, color: bool) -> Self {
let syntax_set: SyntaxSet = from_binary(include_bytes!("./syntaxes.bin"));
@@ -210,12 +197,10 @@ impl Printer {
}
}
#[cfg(not(target_arch = "wasm32"))]
impl Inspector {
fn new(database_path: &str, json: bool, color: bool) -> Self {
let printer = Printer::new(json, color);
// FIXME: THIS DOESN"T MAKE SENSE
let store = Store::open_memory_store();
let store = Store::new(Box::new(StateStore::open_with_path(database_path).expect("Can't open sled database")));
Self { store, printer }
}
@@ -308,10 +293,10 @@ impl Inspector {
async fn parse_and_run(&self, input: &str) {
let argparse = Argparse::new("state-inspector")
.global_setting(ArgParseSettings::DisableHelpFlag)
.global_setting(ArgParseSettings::DisableVersionFlag)
.global_setting(ArgParseSettings::NoBinaryName)
.setting(ArgParseSettings::SubcommandRequiredElseHelp)
.disable_version_flag(true)
.disable_help_flag(true)
.no_binary_name(true)
.arg_required_else_help(true)
.subcommands(Inspector::subcommands());
match argparse.try_get_matches_from(input.split_ascii_whitespace()) {
@@ -325,10 +310,9 @@ impl Inspector {
}
}
#[cfg(not(target_arch = "wasm32"))]
fn main() {
let argparse = Argparse::new("state-inspector")
.global_setting(ArgParseSettings::DisableVersionFlag)
.disable_version_flag(true)
.arg(Arg::new("database").required(true))
.arg(
Arg::new("json")
@@ -367,9 +351,4 @@ fn main() {
} else {
block_on(inspector.run(matches));
}
}
#[cfg(target_arch = "wasm32")]
fn main() {
panic!("This example doesn't run on WASM");
}
}