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 use super::welcome_aboard as welcome;
17
18// ── Import ──────────────────────────────────────────────────────
19
20pub const IMPORT_NO_FILE: &str =
21    "Provide a file or use --known-hosts. Run 'purple import --help' for details.";
22
23// ── Provider CLI ────────────────────────────────────────────────
24
25pub const NO_PROVIDERS: &str = "No providers configured. Run 'purple provider add' to set one up.";
26
27/// All supported provider slugs as a comma-separated string. Surfaced in
28/// `unknown_provider` and `skipping_unknown_provider`. Kept as a single
29/// const so adding a new provider only updates one place.
30pub const PROVIDER_LIST: &str = "digitalocean, vultr, linode, hetzner, upcloud, proxmox, aws, \
31     scaleway, gcp, azure, tailscale, oracle, ovh, leaseweb, i3d, transip";
32
33/// Stderr line when the user passed `--provider X` for an unknown slug.
34/// Different from `skipping_unknown_provider` so each call site can
35/// evolve its wording without breaking the other.
36pub fn unknown_provider(name: &str) -> String {
37    format!("Never heard of '{}'. Try: {}.", name, PROVIDER_LIST)
38}
39
40/// Stderr line when iterating configured providers and one is unknown
41/// (e.g. config file references a since-removed provider). The sync
42/// continues with the remaining providers.
43pub fn skipping_unknown_provider(name: &str) -> String {
44    format!(
45        "Skipping unknown provider '{}'. Try: {}.",
46        name, PROVIDER_LIST
47    )
48}
49
50/// Stderr line printed by `purple add` when the alias already exists.
51/// Tells the user the exact flag to fix it instead of just complaining.
52pub fn alias_already_exists(alias: &str) -> String {
53    format!(
54        "'{}' already exists. Use --alias to pick a different name.",
55        alias
56    )
57}
58
59/// Stderr lines printed after `purple import` when some lines failed
60/// to parse or read. Use the singular/plural form via the count.
61pub fn import_parse_failures(count: usize) -> String {
62    let s = if count == 1 { "" } else { "s" };
63    format!(
64        "! {} line{} could not be parsed (invalid format).",
65        count, s
66    )
67}
68
69pub fn import_read_errors(count: usize) -> String {
70    let s = if count == 1 { "" } else { "s" };
71    format!("! {} line{} could not be read (encoding error).", count, s)
72}
73
74pub fn no_config_for(provider: &str) -> String {
75    format!(
76        "No configuration for {}. Run 'purple provider add {}' first.",
77        provider, provider
78    )
79}
80
81pub fn saved_config(provider: &str) -> String {
82    format!("Saved {} configuration.", provider)
83}
84
85pub fn no_config_to_remove(provider: &str) -> String {
86    format!("No configuration for '{}'. Nothing to remove.", provider)
87}
88
89pub fn removed_config(provider: &str) -> String {
90    format!("Removed {} configuration.", provider)
91}
92
93pub fn removed_configs(provider: &str, count: usize) -> String {
94    format!("Removed {} {} configurations.", count, provider)
95}
96
97pub fn invalid_label_flag(reason: &str) -> String {
98    format!("Invalid --label: {}", reason)
99}
100
101pub fn add_requires_label(provider: &str) -> String {
102    format!(
103        "Provider '{}' already has labeled configs. Pass --label to add another.",
104        provider
105    )
106}
107
108pub fn add_label_collides_with_bare(provider: &str) -> String {
109    format!(
110        "Provider '{}' has a bare config. Remove it first or use the TUI add flow which prompts for labels.",
111        provider
112    )
113}
114
115// ── Tunnel CLI ──────────────────────────────────────────────────
116
117pub fn no_tunnels_for(alias: &str) -> String {
118    format!("No tunnels configured for {}.", alias)
119}
120
121pub fn tunnels_for(alias: &str) -> String {
122    format!("Tunnels for {}:", alias)
123}
124
125pub const NO_TUNNELS: &str = "No tunnels configured.";
126
127pub fn starting_tunnel(alias: &str) -> String {
128    format!("Starting tunnel for {}... (Ctrl+C to stop)", alias)
129}
130
131pub fn host_not_found(alias: &str) -> String {
132    format!("No host '{}' found.", alias)
133}
134
135pub fn added_forward(forward: &str, alias: &str) -> String {
136    format!("Added {} to {}.", forward, alias)
137}
138
139pub fn forward_exists(forward: &str, alias: &str) -> String {
140    format!("Forward {} already exists on {}.", forward, alias)
141}
142
143pub fn forward_not_found(forward: &str, alias: &str) -> String {
144    format!("No matching forward {} found on {}.", forward, alias)
145}
146
147pub fn removed_forward(forward: &str, alias: &str) -> String {
148    format!("Removed {} from {}.", forward, alias)
149}
150
151pub fn no_forwards(alias: &str) -> String {
152    format!("No forwarding directives configured for '{}'.", alias)
153}
154
155pub fn save_config_failed(e: &impl std::fmt::Display) -> String {
156    format!("Failed to save config: {}", e)
157}
158
159pub fn included_host_read_only(alias: &str) -> String {
160    format!(
161        "Host '{}' is from an included file and cannot be modified.",
162        alias
163    )
164}
165
166pub fn operation_failed(e: &impl std::fmt::Display) -> String {
167    format!("Failed: {}", e)
168}
169
170// ── Snippet CLI ─────────────────────────────────────────────────
171
172pub const NO_SNIPPETS: &str = "No snippets configured. Use 'purple snippet add' to create one.";
173
174pub use super::snippet_added;
175pub use super::snippet_removed;
176pub use super::snippet_updated;
177
178pub fn snippet_not_found(name: &str) -> String {
179    format!("No snippet '{}' found.", name)
180}
181
182pub fn no_hosts_with_tag(tag: &str) -> String {
183    format!("No hosts found with tag '{}'.", tag)
184}
185
186pub const SPECIFY_TARGET: &str = "Specify a host alias, --tag or --all.";
187
188// ── Run/exec output ─────────────────────────────────────────────
189
190pub fn beaming_up(alias: &str) -> String {
191    format!("Beaming you up to {}...\n", alias)
192}
193
194pub fn running_snippet_on(name: &str, alias: &str) -> String {
195    format!("Running '{}' on {}...\n", name, alias)
196}
197
198pub fn host_separator(alias: &str) -> String {
199    format!("── {} ──", alias)
200}
201
202pub fn exited_with_code(code: i32) -> String {
203    format!("Exited with code {}.", code)
204}
205
206pub const DONE: &str = "Done.";
207
208pub fn done_multi(name: &str, count: usize) -> String {
209    format!("Done. Ran '{}' on {} hosts.", name, count)
210}
211
212pub const PRESS_ENTER: &str = "Press Enter to continue...";
213
214pub fn host_failed(alias: &str, e: &impl std::fmt::Display) -> String {
215    format!("[{}] Failed: {}", alias, e)
216}
217
218pub fn skipping_host(alias: &str, e: &impl std::fmt::Display) -> String {
219    format!("Skipping {}: {}", alias, e)
220}
221
222// ── Password CLI ────────────────────────────────────────────────
223
224pub fn password_removed(alias: &str) -> String {
225    format!("Password removed for {}.", alias)
226}
227
228// ── Log CLI ─────────────────────────────────────────────────────
229
230pub fn log_deleted(path: &impl std::fmt::Display) -> String {
231    format!("Log file deleted: {}", path)
232}
233
234pub fn no_log_file(path: &impl std::fmt::Display) -> String {
235    format!("No log file found at {}", path)
236}
237
238// ── Theme CLI ───────────────────────────────────────────────────
239
240pub const BUILTIN_THEMES: &str = "Built-in themes:";
241pub const CUSTOM_THEMES: &str = "\nCustom themes:";
242
243pub fn theme_set(name: &str) -> String {
244    format!("Theme set to: {}", name)
245}
246
247// ── Sync output ─────────────────────────────────────────────────
248
249pub fn syncing(name: &str, summary: &str) -> String {
250    format!("\x1b[2K\rSyncing {}... {}", name, summary)
251}
252
253/// One-shot "Syncing X... " prefix without the cursor-clear/CR escapes.
254/// Used before progress callbacks start emitting overwrite-style updates,
255/// so the user sees something happening even if the provider is slow to
256/// produce the first progress event.
257pub fn syncing_start(name: &str) -> String {
258    format!("Syncing {}... ", name)
259}
260
261/// Rendered before the dot-progress (`\u{2713}` or error) on each
262/// per-host vault sign in the CLI bulk path. The trailing space is
263/// intentional — the success/fail glyph follows on the same line.
264pub fn vault_signing_host(alias: &str) -> String {
265    format!("Signing {}... ", alias)
266}
267
268/// Stderr line emitted by `purple vault sign --all` when a host block
269/// disappeared between the moment we enumerated it and the moment we
270/// tried to write its CertificateFile (rename, delete, race with another
271/// process). The cert is on disk; only the wiring is missing.
272pub fn vault_sign_host_block_gone(alias: &str) -> String {
273    format!(
274        "  warning: {} no longer in ssh config; CertificateFile not written (cert saved on disk)",
275        alias
276    )
277}
278
279/// Single-word "failed." status the CLI sync output appends when a
280/// provider fetch hit a hard error. Mirrors the trailing-status pattern
281/// used by `syncing_start` so the line reads `Syncing X... failed.`.
282pub const SYNC_FAILED: &str = "failed.";
283
284pub fn servers_found_with_failures(count: usize, failures: usize, total: usize) -> String {
285    format!(
286        "{} servers found ({} of {} failed to fetch).",
287        count, failures, total
288    )
289}
290
291pub fn servers_found(count: usize) -> String {
292    format!("{} servers found.", count)
293}
294
295pub fn sync_result(prefix: &str, added: usize, updated: usize, unchanged: usize) -> String {
296    format!(
297        "{}Added {}, updated {}, unchanged {}.",
298        prefix, added, updated, unchanged
299    )
300}
301
302pub fn sync_removed(count: usize) -> String {
303    format!("  Removed {}.", count)
304}
305
306pub fn sync_stale(count: usize) -> String {
307    format!("  Marked {} stale.", count)
308}
309
310pub fn sync_skip_remove(display_name: &str) -> String {
311    format!(
312        "! {}: skipping --remove due to partial failures.",
313        display_name
314    )
315}
316
317pub fn sync_error(display_name: &str, e: &impl std::fmt::Display) -> String {
318    format!("! {}: {}", display_name, e)
319}
320
321pub const SYNC_SKIP_WRITE: &str =
322    "! Skipping config write due to sync failures. Fix the errors and re-run.";
323
324// ── Provider validation (CLI) ───────────────────────────────────
325
326pub const PROXMOX_URL_REQUIRED: &str =
327    "Proxmox requires --url (e.g. --url https://pve.example.com:8006).";
328pub const AWS_REGIONS_REQUIRED: &str =
329    "AWS requires --regions (e.g. --regions us-east-1,eu-west-1).";
330pub const AZURE_REGIONS_REQUIRED: &str =
331    "Azure requires --regions with one or more subscription IDs.";
332pub const GCP_PROJECT_REQUIRED: &str = "GCP requires --project (e.g. --project my-gcp-project-id).";
333pub use super::ALIAS_PREFIX_INVALID;
334
335pub const WARN_URL_NOT_USED: &str =
336    "Warning: --url is only used by the Proxmox provider. Ignoring.";
337pub const WARN_PROFILE_NOT_USED: &str =
338    "Warning: --profile is only used by the AWS provider. Ignoring.";
339pub const WARN_PROJECT_NOT_USED: &str =
340    "Warning: --project is only used by the GCP provider. Ignoring.";
341pub const WARN_COMPARTMENT_NOT_USED: &str =
342    "Warning: --compartment is only used by the Oracle provider. Ignoring.";
343pub const WARN_NO_VERIFY_TLS_NOT_USED: &str =
344    "Warning: --no-verify-tls is only used by the Proxmox provider. Ignoring.";
345pub const WARN_VERIFY_TLS_NOT_USED: &str =
346    "Warning: --verify-tls is only used by the Proxmox provider. Ignoring.";
347pub const WARN_REGIONS_NOT_USED: &str = "Warning: --regions is only used by the AWS, Scaleway, GCP, Azure and Oracle providers. \
348     Ignoring.";
349
350/// Per-host status prefixes for `purple sync` output. Indented two
351/// spaces so the result line aligns under the `Syncing X...` header.
352/// `--dry-run` mode prepends "Would have:" so the user knows nothing
353/// was written.
354pub const SYNC_RESULT_PREFIX_LIVE: &str = "  ";
355pub const SYNC_RESULT_PREFIX_DRY_RUN: &str = "  Would have: ";
356
357/// Stderr line printed by `purple provider add` when the user-supplied
358/// URL does not start with `https://`. CLI-flavoured: tells the user to
359/// use the `--no-verify-tls` flag, distinct from the TUI variant which
360/// references a Verify TLS toggle.
361pub const PROVIDER_URL_REQUIRES_HTTPS: &str =
362    "URL must start with https://. For self-signed certificates use --no-verify-tls.";
363
364/// Reuse the TUI form's `Token can't be empty...` lines verbatim — the
365/// remediation steps (paste a JSON file path, paste an OCI config path,
366/// grab a token from the dashboard) are identical between CLI and TUI.
367pub use super::PROVIDER_TOKEN_REQUIRED_GCP;
368pub use super::PROVIDER_TOKEN_REQUIRED_ORACLE;
369pub use super::azure_subscription_id_invalid;
370pub use super::provider_token_required;
371
372/// Stderr line printed when `purple provider add scaleway` is missing
373/// `--regions`. Mirrors the Azure/GCP/Oracle pattern of including the
374/// concrete flag form in the message.
375pub const SCALEWAY_REGIONS_REQUIRED: &str = "Scaleway requires --regions with one or more zones \
376     (e.g. --regions fr-par-1,nl-ams-1).";
377
378pub const ORACLE_COMPARTMENT_REQUIRED: &str =
379    "Oracle requires --compartment (e.g. --compartment ocid1.compartment.oc1..aaa...).";
380
381// ── Vault CLI ───────────────────────────────────────────────────
382
383pub fn vault_no_role(alias: &str) -> String {
384    format!(
385        "No Vault SSH role configured for '{}'. Set it in the host form \
386         (Vault SSH Role field) or in the provider config (vault_role).",
387        alias
388    )
389}
390
391pub fn vault_cert_signed(path: &impl std::fmt::Display) -> String {
392    format!("Certificate signed: {}", path)
393}
394
395pub fn vault_sign_failed(e: &impl std::fmt::Display) -> String {
396    format!("failed: {}", e)
397}
398
399pub fn vault_config_update_warning(e: &impl std::fmt::Display) -> String {
400    format!("Warning: Failed to update SSH config: {}", e)
401}
402
403// ── List hosts ──────────────────────────────────────────────────
404
405pub const NO_HOSTS: &str = "No hosts configured. Run 'purple' to add some!";
406
407// ── Token ───────────────────────────────────────────────────────
408
409pub const NO_TOKEN: &str =
410    "No token provided. Use --token, --token-stdin, or set PURPLE_TOKEN env var.";
411
412// ── What's new (CLI) ────────────────────────────────────────────
413
414pub mod whats_new {
415    pub const HEADER: &str = "purple release notes";
416}