dsc/cli.rs
1use clap::{ArgAction, Parser, Subcommand, ValueEnum};
2use clap_complete::Shell;
3use std::path::PathBuf;
4
5#[derive(Parser)]
6#[command(name = "dsc")]
7#[command(about = "Discourse CLI", long_about = None)]
8#[command(next_display_order = None)]
9pub struct Cli {
10 /// Path to the config file. If omitted, `dsc` consults `$DSC_CONFIG`,
11 /// then searches `./dsc.toml`, `$DSC_CONFIG_HOME/dsc.toml`
12 /// (default `~/.config/dsc/dsc.toml`), then system locations.
13 /// Errors if the given file does not exist (no silent fallthrough).
14 /// See `dsc config` for the active selection.
15 #[arg(long, short = 'c')]
16 pub config: Option<PathBuf>,
17 /// Describe destructive actions without sending them. Read-only commands
18 /// ignore the flag.
19 #[arg(long, short = 'n', global = true)]
20 pub dry_run: bool,
21 #[command(subcommand)]
22 pub command: Commands,
23}
24
25#[derive(Subcommand)]
26#[command(next_display_order = None)]
27pub enum Commands {
28 /// List configured Discourses.
29 #[command(visible_alias = "ls")]
30 #[command(after_help = "Examples:
31 dsc list
32 dsc list --tags production -f json")]
33 List {
34 /// Output format for the listing.
35 #[arg(long, short = 'f', value_enum, default_value = "text")]
36 format: OutputFormat,
37 /// Filter by tags (comma/semicolon separated, match-any).
38 #[arg(long, value_name = "tag1,tag2")]
39 tags: Option<String>,
40 /// Open each listed Discourse base URL in a browser tab/window.
41 #[arg(long, short = 'o')]
42 open: bool,
43 /// Include empty results and verbose listing details where supported.
44 #[arg(long, short = 'v')]
45 verbose: bool,
46 #[command(subcommand)]
47 command: Option<ListCommand>,
48 },
49 /// Add one or more Discourses to the config.
50 #[command(visible_alias = "a")]
51 #[command(after_help = "Examples:
52 dsc add myforum
53 dsc add forum-a,forum-b -i")]
54 Add {
55 /// Comma-separated discourse names to add.
56 names: String,
57 /// Prompt for additional optional fields while adding.
58 #[arg(long, short = 'i')]
59 interactive: bool,
60 },
61 /// Import Discourses from a file or stdin.
62 #[command(visible_alias = "imp")]
63 #[command(after_help = "Examples:
64 dsc import forums.csv
65 cat forums.txt | dsc import")]
66 Import {
67 /// Path to import input (text/CSV). Reads stdin when omitted.
68 path: Option<PathBuf>,
69 },
70 /// Run remote OS + Discourse update workflow for one or all Discourses.
71 #[command(visible_alias = "up")]
72 #[command(after_help = "Examples:
73 dsc update myforum
74 dsc update all -p # update every forum in parallel")]
75 Update {
76 /// Discourse name, or 'all' to update every configured Discourse.
77 name: String,
78 /// Parallel update mode for `dsc update all`.
79 #[arg(long, short = 'p')]
80 parallel: bool,
81 /// Maximum workers when parallel mode is enabled (default: 3).
82 #[arg(long, short = 'm')]
83 max: Option<usize>,
84 /// Disable changelog posting (posting prompt is on by default).
85 #[arg(long = "no-changelog", action = ArgAction::SetFalse, default_value_t = true)]
86 post_changelog: bool,
87 /// Auto-confirm changelog posting prompt (non-interactive mode).
88 #[arg(long, short = 'y')]
89 yes: bool,
90 },
91 /// Manage custom emoji.
92 #[command(visible_alias = "em")]
93 #[command(after_help = "Examples:
94 dsc emoji push myforum ./emoji/ # bulk-upload a folder
95 dsc emoji list myforum")]
96 Emoji {
97 #[command(subcommand)]
98 command: EmojiCommand,
99 },
100 /// Pull/push/sync topics as local Markdown.
101 #[command(visible_alias = "t")]
102 #[command(after_help = "Examples:
103 dsc topic pull myforum 123 topic.md
104 dsc topic push myforum 123 topic.md
105 dsc topic title myforum 123 \"A clearer title\"")]
106 Topic {
107 #[command(subcommand)]
108 command: TopicCommand,
109 },
110 /// List/copy/pull/push categories.
111 #[command(visible_alias = "cat")]
112 #[command(after_help = "Examples:
113 dsc category pull myforum 34 ./playbook/
114 dsc category push -n myforum 34 ./playbook/ # -n previews the plan")]
115 Category {
116 #[command(subcommand)]
117 command: CategoryCommand,
118 },
119 /// List/inspect/copy groups.
120 #[command(visible_alias = "grp")]
121 #[command(after_help = "Examples:
122 dsc group list myforum
123 dsc group info myforum staff")]
124 Group {
125 #[command(subcommand)]
126 command: GroupCommand,
127 },
128 /// Operations that act from a user's perspective.
129 #[command(visible_alias = "usr")]
130 #[command(after_help = "Examples:
131 dsc user list myforum -f json
132 dsc user info myforum alice
133 dsc user activity myforum alice")]
134 User {
135 #[command(subcommand)]
136 command: UserCommand,
137 },
138 /// Send invites — single or bulk from a file.
139 #[command(visible_alias = "inv")]
140 #[command(after_help = "Examples:
141 dsc invite send myforum newuser@example.com
142 dsc invite bulk myforum emails.txt")]
143 Invite {
144 #[command(subcommand)]
145 command: InviteCommand,
146 },
147 /// Manage API keys (admin scope).
148 #[command(visible_alias = "ak")]
149 #[command(after_help = "Examples:
150 dsc api-key list myforum
151 dsc api-key create myforum ci-bot")]
152 ApiKey {
153 #[command(subcommand)]
154 command: ApiKeyCommand,
155 },
156 /// Send and list private messages.
157 #[command(visible_alias = "msg")]
158 #[command(after_help = "Examples:
159 dsc pm list myforum alice
160 dsc pm send myforum alice -t Greetings body.md")]
161 Pm {
162 #[command(subcommand)]
163 command: PmCommand,
164 },
165 /// Create/list/restore backups.
166 #[command(visible_alias = "bk")]
167 #[command(after_help = "Examples:
168 dsc backup create myforum
169 dsc backup pull myforum backup.tar.gz")]
170 Backup {
171 #[command(subcommand)]
172 command: BackupCommand,
173 },
174 /// List/pull/push color palettes.
175 #[command(visible_alias = "pal")]
176 #[command(after_help = "Examples (now lives under `dsc theme palette`):
177 dsc theme palette list myforum
178 dsc theme palette pull myforum 2 palette.json")]
179 Palette {
180 #[command(subcommand)]
181 command: PaletteCommand,
182 },
183 /// List/install/remove plugins.
184 #[command(visible_alias = "plg")]
185 #[command(after_help = "Examples:
186 dsc plugin list myforum
187 dsc plugin install myforum https://github.com/org/plugin")]
188 Plugin {
189 #[command(subcommand)]
190 command: PluginCommand,
191 },
192 /// List/install/remove/pull/push/duplicate themes.
193 #[command(visible_alias = "th")]
194 #[command(after_help = "Examples:
195 dsc theme list myforum
196 dsc theme show myforum 11
197 dsc theme setting set myforum 14 links_position left")]
198 Theme {
199 #[command(subcommand)]
200 command: ThemeCommand,
201 },
202 /// Get, set, list, diff, audit, and snapshot site settings.
203 ///
204 /// To discover what settings exist, `dsc setting pull` writes a
205 /// self-documenting catalog of every setting (value, default, type,
206 /// category, and Discourse's own description) - the reference guide for
207 /// what is available and adjustable.
208 #[command(visible_alias = "set")]
209 #[command(after_help = "Examples:
210 dsc setting pull myforum settings.yaml # catalog EVERY setting + descriptions (start here)
211 dsc setting get myforum title
212 dsc setting set myforum login_required true
213 dsc setting audit login_required # compare one setting across all forums")]
214 Setting {
215 #[command(subcommand)]
216 command: SettingCommand,
217 },
218 /// Export everything a forum holds about one person into a reviewable
219 /// Subject Access Request (SAR / GDPR Art. 15) bundle. Single forum.
220 #[command(after_help = "Examples:
221 dsc sar myforum jane@example.com
222 dsc sar myforum jane-doe --messages # include private messages")]
223 Sar {
224 /// Discourse name.
225 discourse: String,
226 /// Subject: a username or an email address.
227 user: String,
228 /// Output directory (default `sar-<username>-<date>/`).
229 #[arg(long, short = 'o')]
230 output: Option<PathBuf>,
231 /// Also collect the subject's private messages. Off by default: PMs
232 /// contain third-party personal data and need a disclose/redact
233 /// judgement. Written with a REVIEW REQUIRED banner when included.
234 #[arg(long)]
235 messages: bool,
236 },
237 /// Manage the tag taxonomy: list/pull/push tags and tag groups.
238 #[command(visible_alias = "tg")]
239 #[command(after_help = "Examples:
240 dsc tag pull myforum tags.yaml
241 dsc tag rename myforum old-tag new-tag")]
242 Tag {
243 #[command(subcommand)]
244 command: TagCommand,
245 },
246 /// Post-level operations: edit / delete / move.
247 #[command(visible_alias = "po")]
248 #[command(after_help = "Examples:
249 dsc post edit myforum 456 body.md
250 dsc post move myforum 456 789")]
251 Post {
252 #[command(subcommand)]
253 command: PostCommand,
254 },
255 /// Open a Discourse in the default browser.
256 #[command(visible_alias = "o")]
257 #[command(after_help = "Examples:
258 dsc open myforum")]
259 Open {
260 /// Discourse name.
261 discourse: String,
262 },
263 /// Harden a fresh Ubuntu server reachable via `ssh root@host`.
264 ///
265 /// **Stage 1 (current):** creates a non-root sudo user, installs the
266 /// given pubkey to their authorized_keys, and verifies the new-user
267 /// SSH login works. Does NOT yet tighten sshd_config, install Docker
268 /// / fail2ban / etc — those come in follow-up releases.
269 ///
270 /// Defaults can be overridden in the `[harden]` block of dsc.toml;
271 /// the flags below override that block on a per-run basis.
272 #[command(visible_alias = "hd")]
273 #[command(after_help = "Examples:
274 dsc harden 203.0.113.10 --new-user discourse --pubkey-file ~/.ssh/id_ed25519.pub")]
275 Harden {
276 /// Target hostname or IP (reachable via SSH).
277 host: String,
278 /// Username to SSH in as initially. Defaults to `root`, which is
279 /// what a fresh cloud-provisioned box typically has.
280 #[arg(long, default_value = "root")]
281 ssh_user: String,
282 /// Username for the new sudo-enabled non-root account. Overrides
283 /// `[harden].new_user` from dsc.toml. Built-in default: `discourse`.
284 #[arg(long)]
285 new_user: Option<String>,
286 /// SSH port to move the daemon to in stage 2. Overrides
287 /// `[harden].ssh_port`. Built-in default: 2227. Parsed now so the
288 /// CLI is stable; not yet applied in stage 1.
289 #[arg(long)]
290 ssh_port: Option<u16>,
291 /// Path to an SSH public key file whose contents will be added to
292 /// the new user's authorized_keys. A typical value is
293 /// `~/.ssh/<hostname>.pub` — the per-server keypair pattern in
294 /// the Bawmedical hardening playbook.
295 #[arg(long)]
296 pubkey_file: PathBuf,
297 },
298 /// Community-health analytics — growth, activity, and health metrics
299 /// for a Discourse, with optional period-over-period comparison.
300 ///
301 /// See `spec/analytics.md` for the full spec. v1 ships every metric
302 /// that maps onto a single `/admin/reports/{id}.json` endpoint;
303 /// derivation-heavy ones (e.g. lost regulars, top-10 share) print
304 /// `— (n/i)` until follow-up implementation lands.
305 #[command(visible_alias = "stats")]
306 #[command(after_help = "Examples:
307 dsc analytics myforum
308 dsc analytics myforum --section growth --since 30d")]
309 Analytics {
310 /// Discourse name.
311 discourse: String,
312 /// Window to report on. Same syntax as `dsc user activity --since`
313 /// (e.g. `7d`, `24h`, `1m`, ISO-8601). Ignored when `--snapshot`
314 /// is set. Default: 30d.
315 #[arg(long, short = 's', default_value = "30d")]
316 since: String,
317 /// Also fetch the immediately preceding window of equal length and
318 /// show a delta column. Mutually exclusive with `--snapshot`.
319 #[arg(long, short = 'c', conflicts_with = "snapshot")]
320 compare: bool,
321 /// Multi-window snapshot mode. Reports each metric across several
322 /// preset windows (`--periods`) so you see growth/health trends
323 /// at a glance. Replaces `--since` + `--compare`.
324 #[arg(long)]
325 snapshot: bool,
326 /// Comma-separated periods for `--snapshot`. Default: `24h,7d,30d,1y`.
327 #[arg(long, requires = "snapshot")]
328 periods: Option<String>,
329 /// Restrict output to one section.
330 #[arg(long, value_enum, default_value = "all")]
331 section: SectionArg,
332 /// Output format. `table` is DuckDB-style box-drawing; falls
333 /// through to `text` automatically when stdout isn't a TTY.
334 #[arg(long, short = 'f', value_enum, default_value = "text")]
335 format: AnalyticsFormat,
336 },
337 /// Search topics on a Discourse.
338 #[command(visible_alias = "s")]
339 #[command(after_help = "Examples:
340 dsc search myforum \"status:open category:bugs\"
341 dsc search myforum @alice -f json")]
342 Search {
343 /// Discourse name.
344 discourse: String,
345 /// Search query (passed through verbatim, including any
346 /// Discourse filter syntax like `category:foo` or `@user`).
347 query: String,
348 /// Output format.
349 #[arg(long, short = 'f', value_enum, default_value = "text")]
350 format: ListFormat,
351 },
352 /// Upload a file. Prints the resulting upload:// short URL by default.
353 #[command(visible_alias = "u")]
354 #[command(after_help = "Examples:
355 dsc upload myforum ./diagram.png")]
356 Upload {
357 /// Discourse name.
358 discourse: String,
359 /// Path to the file to upload.
360 file: PathBuf,
361 /// Discourse upload context. Default `composer` is correct for
362 /// embedding in posts; other values include `avatar`,
363 /// `profile_background`, `card_background`, `custom_emoji`.
364 #[arg(long, short = 't', default_value = "composer")]
365 upload_type: String,
366 /// Output format. Text mode prints just the short URL.
367 #[arg(long, short = 'f', value_enum, default_value = "text")]
368 format: ListFormat,
369 },
370 /// Inspect and validate configuration.
371 #[command(visible_alias = "cfg")]
372 #[command(after_help = "Examples:
373 dsc config # show active config + search order
374 dsc config check # probe API auth + SSH for every forum")]
375 Config {
376 #[command(subcommand)]
377 command: Option<ConfigCommand>,
378 },
379 /// Generate shell completion scripts.
380 #[command(visible_alias = "comp")]
381 #[command(after_help = "Examples:
382 dsc completions zsh > _dsc
383 dsc completions bash > dsc.bash")]
384 Completions {
385 /// Target shell.
386 #[arg(value_enum)]
387 shell: CompletionShell,
388 /// Output directory. Prints to stdout when omitted.
389 #[arg(long, short = 'd')]
390 dir: Option<PathBuf>,
391 },
392 /// Generate man pages for `dsc` and every subcommand.
393 ///
394 /// Writes one ROFF-formatted file per (sub)command (e.g. `dsc.1`,
395 /// `dsc-tag-pull.1`) into the given directory. Distro packagers
396 /// install these into section 1 of the man path. Run `gzip -9` on
397 /// the output if your packaging convention expects compressed pages.
398 #[command(visible_alias = "manpages")]
399 #[command(after_help = "Examples:
400 dsc man --dir ./man")]
401 Man {
402 /// Output directory. Required - this command always writes to disk.
403 #[arg(long, short = 'd')]
404 dir: PathBuf,
405 },
406 /// Print the dsc version.
407 #[command(visible_alias = "ver")]
408 /// Print dsc's own version, or a configured forum's Discourse version + commit.
409 #[command(after_help = "Examples:
410 dsc version # dsc's own version
411 dsc version accm # the forum's live Discourse version + git commit")]
412 Version {
413 /// Forum name. When given, print that forum's live Discourse version
414 /// and git commit (from /about.json, via the configured API key)
415 /// instead of dsc's own version.
416 discourse: Option<String>,
417 },
418}
419
420#[derive(Subcommand)]
421#[command(next_display_order = None)]
422pub enum ConfigCommand {
423 /// Probe each configured Discourse: API auth and (optionally) SSH reachability.
424 #[command(visible_alias = "ck")]
425 Check {
426 /// Output format.
427 #[arg(long, short = 'f', value_enum, default_value = "text")]
428 format: ListFormat,
429 /// Skip the SSH reachability probe.
430 #[arg(long)]
431 skip_ssh: bool,
432 /// Probe forums concurrently (results stream fastest-first). Much
433 /// faster on a large fleet.
434 #[arg(long, short = 'p')]
435 parallel: bool,
436 /// Maximum workers when --parallel is set (default: 8).
437 #[arg(long, short = 'm')]
438 max: Option<usize>,
439 },
440}
441
442#[derive(Subcommand)]
443#[command(next_display_order = None)]
444pub enum ListCommand {
445 /// Sort discourse entries by name and rewrite config in-place.
446 /// Also inserts placeholder values for unset template keys.
447 #[command(visible_alias = "ty")]
448 Tidy,
449}
450
451#[derive(Subcommand)]
452#[command(next_display_order = None)]
453pub enum EmojiCommand {
454 /// Pull all custom emoji from a Discourse into a local directory.
455 #[command(visible_alias = "pl")]
456 Pull {
457 /// Discourse name.
458 discourse: String,
459 /// Local directory to save emoji images into.
460 output_dir: PathBuf,
461 },
462 /// Push (upload) one emoji file, or bulk-upload from a directory (alias: add).
463 #[command(visible_alias = "ps", alias = "add")]
464 Push {
465 /// Discourse name.
466 discourse: String,
467 /// Local file or directory path.
468 emoji_path: PathBuf,
469 /// Optional emoji name (file uploads only).
470 emoji_name: Option<String>,
471 },
472
473 /// List custom emojis on a Discourse.
474 #[command(visible_alias = "ls")]
475 List {
476 /// Discourse name.
477 discourse: String,
478 /// Output format.
479 #[arg(long, short = 'f', value_enum, default_value = "text")]
480 format: ListFormat,
481 /// Include additional fields where supported.
482 #[arg(long, short = 'v')]
483 verbose: bool,
484 /// Render inline images when terminal protocol support is available.
485 #[arg(long, short = 'i')]
486 inline: bool,
487 },
488}
489
490#[derive(Subcommand)]
491#[command(next_display_order = None)]
492pub enum TopicCommand {
493 /// Pull a topic to a local Markdown file.
494 #[command(visible_alias = "pl")]
495 Pull {
496 /// Discourse name.
497 discourse: String,
498 /// Topic ID.
499 topic_id: u64,
500 /// Destination file or directory (auto-derived when omitted).
501 local_path: Option<PathBuf>,
502 /// Pull the entire thread (every post) as a single Markdown file
503 /// with YAML frontmatter and per-post headings. Default behaviour
504 /// (no `--full`) writes only the OP, which is what `topic push`
505 /// expects.
506 #[arg(long, short = 'F')]
507 full: bool,
508 },
509 /// Push a local Markdown file to a topic.
510 #[command(visible_alias = "ps")]
511 Push {
512 /// Discourse name.
513 discourse: String,
514 /// Topic ID.
515 topic_id: u64,
516 /// Local Markdown file path.
517 local_path: PathBuf,
518 /// Update the post without bumping the topic in the activity feed.
519 /// Use for silent maintenance edits (sends post[no_bump]=true).
520 #[arg(long)]
521 no_bump: bool,
522 /// Update the post without recording an edit-history revision
523 /// (sends post[skip_revision]=true). Suppresses the online audit
524 /// trail - use sparingly.
525 #[arg(long)]
526 skip_revision: bool,
527 },
528 /// Sync a topic and local Markdown file using newest timestamp.
529 #[command(visible_alias = "sy")]
530 Sync {
531 /// Discourse name.
532 discourse: String,
533 /// Topic ID.
534 topic_id: u64,
535 /// Local Markdown file path.
536 local_path: PathBuf,
537 /// Skip sync confirmation prompt.
538 #[arg(long, short = 'y')]
539 yes: bool,
540 },
541 /// Reply to a topic with content from a file or stdin.
542 #[command(visible_alias = "r")]
543 Reply {
544 /// Discourse name.
545 discourse: String,
546 /// Topic ID.
547 topic_id: u64,
548 /// Input file path. Reads stdin when omitted or `-`.
549 local_path: Option<PathBuf>,
550 /// Output format.
551 #[arg(long, short = 'f', value_enum, default_value = "text")]
552 format: ListFormat,
553 },
554 /// Create a new topic in a category, body from a file or stdin.
555 #[command(visible_alias = "n")]
556 New {
557 /// Discourse name.
558 discourse: String,
559 /// Target category ID.
560 category_id: u64,
561 /// Topic title.
562 #[arg(long, short = 't')]
563 title: String,
564 /// Input file path. Reads stdin when omitted or `-`.
565 local_path: Option<PathBuf>,
566 /// Output format.
567 #[arg(long, short = 'f', value_enum, default_value = "text")]
568 format: ListFormat,
569 },
570 /// Add a tag to a topic.
571 Tag {
572 /// Discourse name.
573 discourse: String,
574 /// Topic ID.
575 topic_id: u64,
576 /// Tag to add.
577 tag: String,
578 },
579 /// Remove a tag from a topic.
580 Untag {
581 /// Discourse name.
582 discourse: String,
583 /// Topic ID.
584 topic_id: u64,
585 /// Tag to remove.
586 tag: String,
587 },
588 /// Rename a topic's title (changes its URL slug). Honours `--dry-run`.
589 Title {
590 /// Discourse name.
591 discourse: String,
592 /// Topic ID.
593 topic_id: u64,
594 /// New title.
595 title: String,
596 },
597 /// Set a topic's full tag list, replacing existing tags. Pass no tags to
598 /// clear all tags. Honours `--dry-run`.
599 Tags {
600 /// Discourse name.
601 discourse: String,
602 /// Topic ID.
603 topic_id: u64,
604 /// Tags to set (space-separated; omit to clear all tags).
605 tags: Vec<String>,
606 },
607}
608
609#[derive(Subcommand)]
610#[command(next_display_order = None)]
611pub enum CategoryCommand {
612 /// List categories.
613 #[command(visible_alias = "ls")]
614 List {
615 /// Discourse name.
616 discourse: String,
617 /// Output format.
618 #[arg(long, short = 'f', value_enum, default_value = "text")]
619 format: ListFormat,
620 /// Include additional fields where supported.
621 #[arg(long, short = 'v')]
622 verbose: bool,
623 /// Show category hierarchy tree.
624 #[arg(long)]
625 tree: bool,
626 },
627 /// Copy a category to another Discourse.
628 #[command(visible_alias = "cp")]
629 Copy {
630 /// Source discourse name.
631 discourse: String,
632 /// Target discourse name (defaults to source when omitted).
633 #[arg(long, short = 't')]
634 target: Option<String>,
635 /// Category ID or slug.
636 category: String,
637 },
638 /// Pull all topics from a category into local Markdown files.
639 #[command(visible_alias = "pl")]
640 Pull {
641 /// Discourse name.
642 discourse: String,
643 /// Category ID or slug.
644 category: String,
645 /// Destination directory (auto-derived when omitted).
646 local_path: Option<PathBuf>,
647 },
648 /// Push local Markdown files into a category.
649 #[command(visible_alias = "ps")]
650 Push {
651 /// Discourse name.
652 discourse: String,
653 /// Category ID or slug.
654 category: String,
655 /// Local directory containing Markdown files.
656 local_path: PathBuf,
657 /// Only update existing topics; error instead of creating a new topic
658 /// when a local file has no remote match.
659 #[arg(long)]
660 updates_only: bool,
661 /// Update posts without bumping their topics in the activity feed.
662 /// Use for silent bulk maintenance edits (sends post[no_bump]=true).
663 #[arg(long)]
664 no_bump: bool,
665 /// Update posts without recording edit-history revisions
666 /// (sends post[skip_revision]=true). Suppresses the online audit
667 /// trail - use sparingly.
668 #[arg(long)]
669 skip_revision: bool,
670 },
671}
672
673#[derive(Subcommand)]
674#[command(next_display_order = None)]
675pub enum GroupCommand {
676 /// List groups.
677 #[command(visible_alias = "ls")]
678 List {
679 /// Discourse name.
680 discourse: String,
681 /// Output format.
682 #[arg(long, short = 'f', value_enum, default_value = "text")]
683 format: ListFormat,
684 /// Include additional fields where supported.
685 #[arg(long, short = 'v')]
686 verbose: bool,
687 },
688 /// Show group details.
689 #[command(visible_alias = "i")]
690 Info {
691 /// Discourse name.
692 discourse: String,
693 /// Group ID.
694 group: u64,
695 /// Output format.
696 #[arg(long, short = 'f', value_enum, default_value = "json")]
697 format: StructuredFormat,
698 },
699 /// List members of a group.
700 #[command(visible_alias = "m")]
701 Members {
702 /// Discourse name.
703 discourse: String,
704 /// Group ID.
705 group: u64,
706 /// Output format.
707 #[arg(long, short = 'f', value_enum, default_value = "text")]
708 format: ListFormat,
709 },
710 /// Copy a group to another Discourse.
711 #[command(visible_alias = "cp")]
712 Copy {
713 /// Source discourse name.
714 discourse: String,
715 /// Target discourse name (defaults to source when omitted).
716 #[arg(long, short = 't')]
717 target: Option<String>,
718 /// Group ID.
719 group: u64,
720 },
721 /// Bulk add members to a group from a file (or stdin) of email addresses.
722 #[command(visible_alias = "a")]
723 Add {
724 /// Discourse name.
725 discourse: String,
726 /// Group ID.
727 group: u64,
728 /// Path to a file of email addresses (one per line; blank
729 /// lines and `#` comments are ignored). Reads stdin when
730 /// omitted or `-`.
731 local_path: Option<PathBuf>,
732 /// Send Discourse notifications to added users.
733 #[arg(long)]
734 notify: bool,
735 },
736}
737
738#[derive(Subcommand)]
739#[command(next_display_order = None)]
740pub enum BackupCommand {
741 /// Create a new backup.
742 #[command(visible_alias = "cr")]
743 Create {
744 /// Discourse name.
745 discourse: String,
746 },
747 /// List backups.
748 #[command(visible_alias = "ls")]
749 List {
750 /// Discourse name.
751 discourse: String,
752 /// Output format.
753 #[arg(long, short = 'f', value_enum, default_value = "text")]
754 format: OutputFormat,
755 /// Include additional fields where supported.
756 #[arg(long, short = 'v')]
757 verbose: bool,
758 },
759 /// Pull (download) a backup to a local file.
760 #[command(visible_alias = "pl")]
761 Pull {
762 /// Discourse name.
763 discourse: String,
764 /// Backup filename on the server (from `dsc backup list`).
765 backup_filename: String,
766 /// Local output path. Defaults to the backup filename in the current directory.
767 local_path: Option<PathBuf>,
768 },
769 /// Push (restore) a backup on the server (alias: restore).
770 #[command(visible_alias = "ps", alias = "restore")]
771 Push {
772 /// Discourse name.
773 discourse: String,
774 /// Backup filename/path on the target system.
775 backup_path: String,
776 },
777 /// Provision an S3 backup bucket + a scoped IAM user and point Discourse at
778 /// it (one command for the per-forum AWS backup runbook). Requires the
779 /// `aws` CLI configured with IAM + S3 admin rights. Always preview with
780 /// `-n` / `--dry-run` first.
781 #[command(after_help = "Examples:
782 dsc backup setup-s3 -n myforum # preview the full plan (review gate)
783 dsc backup setup-s3 myforum --region eu-west-1
784 dsc backup setup-s3 myforum --no-test")]
785 SetupS3 {
786 /// Discourse name.
787 discourse: String,
788 /// AWS region for the bucket.
789 #[arg(long, default_value = "eu-west-2")]
790 region: String,
791 /// Bucket name (default: `<name>-discourse-backups`).
792 #[arg(long)]
793 bucket: Option<String>,
794 /// Skip the verification backup after provisioning.
795 #[arg(long)]
796 no_test: bool,
797 },
798}
799
800#[derive(Subcommand)]
801#[command(next_display_order = None)]
802pub enum PaletteCommand {
803 /// List color palettes.
804 #[command(visible_alias = "ls")]
805 List {
806 /// Discourse name.
807 discourse: String,
808 /// Output format.
809 #[arg(long, short = 'f', value_enum, default_value = "text")]
810 format: ListFormat,
811 /// Include additional fields where supported.
812 #[arg(long, short = 'v')]
813 verbose: bool,
814 },
815 /// Pull a palette to local JSON.
816 #[command(visible_alias = "pl")]
817 Pull {
818 /// Discourse name.
819 discourse: String,
820 /// Palette ID.
821 palette_id: u64,
822 /// Destination file path (auto-derived when omitted).
823 local_path: Option<PathBuf>,
824 },
825 /// Push local JSON to create or update a palette.
826 #[command(visible_alias = "ps")]
827 Push {
828 /// Discourse name.
829 discourse: String,
830 /// Local JSON file path.
831 local_path: PathBuf,
832 /// Palette ID to update (creates a new palette when omitted).
833 palette_id: Option<u64>,
834 },
835}
836
837#[derive(Subcommand)]
838#[command(next_display_order = None)]
839pub enum PluginCommand {
840 /// List installed plugins.
841 #[command(visible_alias = "ls")]
842 List {
843 /// Discourse name.
844 discourse: String,
845 /// Output format.
846 #[arg(long, short = 'f', value_enum, default_value = "text")]
847 format: ListFormat,
848 /// Include additional fields where supported.
849 #[arg(long, short = 'v')]
850 verbose: bool,
851 },
852 /// Install a plugin from URL.
853 #[command(visible_alias = "i")]
854 Install {
855 /// Discourse name.
856 discourse: String,
857 /// Plugin repository URL.
858 url: String,
859 },
860 /// Remove a plugin by name.
861 #[command(visible_alias = "rm")]
862 Remove {
863 /// Discourse name.
864 discourse: String,
865 /// Plugin name.
866 name: String,
867 },
868}
869
870#[derive(Subcommand)]
871#[command(next_display_order = None)]
872pub enum ThemeCommand {
873 /// List installed themes.
874 #[command(visible_alias = "ls")]
875 List {
876 /// Discourse name.
877 discourse: String,
878 /// Output format.
879 #[arg(long, short = 'f', value_enum, default_value = "text")]
880 format: ListFormat,
881 /// Include additional fields where supported.
882 #[arg(long, short = 'v')]
883 verbose: bool,
884 },
885 /// Install a theme from URL.
886 #[command(visible_alias = "i")]
887 Install {
888 /// Discourse name.
889 discourse: String,
890 /// Theme repository URL.
891 url: String,
892 },
893 /// Remove a theme by name.
894 #[command(visible_alias = "rm")]
895 Remove {
896 /// Discourse name.
897 discourse: String,
898 /// Theme name.
899 name: String,
900 },
901 /// Pull a theme to a local JSON file.
902 #[command(visible_alias = "pl")]
903 Pull {
904 /// Discourse name.
905 discourse: String,
906 /// Theme ID (from `dsc theme list`).
907 theme_id: u64,
908 /// Destination file path (auto-derived from theme name when omitted).
909 local_path: Option<PathBuf>,
910 },
911 /// Push a local JSON file to create or update a theme.
912 #[command(visible_alias = "ps")]
913 Push {
914 /// Discourse name.
915 discourse: String,
916 /// Local JSON file path.
917 local_path: PathBuf,
918 /// Theme ID to update (creates a new theme when omitted).
919 theme_id: Option<u64>,
920 },
921 /// Duplicate a theme and print the new theme ID.
922 #[command(visible_alias = "dup")]
923 Duplicate {
924 /// Discourse name.
925 discourse: String,
926 /// Theme ID to duplicate (from `dsc theme list`).
927 theme_id: u64,
928 /// Output format.
929 #[arg(long, short = 'f', value_enum, default_value = "text")]
930 format: ListFormat,
931 },
932 /// Show a richer view of one theme/component than `list`.
933 Show {
934 /// Discourse name.
935 discourse: String,
936 /// Theme ID (from `dsc theme list`).
937 theme_id: u64,
938 /// Output format.
939 #[arg(long, short = 'f', value_enum, default_value = "text")]
940 format: ListFormat,
941 },
942 /// Read and write a theme/component's settings (not site settings).
943 Setting {
944 #[command(subcommand)]
945 command: ThemeSettingCommand,
946 },
947 /// Enable a theme or component.
948 Enable {
949 /// Discourse name.
950 discourse: String,
951 /// Theme ID (from `dsc theme list`).
952 theme_id: u64,
953 },
954 /// Disable a theme or component.
955 Disable {
956 /// Discourse name.
957 discourse: String,
958 /// Theme ID (from `dsc theme list`).
959 theme_id: u64,
960 },
961 /// Attach a component to a parent theme (makes it active on that theme).
962 Attach {
963 /// Discourse name.
964 discourse: String,
965 /// Parent theme ID.
966 parent_id: u64,
967 /// Component (child theme) ID to attach.
968 component_id: u64,
969 },
970 /// Detach a component from a parent theme.
971 Detach {
972 /// Discourse name.
973 discourse: String,
974 /// Parent theme ID.
975 parent_id: u64,
976 /// Component (child theme) ID to detach.
977 component_id: u64,
978 },
979 /// Manage colour palettes (colour schemes). The canonical home for what
980 /// was `dsc palette`.
981 Palette {
982 #[command(subcommand)]
983 command: PaletteCommand,
984 },
985}
986
987#[derive(Subcommand)]
988#[command(next_display_order = None)]
989pub enum ThemeSettingCommand {
990 /// List a theme/component's settings.
991 #[command(visible_alias = "ls")]
992 List {
993 /// Discourse name.
994 discourse: String,
995 /// Theme ID (from `dsc theme list`).
996 theme_id: u64,
997 /// Output format.
998 #[arg(long, short = 'f', value_enum, default_value = "text")]
999 format: ListFormat,
1000 },
1001 /// Print a single setting's current value.
1002 Get {
1003 /// Discourse name.
1004 discourse: String,
1005 /// Theme ID.
1006 theme_id: u64,
1007 /// Setting key (the `setting` name from `theme setting list`).
1008 key: String,
1009 /// Output format.
1010 #[arg(long, short = 'f', value_enum, default_value = "text")]
1011 format: ListFormat,
1012 },
1013 /// Set a single setting. Value is sent verbatim (pass JSON text for
1014 /// json-schema list settings). Honours global `--dry-run`.
1015 Set {
1016 /// Discourse name.
1017 discourse: String,
1018 /// Theme ID.
1019 theme_id: u64,
1020 /// Setting key.
1021 key: String,
1022 /// New value (verbatim).
1023 value: String,
1024 },
1025}
1026
1027#[derive(Subcommand)]
1028#[command(next_display_order = None)]
1029pub enum PmCommand {
1030 /// Send a private message.
1031 #[command(visible_alias = "s")]
1032 Send {
1033 /// Discourse name.
1034 discourse: String,
1035 /// Recipient(s) — comma-separated usernames or group names.
1036 recipients: String,
1037 /// PM title / subject.
1038 #[arg(long, short = 't')]
1039 title: String,
1040 /// Input file path. Reads stdin when omitted or `-`.
1041 local_path: Option<PathBuf>,
1042 },
1043 /// List PMs for a user.
1044 #[command(visible_alias = "ls")]
1045 List {
1046 /// Discourse name.
1047 discourse: String,
1048 /// Username whose PMs to list.
1049 username: String,
1050 /// Direction / view: inbox | sent | archive | unread | new.
1051 #[arg(long, short = 'd', default_value = "inbox")]
1052 direction: String,
1053 /// Output format.
1054 #[arg(long, short = 'f', value_enum, default_value = "text")]
1055 format: ListFormat,
1056 },
1057}
1058
1059#[derive(Subcommand)]
1060#[command(next_display_order = None)]
1061pub enum ApiKeyCommand {
1062 /// List API keys.
1063 #[command(visible_alias = "ls")]
1064 List {
1065 /// Discourse name.
1066 discourse: String,
1067 /// Output format.
1068 #[arg(long, short = 'f', value_enum, default_value = "text")]
1069 format: ListFormat,
1070 },
1071 /// Create a new API key. The secret is only shown at creation time —
1072 /// capture it from the output.
1073 #[command(visible_alias = "cr")]
1074 Create {
1075 /// Discourse name.
1076 discourse: String,
1077 /// Description / label for the key (shown in admin UI).
1078 description: String,
1079 /// Username the key acts as. Omit for a global all-users key.
1080 #[arg(long, short = 'u')]
1081 username: Option<String>,
1082 /// Output format.
1083 #[arg(long, short = 'f', value_enum, default_value = "text")]
1084 format: ListFormat,
1085 },
1086 /// Revoke an API key by ID.
1087 #[command(visible_alias = "rm")]
1088 Revoke {
1089 /// Discourse name.
1090 discourse: String,
1091 /// API key ID (from `dsc api-key list`).
1092 key_id: u64,
1093 },
1094}
1095
1096#[derive(Subcommand)]
1097#[command(next_display_order = None)]
1098pub enum InviteCommand {
1099 /// Invite a single email address.
1100 #[command(visible_alias = "s")]
1101 Send {
1102 /// Discourse name.
1103 discourse: String,
1104 /// Email address to invite.
1105 email: String,
1106 /// Add invitee to one or more groups on accept (repeatable).
1107 #[arg(long, short = 'g')]
1108 group: Vec<u64>,
1109 /// Land the invitee on a specific topic on accept.
1110 #[arg(long, short = 't')]
1111 topic: Option<u64>,
1112 /// Custom invitation message.
1113 #[arg(long, short = 'm')]
1114 message: Option<String>,
1115 },
1116 /// Bulk-invite from a file (or stdin) of email addresses.
1117 #[command(visible_alias = "b")]
1118 Bulk {
1119 /// Discourse name.
1120 discourse: String,
1121 /// Path to a file of email addresses (one per line; blank lines and
1122 /// `#` comments ignored). Reads stdin when omitted or `-`.
1123 local_path: Option<PathBuf>,
1124 /// Add every invitee to one or more groups on accept (repeatable).
1125 #[arg(long, short = 'g')]
1126 group: Vec<u64>,
1127 /// Land every invitee on a specific topic on accept.
1128 #[arg(long, short = 't')]
1129 topic: Option<u64>,
1130 /// Custom invitation message attached to each invite.
1131 #[arg(long, short = 'm')]
1132 message: Option<String>,
1133 },
1134}
1135
1136#[derive(Subcommand)]
1137#[command(next_display_order = None)]
1138pub enum UserCommand {
1139 /// List users via the admin users endpoint.
1140 #[command(visible_alias = "ls")]
1141 List {
1142 /// Discourse name.
1143 discourse: String,
1144 /// Listing type: active | new | staff | suspended | silenced | staged.
1145 #[arg(long, short = 'l', default_value = "active")]
1146 listing: String,
1147 /// Page number (Discourse paginates 100 per page).
1148 #[arg(long, short = 'p', default_value_t = 1)]
1149 page: u32,
1150 /// Output format.
1151 #[arg(long, short = 'f', value_enum, default_value = "text")]
1152 format: ListFormat,
1153 },
1154 /// Show detailed info for a user.
1155 #[command(visible_alias = "i")]
1156 Info {
1157 /// Discourse name.
1158 discourse: String,
1159 /// Username.
1160 username: String,
1161 /// Output format.
1162 #[arg(long, short = 'f', value_enum, default_value = "text")]
1163 format: ListFormat,
1164 },
1165 /// Suspend a user.
1166 #[command(visible_alias = "sus")]
1167 Suspend {
1168 /// Discourse name.
1169 discourse: String,
1170 /// Username.
1171 username: String,
1172 /// When the suspension ends. ISO-8601 timestamp (e.g.
1173 /// `2026-12-31T00:00:00Z`) or `forever`.
1174 #[arg(long, short = 'u', default_value = "forever")]
1175 until: String,
1176 /// Reason shown to the user and in the audit log.
1177 #[arg(long, short = 'r', default_value = "")]
1178 reason: String,
1179 },
1180 /// Remove a suspension from a user.
1181 #[command(visible_alias = "uns")]
1182 Unsuspend {
1183 /// Discourse name.
1184 discourse: String,
1185 /// Username.
1186 username: String,
1187 },
1188 /// Silence a user (prevents posting; less visible than suspend).
1189 #[command(visible_alias = "sil")]
1190 Silence {
1191 /// Discourse name.
1192 discourse: String,
1193 /// Username.
1194 username: String,
1195 /// When the silence ends. ISO-8601 timestamp; empty means
1196 /// indefinite.
1197 #[arg(long, short = 'u', default_value = "")]
1198 until: String,
1199 /// Reason shown to the user and in the audit log.
1200 #[arg(long, short = 'r', default_value = "")]
1201 reason: String,
1202 },
1203 /// Lift a silence on a user.
1204 #[command(visible_alias = "unsil")]
1205 Unsilence {
1206 /// Discourse name.
1207 discourse: String,
1208 /// Username.
1209 username: String,
1210 },
1211 /// Grant the user the admin or moderator role.
1212 #[command(visible_alias = "pr")]
1213 Promote {
1214 /// Discourse name.
1215 discourse: String,
1216 /// Username.
1217 username: String,
1218 /// Role to grant.
1219 #[arg(long, short = 'r', value_enum)]
1220 role: RoleArg,
1221 },
1222 /// Revoke the user's admin or moderator role.
1223 #[command(visible_alias = "de")]
1224 Demote {
1225 /// Discourse name.
1226 discourse: String,
1227 /// Username.
1228 username: String,
1229 /// Role to revoke.
1230 #[arg(long, short = 'r', value_enum)]
1231 role: RoleArg,
1232 },
1233 /// Create a new user. `--approve` also marks the account approved
1234 /// (needed when site requires manual approval). Password is either
1235 /// supplied via stdin (`--password-stdin`) or omitted — in the
1236 /// latter case the user will have to set one via the reset flow.
1237 #[command(visible_alias = "cr")]
1238 Create {
1239 /// Discourse name.
1240 discourse: String,
1241 /// New user's email address.
1242 email: String,
1243 /// New user's username.
1244 username: String,
1245 /// Display name (optional).
1246 #[arg(long, short = 'N')]
1247 name: Option<String>,
1248 /// Read the password from stdin instead of auto-reset.
1249 #[arg(long)]
1250 password_stdin: bool,
1251 /// Also mark the user approved (for sites with manual approval).
1252 #[arg(long)]
1253 approve: bool,
1254 },
1255 /// Trigger Discourse's password-reset email flow for a user.
1256 #[command(name = "password-reset", visible_aliases = ["pwreset", "pw-reset"])]
1257 PasswordReset {
1258 /// Discourse name.
1259 discourse: String,
1260 /// Username or email.
1261 username: String,
1262 },
1263 /// Set a user's primary email address. Requires admin scope.
1264 #[command(name = "email-set", visible_alias = "email")]
1265 EmailSet {
1266 /// Discourse name.
1267 discourse: String,
1268 /// Username.
1269 username: String,
1270 /// New email address.
1271 email: String,
1272 },
1273 /// Show a user's recent public activity (topics + replies by default).
1274 ///
1275 /// Built for the "archive my own activity to a journal forum" loop —
1276 /// pipe the markdown output straight into `dsc topic reply`/`topic new`.
1277 #[command(visible_alias = "act")]
1278 Activity {
1279 /// Discourse name (the *source* forum to read activity from).
1280 discourse: String,
1281 /// Username whose activity to read.
1282 username: String,
1283 /// How far back to look. Accepts `7d`, `24h`, `30m`, `1w`, `90s`, or
1284 /// an ISO-8601 timestamp / date. Omit to fetch everything available.
1285 #[arg(long, short = 's')]
1286 since: Option<String>,
1287 /// Action types to include, comma-separated. Default: topics,replies.
1288 /// Also recognises: mentions, quotes, likes, edits, responses.
1289 #[arg(long, short = 't', default_value = "topics,replies")]
1290 types: String,
1291 /// Hard cap on number of items returned.
1292 #[arg(long, short = 'L')]
1293 limit: Option<u32>,
1294 /// Output format.
1295 #[arg(long, short = 'f', value_enum, default_value = "markdown")]
1296 format: ActivityFormatArg,
1297 },
1298 /// Manage a user's group memberships.
1299 #[command(visible_alias = "g")]
1300 Groups {
1301 #[command(subcommand)]
1302 command: UserGroupsCommand,
1303 },
1304}
1305
1306#[derive(ValueEnum, Clone, Copy)]
1307pub enum SectionArg {
1308 All,
1309 Growth,
1310 Activity,
1311 Health,
1312}
1313
1314#[derive(ValueEnum, Clone, Copy)]
1315pub enum AnalyticsFormat {
1316 /// Plain text (default). Fixed-width columns, no borders.
1317 Text,
1318 /// DuckDB-style box-drawing table. Falls through to `text` when
1319 /// stdout isn't a TTY.
1320 Table,
1321 /// Pretty JSON.
1322 Json,
1323 /// YAML.
1324 #[value(alias = "yml")]
1325 Yaml,
1326 /// Markdown bullet list per section.
1327 #[value(alias = "md")]
1328 Markdown,
1329 /// Markdown table per section.
1330 #[value(alias = "md-table", name = "markdown-table")]
1331 MarkdownTable,
1332 /// CSV — one row per metric.
1333 Csv,
1334}
1335
1336#[derive(ValueEnum, Clone, Copy)]
1337pub enum ActivityFormatArg {
1338 Text,
1339 Json,
1340 #[value(alias = "yml")]
1341 Yaml,
1342 #[value(alias = "md")]
1343 Markdown,
1344 Csv,
1345}
1346
1347#[derive(ValueEnum, Clone, Copy)]
1348pub enum RoleArg {
1349 Admin,
1350 Moderator,
1351}
1352
1353#[derive(Subcommand)]
1354#[command(next_display_order = None)]
1355pub enum UserGroupsCommand {
1356 /// List the groups a user belongs to.
1357 #[command(visible_alias = "ls")]
1358 List {
1359 /// Discourse name.
1360 discourse: String,
1361 /// Target username.
1362 username: String,
1363 /// Output format.
1364 #[arg(long, short = 'f', value_enum, default_value = "text")]
1365 format: ListFormat,
1366 },
1367 /// Add a user to a group.
1368 #[command(visible_alias = "a")]
1369 Add {
1370 /// Discourse name.
1371 discourse: String,
1372 /// Target username.
1373 username: String,
1374 /// Group ID.
1375 group_id: u64,
1376 /// Send Discourse notification to the user.
1377 #[arg(long)]
1378 notify: bool,
1379 },
1380 /// Remove a user from a group.
1381 #[command(visible_alias = "rm")]
1382 Remove {
1383 /// Discourse name.
1384 discourse: String,
1385 /// Target username.
1386 username: String,
1387 /// Group ID.
1388 group_id: u64,
1389 },
1390}
1391
1392#[derive(Subcommand)]
1393#[command(next_display_order = None)]
1394pub enum PostCommand {
1395 /// Pull a post's raw Markdown to a local file.
1396 #[command(visible_alias = "pl")]
1397 Pull {
1398 /// Discourse name.
1399 discourse: String,
1400 /// Post ID.
1401 post_id: u64,
1402 /// Output file path. Prints to stdout when omitted.
1403 local_path: Option<PathBuf>,
1404 },
1405 /// Push a local file to update a post (alias: edit).
1406 #[command(visible_alias = "ps", alias = "edit")]
1407 Push {
1408 /// Discourse name.
1409 discourse: String,
1410 /// Post ID.
1411 post_id: u64,
1412 /// Input file path. Reads stdin when omitted or `-`.
1413 local_path: Option<PathBuf>,
1414 },
1415 /// Delete a post by ID.
1416 #[command(visible_alias = "rm")]
1417 Delete {
1418 /// Discourse name.
1419 discourse: String,
1420 /// Post ID.
1421 post_id: u64,
1422 },
1423 /// Move a post to a different topic.
1424 #[command(visible_alias = "mv")]
1425 Move {
1426 /// Discourse name.
1427 discourse: String,
1428 /// Post ID to move.
1429 post_id: u64,
1430 /// Destination topic ID.
1431 #[arg(long = "to-topic", short = 't')]
1432 to_topic: u64,
1433 },
1434}
1435
1436#[derive(Subcommand)]
1437#[command(next_display_order = None)]
1438pub enum TagCommand {
1439 /// List every tag on the Discourse.
1440 #[command(visible_alias = "ls")]
1441 List {
1442 /// Discourse name.
1443 discourse: String,
1444 /// Output format.
1445 #[arg(long, short = 'f', value_enum, default_value = "text")]
1446 format: ListFormat,
1447 },
1448 /// Pull the tag taxonomy (tags + tag groups) to a local file.
1449 #[command(visible_alias = "pl")]
1450 Pull {
1451 /// Discourse name.
1452 discourse: String,
1453 /// Output file (default: tags.yaml). Extension determines format (.yaml/.json).
1454 #[arg(default_value = "tags.yaml")]
1455 local_path: PathBuf,
1456 },
1457 /// Push a local taxonomy file to the server (upsert; optionally prune).
1458 #[command(visible_alias = "ps")]
1459 Push {
1460 /// Discourse name.
1461 discourse: String,
1462 /// Input taxonomy file.
1463 local_path: PathBuf,
1464 /// Delete server tags/groups absent from the file.
1465 #[arg(long)]
1466 prune: bool,
1467 },
1468 /// Rename a tag, preserving topic associations.
1469 ///
1470 /// Discourse rewrites every topic's tag list in-place, so this avoids
1471 /// the delete-and-recreate pattern that loses topic membership.
1472 #[command(visible_alias = "rn")]
1473 Rename {
1474 /// Discourse name.
1475 discourse: String,
1476 /// Current tag name.
1477 old_name: String,
1478 /// New tag name.
1479 new_name: String,
1480 },
1481}
1482
1483#[derive(Subcommand)]
1484#[command(next_display_order = None)]
1485pub enum SettingCommand {
1486 /// Set a site setting on a Discourse (or all tagged Discourses).
1487 ///
1488 /// Usage:
1489 /// dsc setting set <discourse> <setting> <value>
1490 /// dsc setting set --tags <tag1,tag2> <setting> <value>
1491 #[command(visible_alias = "s")]
1492 Set {
1493 /// Discourse name. Required unless `--tags` is provided.
1494 discourse: Option<String>,
1495 /// Setting key. Required.
1496 setting: Option<String>,
1497 /// Setting value. Required.
1498 value: Option<String>,
1499 /// Tag filter (comma/semicolon separated, match-any). Apply across all
1500 /// Discourses matching any of the tags. When set, omit `<discourse>`
1501 /// and pass `<setting> <value>` as the only positionals.
1502 #[arg(long, value_name = "tag1,tag2")]
1503 tags: Option<String>,
1504 },
1505
1506 /// Get the current value of a site setting.
1507 #[command(visible_alias = "g")]
1508 Get {
1509 /// Discourse name.
1510 discourse: String,
1511 /// Setting key.
1512 setting: String,
1513 /// Output format.
1514 #[arg(long, short = 'f', value_enum, default_value = "text")]
1515 format: ListFormat,
1516 },
1517
1518 /// List all site settings.
1519 #[command(visible_alias = "ls")]
1520 List {
1521 /// Discourse name.
1522 discourse: String,
1523 /// Output format.
1524 #[arg(long, short = 'f', value_enum, default_value = "text")]
1525 format: ListFormat,
1526 /// Show output even when list is empty.
1527 #[arg(long, short = 'v')]
1528 verbose: bool,
1529 },
1530
1531 /// Snapshot every site setting to a file - the reference for what settings exist.
1532 ///
1533 /// See spec/setting-sync.md for the full schema and workflow. The
1534 /// generated file is a self-documenting YAML (or JSON) including each
1535 /// setting's value, default, type, category, and Discourse's own
1536 /// description - so it doubles as a catalog of available settings.
1537 #[command(visible_alias = "pl")]
1538 Pull {
1539 /// Discourse name.
1540 discourse: String,
1541 /// Output path. Format detected by extension (.json → JSON,
1542 /// otherwise YAML). Defaults to `settings.yaml`.
1543 #[arg(default_value = "settings.yaml")]
1544 local_path: PathBuf,
1545 /// Only include settings whose value differs from default. Produces
1546 /// a manageable file (~50-100 entries) suitable for version control.
1547 #[arg(long, short = 'c')]
1548 changed_only: bool,
1549 /// Limit to settings in this category (e.g. `required`, `email`,
1550 /// `security`).
1551 #[arg(long)]
1552 category: Option<String>,
1553 },
1554
1555 /// Apply a settings snapshot file to a Discourse (idempotent).
1556 ///
1557 /// Compares each setting in the file against the server and PUTs only
1558 /// values that differ. Combine with `--dry-run` to preview the plan.
1559 #[command(visible_alias = "ph")]
1560 Push {
1561 /// Discourse name.
1562 discourse: String,
1563 /// Path to the settings snapshot file (YAML or JSON).
1564 local_path: PathBuf,
1565 /// For settings present on the server but absent from the file,
1566 /// reset them to their default value. Off by default (file describes
1567 /// only the values you care about).
1568 #[arg(long)]
1569 reset_unlisted: bool,
1570 },
1571
1572 /// Compare site settings between two sources.
1573 ///
1574 /// Each source can be a Discourse name (live fetch) or a path to a
1575 /// snapshot file produced by `dsc setting pull`. Sources are detected
1576 /// by whether the argument refers to an existing file on disk; if not,
1577 /// it is treated as a Discourse name.
1578 #[command(visible_alias = "df")]
1579 Diff {
1580 /// First source: Discourse name or snapshot file path.
1581 source: String,
1582 /// Second source: Discourse name or snapshot file path.
1583 target: String,
1584 /// Filter to settings where at least one source differs from default.
1585 /// Reduces noise when most settings on both sides are still default.
1586 #[arg(long, short = 'c')]
1587 changed_only: bool,
1588 /// Limit to settings in this category (e.g. `required`, `email`).
1589 /// Only effective when both sources carry category metadata.
1590 #[arg(long)]
1591 category: Option<String>,
1592 /// Output format.
1593 #[arg(long, short = 'f', value_enum, default_value = "text")]
1594 format: ListFormat,
1595 },
1596
1597 /// Show the value of one setting across every configured forum
1598 /// (optionally filtered by `--tags`). Diff-friendly; distinct from `diff`,
1599 /// which compares two specific sources across all settings.
1600 Audit {
1601 /// Setting key.
1602 setting: String,
1603 /// Only audit forums carrying at least one of these tags
1604 /// (comma/semicolon-separated). Omit to audit every configured forum.
1605 #[arg(long, value_name = "tag1,tag2")]
1606 tags: Option<String>,
1607 /// Output format.
1608 #[arg(long, short = 'f', value_enum, default_value = "text")]
1609 format: ListFormat,
1610 },
1611}
1612
1613#[derive(ValueEnum, Clone, Copy)]
1614pub enum CompletionShell {
1615 /// Bash shell.
1616 Bash,
1617 /// Zsh shell.
1618 Zsh,
1619 /// Fish shell.
1620 Fish,
1621}
1622
1623impl From<CompletionShell> for Shell {
1624 fn from(value: CompletionShell) -> Self {
1625 match value {
1626 CompletionShell::Bash => Shell::Bash,
1627 CompletionShell::Zsh => Shell::Zsh,
1628 CompletionShell::Fish => Shell::Fish,
1629 }
1630 }
1631}
1632
1633#[derive(ValueEnum, Clone)]
1634pub enum OutputFormat {
1635 /// Plain text.
1636 #[value(alias = "plaintext")]
1637 Text,
1638 /// Markdown list.
1639 Markdown,
1640 /// Markdown table.
1641 MarkdownTable,
1642 /// Pretty JSON.
1643 Json,
1644 /// YAML.
1645 #[value(alias = "yml")]
1646 Yaml,
1647 /// CSV.
1648 Csv,
1649 /// One base URL per line (pipe-friendly).
1650 #[value(alias = "url")]
1651 Urls,
1652}
1653
1654#[derive(ValueEnum, Clone, Copy)]
1655pub enum ListFormat {
1656 /// Plain text.
1657 Text,
1658 /// Pretty JSON.
1659 Json,
1660 /// YAML.
1661 #[value(alias = "yml")]
1662 Yaml,
1663}
1664
1665#[derive(ValueEnum, Clone, Copy)]
1666pub enum StructuredFormat {
1667 /// Pretty JSON.
1668 Json,
1669 /// YAML.
1670 #[value(alias = "yml")]
1671 Yaml,
1672}