cli.rs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. use clap::{Parser, Subcommand};
  2. #[derive(Parser)]
  3. #[command(author, version, about = "DGX Spark Launcher для vLLM и SGLang")]
  4. pub struct Cli {
  5. #[arg(long, short, default_value = "config.toml")]
  6. pub config: String,
  7. #[arg(long, short, help = "Показать команды без выполнения")]
  8. pub dry_run: bool,
  9. #[command(subcommand)]
  10. pub command: Commands,
  11. }
  12. #[derive(Subcommand)]
  13. pub enum Commands {
  14. /// Запустить кластер
  15. Serve {
  16. #[arg(long, required = true)]
  17. recipe: String,
  18. #[arg(long, default_value = "auto")]
  19. cluster: String,
  20. /// Keep containers after stop (default: auto-remove on stop)
  21. #[arg(long, default_value = "false")]
  22. keep: bool,
  23. },
  24. /// Показать логи контейнеров
  25. Logs {
  26. #[arg(long, required = true)]
  27. recipe: String,
  28. #[arg(long, action = clap::ArgAction::SetTrue)]
  29. follow: bool,
  30. },
  31. /// Остановить кластер
  32. Stop {
  33. #[arg(long, required = true)]
  34. recipe: String,
  35. },
  36. /// Проверить здоровье кластера
  37. Health {
  38. #[arg(
  39. long,
  40. help = "Имя кластера (например, 4nodes-switch). Если не указано - проверяет все."
  41. )]
  42. cluster: Option<String>,
  43. #[arg(
  44. long,
  45. help = "Показать хост-ключи узлов (для добавления в config.toml)"
  46. )]
  47. fingerprint: bool,
  48. },
  49. /// Проверить и исправить рецепт (doctor mode)
  50. Doctor {
  51. #[arg(long, required = true, help = "Имя рецепта для проверки")]
  52. recipe: String,
  53. #[arg(
  54. long,
  55. default_value = "auto",
  56. help = "Кластер (если не auto — использует recipe.cluster)"
  57. )]
  58. cluster: String,
  59. #[arg(
  60. long,
  61. help = "Автоматически исправить проблемы (создать Dockerfile + собрать образ)"
  62. )]
  63. repair: bool,
  64. },
  65. /// Управление tmux-сессиями (альтернатива Docker)
  66. #[command(subcommand)]
  67. Tmux(TmuxCommands),
  68. /// Auto-discover host keys and write them into config.toml
  69. InitHostKeys {
  70. #[arg(
  71. long,
  72. help = "Имя кластера (например, 4nodes-switch). Если не указано — все."
  73. )]
  74. cluster: Option<String>,
  75. },
  76. }
  77. #[derive(Subcommand)]
  78. pub enum TmuxCommands {
  79. /// Запустить кластер через tmux
  80. Serve {
  81. #[arg(long, required = true)]
  82. recipe: String,
  83. #[arg(long, default_value = "auto")]
  84. cluster: String,
  85. },
  86. /// Остановить tmux-сессии
  87. Stop {
  88. #[arg(long, required = true)]
  89. recipe: String,
  90. #[arg(long, default_value = "auto")]
  91. cluster: String,
  92. },
  93. /// Статус tmux-сессий (подробный)
  94. Status {
  95. #[arg(long, required = true)]
  96. recipe: String,
  97. #[arg(long, default_value = "auto")]
  98. cluster: String,
  99. },
  100. /// Показать логи tmux-сессий
  101. Logs {
  102. #[arg(long, required = true)]
  103. recipe: String,
  104. #[arg(long, action = clap::ArgAction::SetTrue)]
  105. follow: bool,
  106. #[arg(long, default_value = "auto")]
  107. cluster: String,
  108. },
  109. /// Подключиться к tmux-сессии головного узла
  110. Attach {
  111. #[arg(long, required = true)]
  112. recipe: String,
  113. #[arg(long, default_value = "auto")]
  114. cluster: String,
  115. },
  116. }