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
// Copyright (C) 2026 Ordinary Labs, LLC.
//
// SPDX-License-Identifier: AGPL-3.0-only
use crate::cmds::accounts::get_current_account;
use clap::Subcommand;
use ordinary_api::client::OrdinaryApiClient;
#[derive(Subcommand, Debug)]
pub enum Templates {
/// add a new template to the Ordinary project
Add {
/// template name
name: String,
/// HTTP route (must start with leading "/")
route: String,
/// MIME type for template output:
/// [reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types/Common_types)
mime: String,
/// whether the template is an error template
#[arg(short, long)]
error: Option<bool>,
},
/// upload templates to application running on `ordinaryd` instance
Upload {
/// name of a specific template to upload (optional).
/// will upload all when the `--name` flag is not passed.
#[arg(short, long)]
name: Option<String>,
},
}
impl Templates {
pub async fn handle(
&self,
api_domain: Option<&str>,
accept_invalid_certs: bool,
project: &str,
insecure: bool,
) -> anyhow::Result<()> {
let account = get_current_account(insecure)?;
let client = OrdinaryApiClient::new(
&account.host,
&account.name,
api_domain,
accept_invalid_certs,
crate::USER_AGENT,
false,
)?;
match self {
Self::Add {
name,
route,
mime,
error,
} => {
ordinary_modify::add_template(
project,
name,
route,
mime,
"",
"",
"",
error.unwrap_or(false),
None,
None,
)?;
}
Self::Upload { name } => {
if let Some(name) = name {
client.upload(project, name).await?;
} else {
client.upload_all(project).await?;
}
}
}
Ok(())
}
}