plantuml_server_client_rs/
mode.rs1mod no_watch;
2mod watch;
3
4use crate::mode::no_watch::no_watch;
5use crate::mode::watch::WatchInner;
6use crate::{Client, Locate};
7use anyhow::{Context as _, Result};
8use std::path::PathBuf;
9use std::sync::Arc;
10use std::time::Duration;
11
12pub enum Mode {
14 Stdin,
16
17 NoWatch(Vec<PathBuf>),
19
20 Watch(WatchInner),
22}
23
24impl Mode {
25 pub async fn run(self, client: Arc<Client>, output: Arc<Locate>) -> Result<()> {
27 match self {
28 Mode::Stdin => {
29 client
30 .request(None.into(), &output)
31 .await
32 .context("failed to request from stdin")?;
33 }
34
35 Mode::NoWatch(input_files) => {
36 no_watch(client, input_files, output)
37 .await
38 .context("failed to request from files")?;
39 }
40
41 Mode::Watch(mode) => {
42 mode.run(client, output).await.context("failed to watch")?;
43 }
44 }
45
46 Ok(())
47 }
48
49 pub fn new_watch(current_dir: PathBuf, input_files: Vec<PathBuf>, throttle: Duration) -> Self {
50 Self::Watch(WatchInner::new(current_dir, input_files, throttle))
51 }
52}