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
use crate::cmds::accounts::get_current_account;
use clap::Subcommand;
use ordinary_api::client::OrdinaryApiClient;
use std::error::Error;
#[derive(Subcommand)]
pub enum Actions {
/// add a new action to your Ordinary project
Add {
/// action name
name: String,
/// language the action runs
lang: String,
/// whether the action is transactional
transactional: Option<bool>,
},
/// install actions to application running on `ordinaryd` instance
Put {
/// name of a specific action to install (optional).
/// will install all when the `--name` flag is not passed.
#[arg(short, long)]
name: Option<String>,
},
}
impl Actions {
pub async fn handle(
&self,
host_domain: Option<&str>,
accept_invalid_certs: bool,
project: &str,
insecure: bool,
) -> Result<(), Box<dyn Error>> {
let account = get_current_account(insecure)?;
let client = OrdinaryApiClient::new(
&account.host,
&account.name,
host_domain,
accept_invalid_certs,
);
match self {
Self::Add {
name,
lang,
transactional,
} => {
ordinary_modify::add_action(project, name, lang, (), (), (), transactional, ())?;
}
Self::Put { name } => {
if let Some(name) = name {
client.install(project, name).await?;
} else {
client.install_all(project).await?;
}
}
}
Ok(())
}
}