From 47f8b48407de79302bea0603a5f829095cceec1f Mon Sep 17 00:00:00 2001 From: Andrey Tkachenko Date: Mon, 28 Mar 2022 17:19:23 +0400 Subject: [PATCH] PMS Basic Update --- .drone.yml | 13 +++ Cargo.toml | 6 ++ README.md | 2 + bin/wplug.rs | 21 +++- src/catalog.rs | 35 +++++++ src/error.rs | 7 ++ src/lib.rs | 79 +++++++++++++++ src/metadata.rs | 221 ++++++++++++++++++++++++++++++++++++++++++ src/plugin.rs | 43 ++++++++ wplug_lib/Cargo.toml | 8 ++ wplug_lib/src/core.rs | 12 +++ wplug_lib/src/lib.rs | 0 12 files changed, 446 insertions(+), 1 deletion(-) create mode 100644 .drone.yml create mode 100644 src/catalog.rs create mode 100644 src/error.rs create mode 100644 src/metadata.rs create mode 100644 src/plugin.rs create mode 100644 wplug_lib/Cargo.toml create mode 100644 wplug_lib/src/core.rs create mode 100644 wplug_lib/src/lib.rs diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..559251e --- /dev/null +++ b/.drone.yml @@ -0,0 +1,13 @@ +kind: pipeline +name: default + +steps: +- name: build + image: hub.aidev.ru/rust + commands: + - cargo build --verbose --all + +- name: fmt-check + image: hub.aidev.ru/rust + commands: + - cargo fmt --all -- --check diff --git a/Cargo.toml b/Cargo.toml index e4023b2..9c794b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,3 +10,9 @@ name = "wplug" path = "./bin/wplug.rs" [dependencies] +clap = {version = "3.1.6", features = ["derive"]} +serde = "1.0.136" +serde_derive = "1.0.136" +slab = "0.4.5" +thiserror = "1.0.30" +toml = "0.5.8" diff --git a/README.md b/README.md index 7dd4a00..a18c85e 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,5 @@ Create and manage `wplug` packages: - create packages - verify - upload to registry + + diff --git a/bin/wplug.rs b/bin/wplug.rs index e14ab36..eef3cf6 100644 --- a/bin/wplug.rs +++ b/bin/wplug.rs @@ -1,6 +1,25 @@ +use clap::{Parser, Subcommand}; +#[derive(Debug, Parser)] +#[clap(author, version, about, long_about = None)] +#[clap(propagate_version = true)] +pub struct Args { + #[clap(subcommand)] + cmd: ArgsCoommans, +} +#[derive(Debug, Subcommand)] +pub enum ArgsCoommans { + Info, + List, + Search { query: String }, + Publish, + Login, + Add { name: String }, + Remove { name: String }, + Update, +} pub fn main() { - + println!("{:?}", Args::parse()); } diff --git a/src/catalog.rs b/src/catalog.rs new file mode 100644 index 0000000..3872dab --- /dev/null +++ b/src/catalog.rs @@ -0,0 +1,35 @@ +use serde_derive::{Deserialize, Serialize}; + +use crate::{metadata::PluginMetadata, Error, PluginId, PluginLink}; + +#[derive(Debug, Clone, Deserialize)] +pub struct PluginSearchResult { + items: Vec, +} + +#[derive(Debug, Clone, Serialize)] +pub struct PluginSearchQuery { + pub title: String, + pub keywords: String, + pub categories: Vec, +} + +pub struct PluginCatalog {} + +impl PluginCatalog { + pub fn new() -> Self { + Self {} + } + pub async fn search_plugin( + &self, + query: PluginSearchQuery, + ) -> Result { + unimplemented!() + } + pub async fn plugin_metadata(&self, plugin_id: PluginId) -> Result { + unimplemented!() + } + pub async fn plugin_link(&self) -> Result { + unimplemented!() + } +} diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..24cae3d --- /dev/null +++ b/src/error.rs @@ -0,0 +1,7 @@ +use thiserror::Error; + +#[derive(Debug, Error)] +pub enum Error { + #[error("test")] + Variant1, +} diff --git a/src/lib.rs b/src/lib.rs index fd40910..a69f0d1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,83 @@ +mod catalog; +mod error; +mod metadata; +mod plugin; +use std::{collections::HashMap, sync::Arc}; +pub use catalog::{PluginCatalog, PluginSearchQuery}; +pub use error::Error; +use metadata::PluginMetadata; +pub use plugin::Plugin; +use serde_derive::Deserialize; +use slab::Slab; +use toml::Value; +pub type PluginId = u64; +#[derive(Debug, Clone, Deserialize)] +pub enum PluginState { + Running, + Failed, + Unloaded, + Updating, + Disabled, +} + +#[derive(Debug, Clone, Deserialize)] +pub enum PluginLink { + GitRepo(String), + Url(String), +} + +#[derive(Debug, Clone, Deserialize)] +pub struct PluginDescription { + metadata: PluginMetadata, + state: PluginState, +} + +pub struct PluginManager { + options: HashMap<(PluginId, String), Value>, + plugins: Slab, +} + +impl PluginManager { + pub fn new() -> Self { + Self { + options: Default::default(), + plugins: Default::default(), + } + } + + pub async fn start() {} + + pub fn plugin_list(&self) -> Vec> { + vec![] + } + + pub async fn update_plugin_option() {} + + pub async fn send_message() {} + + pub async fn request() {} + + // Plugin Management + + pub async fn install_plugin() {} + + pub async fn uninstall_plugin() {} + + pub async fn download_plugin(&self, link: PluginLink) -> Result<(), Error> { + Ok(()) + } + + pub async fn disable_plugin() {} + + // Plugin Runtime + + pub async fn reset_plugin() {} + + pub async fn load_plugin() {} + + pub async fn unload_plugin() {} +} diff --git a/src/metadata.rs b/src/metadata.rs new file mode 100644 index 0000000..ab50f96 --- /dev/null +++ b/src/metadata.rs @@ -0,0 +1,221 @@ +use std::collections::HashMap; + +use serde_derive::Deserialize; +use toml::Value; + +/// +/// +/// +#[derive(Debug, Clone, Deserialize)] +pub struct PluginMetadataHook { + entry: String, +} + +/// +/// +/// +#[derive(Debug, Clone, Deserialize)] +pub struct PluginMetadataExportArgument { + name: String, + #[serde(rename = "type")] + ty: String, + default: Option, + required: bool, +} + +/// +/// Plugin Export Definition +/// +#[derive(Debug, Clone, Deserialize)] +pub struct PluginMetadataExport { + name: String, + args: Vec, + entry: String, +} + +/// +/// Plugin Export Key Mapping +/// +#[derive(Debug, Clone, Deserialize)] +pub struct PluginMetadataExportKeyMapping { + entry: String, + args: Vec, + mapping: String, +} + +/// +/// Plugin Metadata Dependency +/// +#[derive(Debug, Clone, Deserialize)] +pub struct PluginMetadataDependency { + /// + /// Dependecy name + name: String, + + /// + /// Version match pattern + version: Option, + + /// + /// Git repository url + git: Option, + + /// + /// Branch name in case of git repository url set + branch: Option, + + /// + /// Revision number in case of git repository url set + rev: Option, + + /// + /// Path in case package is in file system + path: Option, +} + +/// +/// Plugin Metadata Configuration Option +/// +/// +#[derive(Debug, Clone, Deserialize)] +pub struct PluginMetadataOption { + /// + /// Option name + /// + name: String, + + /// + /// Value Type + /// + #[serde(rename = "type")] + ty: String, + + /// + /// Description + /// + description: Option, + + /// + /// Option default value + /// + default: Option, + + /// + /// Option required flag + required: bool, +} + +/// +/// Plugin Metadata +/// +#[derive(Debug, Clone, Deserialize)] +pub struct PluginMetadata { + /// + /// Plugin name + /// + name: String, + + /// + /// Plugin version signature + /// + version: String, + + /// + /// Licence + /// + licence: String, + + /// + /// Title + /// + title: String, + + /// + /// Description + /// + description: String, + + /// + /// List of plugin's authors + /// + authors: Vec, + + /// + /// Plugin documentation URL + /// + documentation: String, + + /// + /// Plugin homepage URL + /// + homepage: String, + + /// + /// Plugin repository URL + /// + repository: String, + + /// + /// Plugin keywords for search optiomization + /// + keywords: Vec, + + /// + /// API set pluging is using + /// - if plugin uses only editor api (i.e. cursor or buffer content) it should be installed + /// locally + /// - if plugin needs to run commands or acces to fs - so it should be installed remotly + /// + api_version: String, + + /// + /// List of categories the plugin is related to + /// + categories: String, + + /// + /// Resources to include to publishing package + /// + include: Vec, + + /// + /// Files or folders to exclude from publishing the plugin + /// + exclude: Vec, + + /// + /// Plugin dependencies + /// + dependencies: Vec, + + /// + /// Configuration options for the plugin + /// + options: Vec, + + /// + /// Plugin event hooks + /// + hooks: HashMap, + + /// + /// Plugin Exports + /// + exports: Vec, + + /// + /// Key Mapping Exports + /// + export_key_mappings: Vec, + + /// + /// Assets + /// - binary: Wasm Binary + /// - tree-sitter: tree-sitter plugin + /// - theme: App theme styles + /// - icons: icon pack + /// - syntax: Syntax theme colors + /// - readme: Readme file + /// + assets: HashMap, +} diff --git a/src/plugin.rs b/src/plugin.rs new file mode 100644 index 0000000..d4a2e6c --- /dev/null +++ b/src/plugin.rs @@ -0,0 +1,43 @@ +use std::{collections::HashMap, sync::Arc}; + +use toml::Value; + +use crate::{metadata::PluginMetadata, Error}; + +pub struct PluginApiInfo {} + +pub struct PluginInfo { + pub api: PluginApiInfo, + pub options: HashMap, +} + +pub struct Plugin { + metadata: Arc, +} + +impl Plugin { + pub fn metadata(&self) -> Result { + unimplemented!() + } + + pub fn enumerate_callables(&self) -> impl Iterator { + vec![].into_iter() + } + + // Plugin API + + pub async fn initialize(&mut self) -> Result<(), Error> { + unimplemented!() + } + + pub async fn destroy(&mut self) {} + + pub async fn handle(&self, cmd_id: String, args: Vec) -> Result { + unimplemented!() + } +} + +pub struct PluginCall { + name: String, + args: Vec, +} diff --git a/wplug_lib/Cargo.toml b/wplug_lib/Cargo.toml new file mode 100644 index 0000000..26cd39e --- /dev/null +++ b/wplug_lib/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "wplug_lib" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/wplug_lib/src/core.rs b/wplug_lib/src/core.rs new file mode 100644 index 0000000..33ae4e3 --- /dev/null +++ b/wplug_lib/src/core.rs @@ -0,0 +1,12 @@ +pub async fn api_call_async() { + +} + +pub fn api_call() { + +} + +pub fn host_info() { + +} + diff --git a/wplug_lib/src/lib.rs b/wplug_lib/src/lib.rs new file mode 100644 index 0000000..e69de29