81 lines
1.7 KiB
Rust
81 lines
1.7 KiB
Rust
use serde::Deserialize;
|
|
use std::collections::HashMap;
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
pub struct MenuRoot {
|
|
pub version: String,
|
|
pub menu: Vec<MenuItem>,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
pub struct MenuItem {
|
|
pub id: String,
|
|
pub title: String,
|
|
pub description: Option<String>,
|
|
#[serde(flatten)]
|
|
pub kind: MenuItemKind,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
#[serde(untagged)]
|
|
pub enum MenuItemKind {
|
|
Category { children: Vec<MenuItem> },
|
|
Action { action: Action },
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
#[serde(tag = "type", rename_all = "lowercase")]
|
|
pub enum Action {
|
|
Bash {
|
|
script: String,
|
|
#[serde(default = "default_interaction")]
|
|
interaction: InteractionMode,
|
|
#[serde(default)]
|
|
confirm: bool,
|
|
},
|
|
Download {
|
|
url: String,
|
|
filename: Option<String>,
|
|
target_dir: Option<String>,
|
|
#[serde(default)]
|
|
confirm: bool,
|
|
},
|
|
DownloadAndRun {
|
|
url: String,
|
|
filename: Option<String>,
|
|
run_args: Vec<String>,
|
|
#[serde(default)]
|
|
keep_file: bool,
|
|
#[serde(default)]
|
|
confirm: bool,
|
|
},
|
|
HttpRequest {
|
|
method: HttpMethod,
|
|
url: String,
|
|
headers: std::collections::HashMap<String, String>,
|
|
body: Option<String>,
|
|
#[serde(default)]
|
|
confirm: bool,
|
|
},
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub enum InteractionMode {
|
|
Terminal,
|
|
Structured,
|
|
}
|
|
|
|
fn default_interaction() -> InteractionMode {
|
|
InteractionMode::Terminal
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
#[serde(rename_all = "UPPERCASE")]
|
|
pub enum HttpMethod {
|
|
Get,
|
|
Post,
|
|
Put,
|
|
Delete,
|
|
}
|