cli.rs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. use clap::{Parser, Subcommand};
  2. #[derive(Parser)]
  3. #[command(author, version, about = "DGX Spark Launcher for vLLM and SGLang")]
  4. pub struct Cli {
  5. #[arg(long, short, default_value = "config.toml")]
  6. pub config: String,
  7. #[arg(long, short, help = "Show commands without executing")]
  8. pub dry_run: bool,
  9. #[command(subcommand)]
  10. pub command: Commands,
  11. }
  12. #[derive(Subcommand)]
  13. pub enum Commands {
  14. /// Launch a cluster
  15. Serve {
  16. #[arg(long, required = true)]
  17. recipe: String,
  18. #[arg(long, default_value = "auto")]
  19. cluster: String,
  20. /// Target a specific node within the cluster (default: all).
  21. #[arg(long)]
  22. node: Option<String>,
  23. /// Keep containers after stop (default: auto-remove on stop)
  24. #[arg(long, default_value = "false")]
  25. keep: bool,
  26. /// Skip pre-serve hooks (cluster-level + recipe-level).
  27. #[arg(long, default_value = "false")]
  28. skip_before_serve: bool,
  29. /// Follow logs after serving (use --no-follow to skip).
  30. #[arg(long, action = clap::ArgAction::SetFalse, default_value_t = true)]
  31. follow: bool,
  32. /// Power on cluster if switch is off (requires HA config).
  33. #[arg(long, default_value = "false")]
  34. auto_power_on: bool,
  35. },
  36. /// Show container logs
  37. Logs {
  38. #[arg(long, required = true)]
  39. recipe: String,
  40. #[arg(long, action = clap::ArgAction::SetTrue)]
  41. follow: bool,
  42. #[arg(long, default_value = "auto")]
  43. cluster: String,
  44. /// Target a specific node within the cluster (default: head node if following, all nodes if not).
  45. #[arg(long)]
  46. node: Option<String>,
  47. },
  48. /// Stop a cluster
  49. Stop {
  50. #[arg(long, required = true)]
  51. recipe: String,
  52. /// Target specific nodes (repeatable, e.g. --node dgx1 --node dgx2).
  53. #[arg(long)]
  54. node: Vec<String>,
  55. #[arg(long, default_value = "auto")]
  56. cluster: String,
  57. /// Power off cluster after stopping containers (requires HA config).
  58. #[arg(long, default_value = "false")]
  59. power_off: bool,
  60. },
  61. /// Check cluster health
  62. Health {
  63. #[arg(
  64. long,
  65. help = "Cluster name (e.g. 4nodes-switch). If omitted — checks all."
  66. )]
  67. cluster: Option<String>,
  68. #[arg(long, help = "Show node host keys (for adding to config.toml)")]
  69. fingerprint: bool,
  70. },
  71. /// Check and repair a recipe (doctor mode)
  72. Doctor {
  73. #[arg(long, required = true, help = "Recipe name to check")]
  74. recipe: String,
  75. #[arg(
  76. long,
  77. default_value = "auto",
  78. help = "Cluster (if not auto — uses recipe.cluster)"
  79. )]
  80. cluster: String,
  81. #[arg(long, help = "Auto-fix issues (create Dockerfile + build image)")]
  82. repair: bool,
  83. },
  84. /// Manage tmux sessions (Docker alternative)
  85. #[command(subcommand)]
  86. Tmux(TmuxCommands),
  87. /// Auto-discover host keys and write them into config.toml
  88. InitHostKeys {
  89. #[arg(long, help = "Cluster name (e.g. 4nodes-switch). If omitted — all.")]
  90. cluster: Option<String>,
  91. },
  92. /// Run an arbitrary shell command on a cluster or single node
  93. Exec {
  94. /// Cluster name (mutually exclusive with --recipe).
  95. #[arg(long, conflicts_with = "recipe")]
  96. cluster: Option<String>,
  97. /// Recipe name; resolves to the recipe's pinned cluster.
  98. #[arg(long, conflicts_with = "cluster")]
  99. recipe: Option<String>,
  100. /// Target a specific node within the cluster (default: all).
  101. #[arg(long)]
  102. node: Option<String>,
  103. /// Name of an alias from `[exec_aliases]` in config.toml.
  104. /// Mutually exclusive with a trailing command.
  105. #[arg(long)]
  106. alias: Option<String>,
  107. /// Command to run (everything after `--`).
  108. #[arg(trailing_var_arg = true)]
  109. command: Vec<String>,
  110. },
  111. /// Power on/off nodes via Home Assistant (smart plugs / Wake-on-LAN).
  112. Power {
  113. #[command(subcommand)]
  114. action: PowerAction,
  115. },
  116. }
  117. #[derive(Subcommand)]
  118. pub enum PowerAction {
  119. /// Power off: SSH `sudo shutdown now` + wait + HA `turn_off`.
  120. Off {
  121. #[arg(long)]
  122. cluster: String,
  123. /// Target a specific node within the cluster (default: all).
  124. #[arg(long)]
  125. node: Option<String>,
  126. },
  127. /// Power on: HA `turn_on` only (no SSH; the smart plug wakes the machine).
  128. On {
  129. #[arg(long)]
  130. cluster: String,
  131. /// Target a specific node within the cluster (default: all).
  132. #[arg(long)]
  133. node: Option<String>,
  134. },
  135. /// Switch clusters: disable nodes from source, enable nodes in target.
  136. Switch {
  137. /// Current cluster (nodes + entities to shut down).
  138. #[arg(long)]
  139. from: String,
  140. /// Target cluster (nodes + entities to wake up).
  141. #[arg(long)]
  142. to: String,
  143. },
  144. }
  145. #[derive(Subcommand)]
  146. pub enum TmuxCommands {
  147. /// Launch cluster via tmux
  148. Serve {
  149. #[arg(long, required = true)]
  150. recipe: String,
  151. #[arg(long, default_value = "auto")]
  152. cluster: String,
  153. /// Skip pre-serve hooks (cluster-level + recipe-level).
  154. #[arg(long, default_value = "false")]
  155. skip_before_serve: bool,
  156. },
  157. /// Stop tmux sessions
  158. Stop {
  159. #[arg(long, required = true)]
  160. recipe: String,
  161. #[arg(long, default_value = "auto")]
  162. cluster: String,
  163. },
  164. /// Detailed tmux session status
  165. Status {
  166. #[arg(long, required = true)]
  167. recipe: String,
  168. #[arg(long, default_value = "auto")]
  169. cluster: String,
  170. },
  171. /// Show tmux session logs
  172. Logs {
  173. #[arg(long, required = true)]
  174. recipe: String,
  175. #[arg(long, action = clap::ArgAction::SetTrue)]
  176. follow: bool,
  177. #[arg(long, default_value = "auto")]
  178. cluster: String,
  179. },
  180. /// Attach to head node tmux session
  181. Attach {
  182. #[arg(long, required = true)]
  183. recipe: String,
  184. #[arg(long, default_value = "auto")]
  185. cluster: String,
  186. },
  187. }