-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlib.rs
More file actions
189 lines (169 loc) · 5 KB
/
lib.rs
File metadata and controls
189 lines (169 loc) · 5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
use std::result::Result;
use tauri::Manager;
pub mod cli;
pub mod commands;
pub mod types;
pub use types::{enriched, generated};
#[tauri::command]
async fn check_flow_binary() -> Result<(), String> {
let cli = commands::core::CliCommand::new();
cli.check_binary().await.map_err(|e| e.to_string())
}
#[tauri::command]
async fn get_config() -> Result<generated::config::Config, String> {
let runner = cli::cli_executor();
runner.config.get().await.map_err(|e| e.to_string())
}
#[tauri::command]
async fn set_config_theme(theme: String) -> Result<String, String> {
let runner = cli::cli_executor();
runner
.config
.set_theme(&theme)
.await
.map_err(|e| e.to_string())
}
#[tauri::command]
async fn set_config_workspace_mode(mode: String) -> Result<String, String> {
let runner = cli::cli_executor();
runner
.config
.set_workspace_mode(&mode)
.await
.map_err(|e| e.to_string())
}
#[tauri::command]
async fn set_config_log_mode(mode: String) -> Result<String, String> {
let runner = cli::cli_executor();
runner
.config
.set_log_mode(&mode)
.await
.map_err(|e| e.to_string())
}
#[tauri::command]
async fn set_config_namespace(namespace: String) -> Result<String, String> {
let runner = cli::cli_executor();
runner
.config
.set_namespace(&namespace)
.await
.map_err(|e| e.to_string())
}
#[tauri::command]
async fn set_config_timeout(timeout: String) -> Result<String, String> {
let runner = cli::cli_executor();
runner
.config
.set_timeout(&timeout)
.await
.map_err(|e| e.to_string())
}
#[tauri::command]
async fn get_workspace(name: String) -> Result<enriched::Workspace, String> {
let runner = cli::cli_executor();
runner.workspace.get(&name).await.map_err(|e| e.to_string())
}
#[tauri::command]
async fn set_workspace(name: String, fixed: bool) -> Result<String, String> {
let runner = cli::cli_executor();
runner
.workspace
.switch(&name, fixed)
.await
.map_err(|e| e.to_string())
}
#[tauri::command]
async fn list_workspaces() -> Result<Vec<enriched::Workspace>, String> {
let runner = cli::cli_executor();
runner.workspace.list().await.map_err(|e| e.to_string())
}
#[tauri::command]
async fn get_executable(executable_ref: String) -> Result<enriched::Executable, String> {
let runner = cli::cli_executor();
runner
.executable
.get(&executable_ref)
.await
.map_err(|e| e.to_string())
}
#[tauri::command]
async fn list_executables(
workspace: Option<String>,
namespace: Option<String>,
tags: Option<Vec<String>>,
verb: Option<String>,
filter: Option<String>,
) -> Result<Vec<enriched::Executable>, String> {
let runner = cli::cli_executor();
// Convert owned Strings into borrowed &str slices expected by the command layer
let tags_ref_vec: Option<Vec<&str>> = tags
.as_ref()
.map(|v| v.iter().map(|s| s.as_str()).collect());
runner
.executable
.list(
workspace.as_deref(),
namespace.as_deref(),
tags_ref_vec.as_deref(),
verb.as_deref(),
filter.as_deref(),
)
.await
.map_err(|e| e.to_string())
}
#[tauri::command]
async fn sync() -> Result<String, String> {
let runner = cli::cli_executor();
runner.executable.sync().await.map_err(|e| e.to_string())
}
#[tauri::command]
async fn execute(
app: tauri::AppHandle,
verb: String,
executable_id: String,
args: Vec<String>,
params: Option<std::collections::HashMap<String, String>>,
) -> Result<(), String> {
let runner = cli::cli_executor();
let args: Vec<&str> = args.iter().map(|s| s.as_str()).collect();
runner
.executable
.execute::<()>(app, &verb, &executable_id, &args, params)
.await
.map_err(|e| e.to_string())
}
#[tauri::command]
async fn reload_window(app: tauri::AppHandle) -> Result<(), String> {
app.get_webview_window("main")
.ok_or_else(|| "Main window not found".to_string())?
.reload()
.map_err(|e| e.to_string())
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_log::Builder::new().build())
.plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_opener::init())
.setup(|_app| Ok(()))
.invoke_handler(tauri::generate_handler![
check_flow_binary,
sync,
execute,
list_executables,
get_executable,
get_workspace,
set_workspace,
list_workspaces,
get_config,
reload_window,
set_config_theme,
set_config_workspace_mode,
set_config_log_mode,
set_config_namespace,
set_config_timeout,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}