Skip to main content

ordinary/cmds/
actions.rs

1// Copyright (C) 2026 Ordinary Labs, LLC.
2//
3// SPDX-License-Identifier: AGPL-3.0-only
4
5use crate::cmds::accounts::get_current_account;
6use clap::Subcommand;
7use ordinary_api::client::OrdinaryApiClient;
8
9#[derive(Subcommand, Debug)]
10pub enum Actions {
11    /// add a new action to your Ordinary project
12    Add {
13        /// action name
14        name: String,
15        /// language the action runs
16        lang: String,
17        /// whether the action is transactional
18        transactional: Option<bool>,
19    },
20    /// install actions to application running on `ordinaryd` instance
21    Install {
22        /// name of a specific action to install (optional).
23        /// will install all when the `--name` flag is not passed.
24        #[arg(short, long)]
25        name: Option<String>,
26    },
27}
28
29impl Actions {
30    pub async fn handle(
31        &self,
32        api_domain: Option<&str>,
33        accept_invalid_certs: bool,
34        project: &str,
35        insecure: bool,
36    ) -> anyhow::Result<()> {
37        match self {
38            Self::Add {
39                name,
40                lang,
41                transactional,
42            } => {
43                ordinary_modify::add_action(project, name, lang, (), (), (), transactional, ())?;
44            }
45            Self::Install { name } => {
46                let account = get_current_account(insecure)?;
47                let client = OrdinaryApiClient::new(
48                    &account.host,
49                    &account.name,
50                    api_domain,
51                    accept_invalid_certs,
52                    crate::USER_AGENT,
53                    false,
54                )?;
55
56                if let Some(name) = name {
57                    client.install(project, name).await?;
58                } else {
59                    client.install_all(project).await?;
60                }
61            }
62        }
63
64        Ok(())
65    }
66}