Skip to main content

purple_ssh/messages/
cli.rs

1// ── Add host validation ─────────────────────────────────────────
2
3pub const ALIAS_EMPTY: &str = "Alias can't be empty. Use --alias to specify one.";
4pub const ALIAS_WHITESPACE: &str =
5    "Alias can't contain whitespace. Use --alias to pick a simpler name.";
6pub const ALIAS_PATTERN_CHARS: &str =
7    "Alias can't contain pattern characters. Use --alias to pick a different name.";
8pub const HOSTNAME_WHITESPACE: &str = "Hostname can't contain whitespace.";
9pub const USER_WHITESPACE: &str = "User can't contain whitespace.";
10pub const PASSWORD_EMPTY: &str = "Password can't be empty.";
11pub const CANCELLED: &str = "Cancelled.";
12pub const DESCRIPTION_CONTROL_CHARS: &str = "Description contains control characters.";
13
14pub use super::contains_control_chars as control_chars;
15
16pub fn welcome(alias: &str) -> String {
17    format!("Welcome aboard, {}!", alias)
18}
19
20// ── Import ──────────────────────────────────────────────────────
21
22pub const IMPORT_NO_FILE: &str =
23    "Provide a file or use --known-hosts. Run 'purple import --help' for details.";
24
25// ── Provider CLI ────────────────────────────────────────────────
26
27pub const NO_PROVIDERS: &str = "No providers configured. Run 'purple provider add' to set one up.";
28
29pub fn no_config_for(provider: &str) -> String {
30    format!(
31        "No configuration for {}. Run 'purple provider add {}' first.",
32        provider, provider
33    )
34}
35
36pub fn saved_config(provider: &str) -> String {
37    format!("Saved {} configuration.", provider)
38}
39
40pub fn no_config_to_remove(provider: &str) -> String {
41    format!("No configuration for '{}'. Nothing to remove.", provider)
42}
43
44pub fn removed_config(provider: &str) -> String {
45    format!("Removed {} configuration.", provider)
46}
47
48// ── Tunnel CLI ──────────────────────────────────────────────────
49
50pub fn no_tunnels_for(alias: &str) -> String {
51    format!("No tunnels configured for {}.", alias)
52}
53
54pub fn tunnels_for(alias: &str) -> String {
55    format!("Tunnels for {}:", alias)
56}
57
58pub const NO_TUNNELS: &str = "No tunnels configured.";
59
60pub fn starting_tunnel(alias: &str) -> String {
61    format!("Starting tunnel for {}... (Ctrl+C to stop)", alias)
62}
63
64pub fn host_not_found(alias: &str) -> String {
65    format!("No host '{}' found.", alias)
66}
67
68pub fn added_forward(forward: &str, alias: &str) -> String {
69    format!("Added {} to {}.", forward, alias)
70}
71
72pub fn forward_exists(forward: &str, alias: &str) -> String {
73    format!("Forward {} already exists on {}.", forward, alias)
74}
75
76pub fn forward_not_found(forward: &str, alias: &str) -> String {
77    format!("No matching forward {} found on {}.", forward, alias)
78}
79
80pub fn removed_forward(forward: &str, alias: &str) -> String {
81    format!("Removed {} from {}.", forward, alias)
82}
83
84pub fn no_forwards(alias: &str) -> String {
85    format!("No forwarding directives configured for '{}'.", alias)
86}
87
88// ── Snippet CLI ─────────────────────────────────────────────────
89
90pub const NO_SNIPPETS: &str = "No snippets configured. Use 'purple snippet add' to create one.";
91
92pub use super::snippet_added;
93pub use super::snippet_removed;
94pub use super::snippet_updated;
95
96pub fn snippet_not_found(name: &str) -> String {
97    format!("No snippet '{}' found.", name)
98}
99
100pub fn no_hosts_with_tag(tag: &str) -> String {
101    format!("No hosts found with tag '{}'.", tag)
102}
103
104pub const SPECIFY_TARGET: &str = "Specify a host alias, --tag or --all.";
105
106// ── Run/exec output ─────────────────────────────────────────────
107
108pub fn beaming_up(alias: &str) -> String {
109    format!("Beaming you up to {}...\n", alias)
110}
111
112pub fn running_snippet_on(name: &str, alias: &str) -> String {
113    format!("Running '{}' on {}...\n", name, alias)
114}
115
116pub fn host_separator(alias: &str) -> String {
117    format!("── {} ──", alias)
118}
119
120pub fn exited_with_code(code: i32) -> String {
121    format!("Exited with code {}.", code)
122}
123
124pub const DONE: &str = "Done.";
125
126pub fn done_multi(name: &str, count: usize) -> String {
127    format!("Done. Ran '{}' on {} hosts.", name, count)
128}
129
130pub const PRESS_ENTER: &str = "Press Enter to continue...";
131
132pub fn host_failed(alias: &str, e: &impl std::fmt::Display) -> String {
133    format!("[{}] Failed: {}", alias, e)
134}
135
136pub fn skipping_host(alias: &str, e: &impl std::fmt::Display) -> String {
137    format!("Skipping {}: {}", alias, e)
138}
139
140// ── Password CLI ────────────────────────────────────────────────
141
142pub fn password_removed(alias: &str) -> String {
143    format!("Password removed for {}.", alias)
144}
145
146// ── Log CLI ─────────────────────────────────────────────────────
147
148pub fn log_deleted(path: &impl std::fmt::Display) -> String {
149    format!("Log file deleted: {}", path)
150}
151
152pub fn no_log_file(path: &impl std::fmt::Display) -> String {
153    format!("No log file found at {}", path)
154}
155
156// ── Theme CLI ───────────────────────────────────────────────────
157
158pub const BUILTIN_THEMES: &str = "Built-in themes:";
159pub const CUSTOM_THEMES: &str = "\nCustom themes:";
160
161pub fn theme_set(name: &str) -> String {
162    format!("Theme set to: {}", name)
163}
164
165// ── Sync output ─────────────────────────────────────────────────
166
167pub fn syncing(name: &str, summary: &str) -> String {
168    format!("\x1b[2K\rSyncing {}... {}", name, summary)
169}
170
171pub fn servers_found_with_failures(count: usize, failures: usize, total: usize) -> String {
172    format!(
173        "{} servers found ({} of {} failed to fetch).",
174        count, failures, total
175    )
176}
177
178pub fn servers_found(count: usize) -> String {
179    format!("{} servers found.", count)
180}
181
182pub fn sync_result(prefix: &str, added: usize, updated: usize, unchanged: usize) -> String {
183    format!(
184        "{}Added {}, updated {}, unchanged {}.",
185        prefix, added, updated, unchanged
186    )
187}
188
189pub fn sync_removed(count: usize) -> String {
190    format!("  Removed {}.", count)
191}
192
193pub fn sync_stale(count: usize) -> String {
194    format!("  Marked {} stale.", count)
195}
196
197pub fn sync_skip_remove(display_name: &str) -> String {
198    format!(
199        "! {}: skipping --remove due to partial failures.",
200        display_name
201    )
202}
203
204pub fn sync_error(display_name: &str, e: &impl std::fmt::Display) -> String {
205    format!("! {}: {}", display_name, e)
206}
207
208pub const SYNC_SKIP_WRITE: &str =
209    "! Skipping config write due to sync failures. Fix the errors and re-run.";
210
211// ── Provider validation (CLI) ───────────────────────────────────
212
213pub const PROXMOX_URL_REQUIRED: &str =
214    "Proxmox requires --url (e.g. --url https://pve.example.com:8006).";
215pub const AWS_REGIONS_REQUIRED: &str =
216    "AWS requires --regions (e.g. --regions us-east-1,eu-west-1).";
217pub const AZURE_REGIONS_REQUIRED: &str =
218    "Azure requires --regions with one or more subscription IDs.";
219pub const GCP_PROJECT_REQUIRED: &str = "GCP requires --project (e.g. --project my-gcp-project-id).";
220pub use super::ALIAS_PREFIX_INVALID;
221
222pub const WARN_URL_NOT_USED: &str =
223    "Warning: --url is only used by the Proxmox provider. Ignoring.";
224pub const WARN_PROFILE_NOT_USED: &str =
225    "Warning: --profile is only used by the AWS provider. Ignoring.";
226pub const WARN_PROJECT_NOT_USED: &str =
227    "Warning: --project is only used by the GCP provider. Ignoring.";
228pub const WARN_COMPARTMENT_NOT_USED: &str =
229    "Warning: --compartment is only used by the Oracle provider. Ignoring.";
230
231// ── Vault CLI ───────────────────────────────────────────────────
232
233pub fn vault_no_role(alias: &str) -> String {
234    format!(
235        "No Vault SSH role configured for '{}'. Set it in the host form \
236         (Vault SSH Role field) or in the provider config (vault_role).",
237        alias
238    )
239}
240
241pub fn vault_cert_signed(path: &impl std::fmt::Display) -> String {
242    format!("Certificate signed: {}", path)
243}
244
245pub fn vault_sign_failed(e: &impl std::fmt::Display) -> String {
246    format!("failed: {}", e)
247}
248
249pub fn vault_config_update_warning(e: &impl std::fmt::Display) -> String {
250    format!("Warning: Failed to update SSH config: {}", e)
251}
252
253// ── List hosts ──────────────────────────────────────────────────
254
255pub const NO_HOSTS: &str = "No hosts configured. Run 'purple' to add some!";
256
257// ── Token ───────────────────────────────────────────────────────
258
259pub const NO_TOKEN: &str =
260    "No token provided. Use --token, --token-stdin, or set PURPLE_TOKEN env var.";
261
262// ── What's new (CLI) ────────────────────────────────────────────
263
264pub mod whats_new {
265    pub const HEADER: &str = "purple release notes";
266}