main.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. package main
  2. import (
  3. "bufio"
  4. "fmt"
  5. "io"
  6. "os"
  7. "os/exec"
  8. "path/filepath"
  9. "sort"
  10. "strings"
  11. "time"
  12. "github.com/spf13/cobra"
  13. )
  14. const (
  15. Red = "\033[0;31m"
  16. Green = "\033[0;32m"
  17. Blue = "\033[0;34m"
  18. Yellow = "\033[0;33m"
  19. Purple = "\033[0;35m" // For elevated scripts
  20. NC = "\033[0m"
  21. )
  22. type Config struct {
  23. RunsDir string
  24. LogsDir string
  25. DryRun bool
  26. Verbose bool
  27. Interactive bool
  28. }
  29. type Script struct {
  30. Path string // Full filesystem path
  31. Name string // Just filename (e.g. "install.sh")
  32. RelPath string // Relative path from runs/ (e.g. "tools/install.sh")
  33. Desc string // Description from script comment
  34. RequiresSudo bool // Whether script needs elevated privileges
  35. }
  36. var config Config
  37. func log(msg string, args ...any) {
  38. fmt.Printf(Green+"[RUN]"+NC+" "+msg+"\n", args...)
  39. }
  40. func warn(msg string, args ...any) {
  41. fmt.Printf(Yellow+"[WARN]"+NC+" "+msg+"\n", args...)
  42. }
  43. func errorLog(msg string, args ...any) {
  44. fmt.Fprintf(os.Stderr, Red+"[ERROR]"+NC+" "+msg+"\n", args...)
  45. }
  46. func sudoLog(msg string, args ...any) {
  47. fmt.Printf(Purple+"[SUDO]"+NC+" "+msg+"\n", args...)
  48. }
  49. func commandExists(cmd string) bool {
  50. _, err := exec.LookPath(cmd)
  51. return err == nil
  52. }
  53. func checkDependencies() error {
  54. requiredTools := []string{"git", "find", "grep"}
  55. optionalTools := []string{"gitleaks"}
  56. var missing []string
  57. log("Checking dependencies...")
  58. for _, tool := range requiredTools {
  59. if !commandExists(tool) {
  60. missing = append(missing, tool)
  61. }
  62. }
  63. for _, tool := range optionalTools {
  64. if !commandExists(tool) {
  65. warn("Optional tool missing: %s (recommended for security scanning)", tool)
  66. } else {
  67. log("✓ Found: %s", tool)
  68. }
  69. }
  70. if len(missing) > 0 {
  71. errorLog("Missing required tools: %s", strings.Join(missing, ", "))
  72. errorLog("Please install missing dependencies")
  73. return fmt.Errorf("missing dependencies")
  74. }
  75. log("✓ All required dependencies found")
  76. return nil
  77. }
  78. func runSecurityScan() error {
  79. log("Running security scan...")
  80. if !commandExists("gitleaks") {
  81. warn("GitLeaks not installed - skipping security scan")
  82. warn("Install with: paru -S gitleaks")
  83. fmt.Println()
  84. fmt.Print("Continue without security scan? (y/N): ")
  85. reader := bufio.NewReader(os.Stdin)
  86. answer, _ := reader.ReadString('\n')
  87. answer = strings.TrimSpace(strings.ToLower(answer))
  88. if answer != "y" && answer != "yes" {
  89. errorLog("Push cancelled for security")
  90. return fmt.Errorf("security scan cancelled")
  91. }
  92. return nil
  93. }
  94. log("Using GitLeaks for secret detection...")
  95. cmd := exec.Command("gitleaks", "detect", "--verbose", "--exit-code", "1")
  96. if err := cmd.Run(); err != nil {
  97. errorLog("❌ Secrets detected! Review before pushing.")
  98. return fmt.Errorf("secrets detected")
  99. }
  100. log("✅ No secrets detected")
  101. return nil
  102. }
  103. func isGitRepo() bool {
  104. cmd := exec.Command("git", "rev-parse", "--git-dir")
  105. return cmd.Run() == nil
  106. }
  107. func hasUncommittedChanges() bool {
  108. cmd := exec.Command("git", "diff-index", "--quiet", "HEAD", "--")
  109. return cmd.Run() != nil
  110. }
  111. func getCurrentBranch() (string, error) {
  112. cmd := exec.Command("git", "branch", "--show-current")
  113. output, err := cmd.Output()
  114. if err != nil {
  115. return "", err
  116. }
  117. return strings.TrimSpace(string(output)), nil
  118. }
  119. func handlePush() error {
  120. log("Preparing to push repository...")
  121. if !isGitRepo() {
  122. errorLog("Not in a git repository")
  123. return fmt.Errorf("not in git repo")
  124. }
  125. if hasUncommittedChanges() {
  126. warn("You have uncommitted changes")
  127. fmt.Println()
  128. cmd := exec.Command("git", "status", "--short")
  129. cmd.Stdout = os.Stdout
  130. cmd.Run()
  131. fmt.Println()
  132. defaultMsg := fmt.Sprintf("dev: automated commit - %s", time.Now().Format("2006-01-02 15:04:05"))
  133. fmt.Print("Commit all changes? (Y/n): ")
  134. reader := bufio.NewReader(os.Stdin)
  135. answer, _ := reader.ReadString('\n')
  136. answer = strings.TrimSpace(strings.ToLower(answer))
  137. if answer != "n" && answer != "no" {
  138. fmt.Println()
  139. fmt.Printf("Default: %s\n", defaultMsg)
  140. fmt.Print("Custom commit message (or press Enter for default): ")
  141. commitMsg, _ := reader.ReadString('\n')
  142. commitMsg = strings.TrimSpace(commitMsg)
  143. if commitMsg == "" {
  144. commitMsg = defaultMsg
  145. }
  146. if err := exec.Command("git", "add", ".").Run(); err != nil {
  147. return fmt.Errorf("failed to add changes: %v", err)
  148. }
  149. if err := exec.Command("git", "commit", "-m", commitMsg).Run(); err != nil {
  150. return fmt.Errorf("failed to commit changes: %v", err)
  151. }
  152. log("✓ Changes committed: %s", commitMsg)
  153. }
  154. }
  155. if err := runSecurityScan(); err != nil {
  156. return err
  157. }
  158. branch, err := getCurrentBranch()
  159. if err != nil {
  160. return fmt.Errorf("failed to get current branch: %v", err)
  161. }
  162. log("Pushing branch '%s' to origin...", branch)
  163. cmd := exec.Command("git", "push", "origin", branch)
  164. if err := cmd.Run(); err != nil {
  165. errorLog("❌ Push failed")
  166. return fmt.Errorf("push failed")
  167. }
  168. log("✅ Successfully pushed to origin/%s", branch)
  169. return nil
  170. }
  171. func getScriptMetadata(scriptPath string) (string, bool) {
  172. file, err := os.Open(scriptPath)
  173. if err != nil {
  174. return "No description", false
  175. }
  176. defer file.Close()
  177. var desc string
  178. var requiresSudo bool
  179. scanner := bufio.NewScanner(file)
  180. for scanner.Scan() {
  181. line := strings.TrimSpace(scanner.Text())
  182. if strings.HasPrefix(line, "# NAME:") {
  183. desc = strings.TrimSpace(strings.TrimPrefix(line, "# NAME:"))
  184. }
  185. if strings.HasPrefix(line, "# REQUIRES: sudo") ||
  186. strings.HasPrefix(line, "# REQUIRES:sudo") ||
  187. strings.HasPrefix(line, "# ELEVATED: true") ||
  188. strings.HasPrefix(line, "# ELEVATED:true") ||
  189. strings.HasPrefix(line, "# SUDO: true") ||
  190. strings.HasPrefix(line, "# SUDO:true") {
  191. requiresSudo = true
  192. }
  193. }
  194. if desc == "" {
  195. desc = "No description"
  196. }
  197. return desc, requiresSudo
  198. }
  199. func findScripts(filters []string) ([]Script, error) {
  200. var scripts []Script
  201. err := filepath.Walk(config.RunsDir, func(path string, info os.FileInfo, err error) error {
  202. if err != nil {
  203. return err
  204. }
  205. if info.Mode().IsRegular() && (info.Mode()&0o111) != 0 {
  206. // Get relative path from runs directory
  207. relPath, err := filepath.Rel(config.RunsDir, path)
  208. if err != nil {
  209. return err
  210. }
  211. // Skip hidden files and directories
  212. if strings.HasPrefix(filepath.Base(path), ".") {
  213. return nil
  214. }
  215. scriptName := filepath.Base(path)
  216. if len(filters) == 0 || matchesFilters(relPath, scriptName, filters) {
  217. desc, requiresSudo := getScriptMetadata(path)
  218. scripts = append(scripts, Script{
  219. Path: path,
  220. Name: scriptName,
  221. RelPath: relPath,
  222. Desc: desc,
  223. RequiresSudo: requiresSudo,
  224. })
  225. }
  226. }
  227. return nil
  228. })
  229. sort.Slice(scripts, func(i, j int) bool {
  230. return scripts[i].RelPath < scripts[j].RelPath
  231. })
  232. return scripts, err
  233. }
  234. func matchesFilters(relPath, scriptName string, filters []string) bool {
  235. for _, filter := range filters {
  236. // Normalize paths for comparison (remove .sh extension from filter if present)
  237. normalizedFilter := strings.TrimSuffix(filter, ".sh")
  238. normalizedRelPath := strings.TrimSuffix(relPath, ".sh")
  239. normalizedScriptName := strings.TrimSuffix(scriptName, ".sh")
  240. // Check exact matches
  241. if normalizedRelPath == normalizedFilter || normalizedScriptName == normalizedFilter {
  242. return true
  243. }
  244. // Check if filter matches the relative path or script name (case insensitive)
  245. filterLower := strings.ToLower(normalizedFilter)
  246. relPathLower := strings.ToLower(normalizedRelPath)
  247. scriptNameLower := strings.ToLower(normalizedScriptName)
  248. if strings.Contains(relPathLower, filterLower) || strings.Contains(scriptNameLower, filterLower) {
  249. return true
  250. }
  251. // Check directory match (e.g., "tools" matches "tools/install.sh")
  252. if strings.HasPrefix(relPathLower, filterLower+"/") {
  253. return true
  254. }
  255. }
  256. return false
  257. }
  258. func executeScript(script Script, args []string, verbose bool) error {
  259. logFile := filepath.Join(config.LogsDir, strings.TrimSuffix(script.Name, filepath.Ext(script.Name))+".log")
  260. var cmd *exec.Cmd
  261. if script.RequiresSudo {
  262. sudoLog("Script requires elevated privileges: %s", script.RelPath)
  263. if !commandExists("sudo") {
  264. errorLog("sudo command not found - cannot run elevated script")
  265. return fmt.Errorf("sudo not available")
  266. }
  267. fullArgs := append([]string{script.Path}, args...)
  268. cmd = exec.Command("sudo", fullArgs...)
  269. sudoLog("Running with sudo: %s", strings.Join(append([]string{script.Path}, args...), " "))
  270. } else {
  271. cmd = exec.Command(script.Path, args...)
  272. }
  273. if config.Interactive {
  274. cmd.Stdin = os.Stdin
  275. }
  276. logFileHandle, err := os.Create(logFile)
  277. if err != nil {
  278. return err
  279. }
  280. defer logFileHandle.Close()
  281. showOutput := verbose || config.Interactive
  282. if showOutput {
  283. cmd.Stdout = io.MultiWriter(os.Stdout, logFileHandle)
  284. cmd.Stderr = io.MultiWriter(os.Stderr, logFileHandle)
  285. } else {
  286. cmd.Stdout = logFileHandle
  287. cmd.Stderr = logFileHandle
  288. }
  289. return cmd.Run()
  290. }
  291. func createNewScript(scriptName string) error {
  292. scriptPath := filepath.Join(config.RunsDir, scriptName)
  293. dirPath := filepath.Dir(scriptPath)
  294. if err := os.MkdirAll(dirPath, 0o755); err != nil {
  295. return err
  296. }
  297. if !strings.HasSuffix(scriptName, ".sh") {
  298. scriptName += ".sh"
  299. }
  300. if _, err := os.Stat(scriptPath); err == nil {
  301. return fmt.Errorf("script %s already exists", scriptName)
  302. }
  303. template := fmt.Sprintf(`#!/usr/bin/env bash
  304. # NAME: %s script
  305. # REQUIRES: sudo
  306. set -euo pipefail
  307. echo "Running %s script..."
  308. echo "✅ %s completed successfully"
  309. `, strings.TrimSuffix(scriptName, ".sh"), scriptName, strings.TrimSuffix(scriptName, ".sh"))
  310. err := os.WriteFile(scriptPath, []byte(template), 0o755)
  311. if err != nil {
  312. return err
  313. }
  314. log("✅ Created script: %s", scriptPath)
  315. return nil
  316. }
  317. func initConfig() {
  318. wd, _ := os.Getwd()
  319. config.RunsDir = filepath.Join(wd, "runs")
  320. config.LogsDir = filepath.Join(wd, "logs")
  321. }
  322. func ensureRunsDir() error {
  323. if _, err := os.Stat(config.RunsDir); os.IsNotExist(err) {
  324. log("Creating runs directory at: %s", config.RunsDir)
  325. if err := os.MkdirAll(config.RunsDir, 0o755); err != nil {
  326. return err
  327. }
  328. exampleScript := filepath.Join(config.RunsDir, "example.sh")
  329. content := `#!/usr/bin/env bash
  330. # NAME: Example script
  331. echo "Hello from runs/example.sh!"
  332. echo "Edit this script or add your own to runs/"
  333. `
  334. if err := os.WriteFile(exampleScript, []byte(content), 0o755); err != nil {
  335. return err
  336. }
  337. sudoExampleScript := filepath.Join(config.RunsDir, "system-info.sh")
  338. sudoContent := `#!/usr/bin/env bash
  339. # NAME: System information collector
  340. # REQUIRES: sudo
  341. set -euo pipefail
  342. echo "Collecting system information (requires elevated privileges)..."
  343. echo "=== Disk Usage ==="
  344. df -h
  345. echo "=== Memory Info ==="
  346. free -h
  347. echo "=== System Logs (last 10 lines) ==="
  348. tail -n 10 /var/log/syslog 2>/dev/null || tail -n 10 /var/log/messages 2>/dev/null || echo "No accessible system logs"
  349. echo "✅ System info collection completed"
  350. `
  351. if err := os.WriteFile(sudoExampleScript, []byte(sudoContent), 0o755); err != nil {
  352. return err
  353. }
  354. log("✅ Created runs/ directory with example scripts")
  355. return nil
  356. }
  357. return nil
  358. }
  359. var rootCmd = &cobra.Command{
  360. Use: "dev",
  361. Short: "Development script runner",
  362. Long: "A CLI tool for managing and running development scripts",
  363. RunE: func(cmd *cobra.Command, args []string) error {
  364. // Default behavior: list scripts if no subcommand
  365. return listCmd.RunE(cmd, args)
  366. },
  367. }
  368. var runCmd = &cobra.Command{
  369. Use: "run [filters...] [-- script-args...]",
  370. Short: "Run scripts matching filters (or all if no filters)",
  371. Long: `Run scripts matching filters. Use -- to pass arguments to scripts.
  372. Scripts marked with "# REQUIRES: sudo" will automatically run with elevated privileges.
  373. Examples:
  374. dev run tools/dev.sh # Run specific script
  375. dev run tools/dev.sh -- arg1 arg2 # Run with arguments
  376. dev run --verbose install -- --force # Run with flags
  377. dev run system-info # Runs with sudo if marked as required`,
  378. ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
  379. scripts, err := findScripts(nil)
  380. if err != nil {
  381. return nil, cobra.ShellCompDirectiveNoFileComp
  382. }
  383. var completions []string
  384. for _, script := range scripts {
  385. if strings.HasPrefix(script.Name, toComplete) || strings.HasPrefix(script.RelPath, toComplete) {
  386. desc := script.Desc
  387. if script.RequiresSudo {
  388. desc = desc + " [SUDO]"
  389. }
  390. completions = append(completions, fmt.Sprintf("%s\t%s", script.RelPath, desc))
  391. }
  392. }
  393. return completions, cobra.ShellCompDirectiveNoFileComp
  394. },
  395. RunE: func(cmd *cobra.Command, args []string) error {
  396. // Parse arguments manually to handle -- separator
  397. var filters []string
  398. var scriptArgs []string
  399. // Find "run" command position and -- separator in raw args
  400. rawArgs := os.Args[1:] // Skip program name
  401. runIndex := -1
  402. dashDashIndex := -1
  403. for i, arg := range rawArgs {
  404. if arg == "run" {
  405. runIndex = i
  406. }
  407. if arg == "--" && runIndex >= 0 {
  408. dashDashIndex = i
  409. break
  410. }
  411. }
  412. if dashDashIndex >= 0 {
  413. for i := runIndex + 1; i < dashDashIndex; i++ {
  414. arg := rawArgs[i]
  415. if !strings.HasPrefix(arg, "-") {
  416. filters = append(filters, arg)
  417. }
  418. }
  419. scriptArgs = rawArgs[dashDashIndex+1:]
  420. } else {
  421. filters = args
  422. scriptArgs = []string{}
  423. }
  424. if err := ensureRunsDir(); err != nil {
  425. return err
  426. }
  427. if err := os.MkdirAll(config.LogsDir, 0o755); err != nil {
  428. return err
  429. }
  430. scripts, err := findScripts(filters)
  431. if err != nil {
  432. return err
  433. }
  434. if len(scripts) == 0 {
  435. if len(filters) > 0 {
  436. warn("No scripts match filters: %s", strings.Join(filters, ", "))
  437. } else {
  438. warn("No scripts found. Use 'dev new <name>' to create one")
  439. }
  440. return nil
  441. }
  442. for _, script := range scripts {
  443. if config.DryRun {
  444. argsStr := ""
  445. if len(scriptArgs) > 0 {
  446. argsStr = fmt.Sprintf(" with args: %s", strings.Join(scriptArgs, " "))
  447. }
  448. sudoStr := ""
  449. if script.RequiresSudo {
  450. sudoStr = " [SUDO]"
  451. }
  452. fmt.Printf("[DRY] Would run: %s - %s%s%s\n", script.RelPath, script.Desc, sudoStr, argsStr)
  453. continue
  454. }
  455. argsDisplay := ""
  456. if len(scriptArgs) > 0 {
  457. argsDisplay = fmt.Sprintf(" with args: %s", strings.Join(scriptArgs, " "))
  458. }
  459. sudoDisplay := ""
  460. if script.RequiresSudo {
  461. sudoDisplay = " [ELEVATED]"
  462. }
  463. fmt.Printf("Running: %s%s%s\n", script.RelPath, sudoDisplay, argsDisplay)
  464. if err := executeScript(script, scriptArgs, config.Verbose); err != nil {
  465. errorLog("❌ %s failed", script.RelPath)
  466. if !config.Verbose {
  467. fmt.Printf(" Check log: %s\n", filepath.Join(config.LogsDir, strings.TrimSuffix(script.Name, filepath.Ext(script.Name))+".log"))
  468. }
  469. } else {
  470. if script.RequiresSudo {
  471. sudoLog("✅ %s completed (elevated)", script.RelPath)
  472. } else {
  473. log("✅ %s completed", script.RelPath)
  474. }
  475. }
  476. }
  477. return nil
  478. },
  479. }
  480. var listCmd = &cobra.Command{
  481. Use: "ls",
  482. Aliases: []string{"list"},
  483. Short: "List all available scripts",
  484. RunE: func(cmd *cobra.Command, args []string) error {
  485. if err := ensureRunsDir(); err != nil {
  486. return err
  487. }
  488. scripts, err := findScripts(nil)
  489. if err != nil {
  490. return err
  491. }
  492. if len(scripts) == 0 {
  493. warn("No scripts found in %s", config.RunsDir)
  494. fmt.Println("Use 'dev new <name>' to create a new script")
  495. return nil
  496. }
  497. fmt.Printf("Available scripts in %s:\n\n", config.RunsDir)
  498. for _, script := range scripts {
  499. if script.RequiresSudo {
  500. fmt.Printf(" %s%s%s - %s %s[SUDO]%s\n",
  501. Blue, script.RelPath, NC, script.Desc, Purple, NC)
  502. } else {
  503. fmt.Printf(" %s%s%s - %s\n",
  504. Blue, script.RelPath, NC, script.Desc)
  505. }
  506. }
  507. sudoCount := 0
  508. for _, script := range scripts {
  509. if script.RequiresSudo {
  510. sudoCount++
  511. }
  512. }
  513. fmt.Printf("\nTotal: %d scripts", len(scripts))
  514. if sudoCount > 0 {
  515. fmt.Printf(" (%d require elevated privileges)", sudoCount)
  516. }
  517. fmt.Println()
  518. return nil
  519. },
  520. }
  521. var newCmd = &cobra.Command{
  522. Use: "new <name>",
  523. Short: "Create a new script template",
  524. Args: cobra.ExactArgs(1),
  525. RunE: func(cmd *cobra.Command, args []string) error {
  526. return createNewScript(args[0])
  527. },
  528. }
  529. var pushCmd = &cobra.Command{
  530. Use: "push",
  531. Aliases: []string{"u", "ush"},
  532. Short: "Commit, scan for secrets, and push to git origin",
  533. RunE: func(cmd *cobra.Command, args []string) error {
  534. return handlePush()
  535. },
  536. }
  537. var depsCmd = &cobra.Command{
  538. Use: "deps",
  539. Short: "Install dependencies",
  540. RunE: func(cmd *cobra.Command, args []string) error {
  541. return checkDependencies()
  542. },
  543. }
  544. var completionCmd = &cobra.Command{
  545. Use: "completion [bash|zsh|fish|powershell]",
  546. Short: "Generate completion script",
  547. Long: `To load completions:
  548. Bash:
  549. $ source <(dev completion bash)
  550. # To load completions for each session, execute once:
  551. # Linux:
  552. $ dev completion bash > /etc/bash_completion.d/dev
  553. # macOS:
  554. $ dev completion bash > $(brew --prefix)/etc/bash_completion.d/dev
  555. Zsh:
  556. # If shell completion is not already enabled in your environment,
  557. # you will need to enable it. You can execute the following once:
  558. $ echo "autoload -U compinit; compinit" >> ~/.zshrc
  559. # To load completions for each session, execute once:
  560. $ dev completion zsh > "${fpath[1]}/_dev"
  561. # You will need to start a new shell for this setup to take effect.
  562. `,
  563. DisableFlagsInUseLine: true,
  564. ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
  565. Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
  566. RunE: func(cmd *cobra.Command, args []string) error {
  567. switch args[0] {
  568. case "bash":
  569. return rootCmd.GenBashCompletion(os.Stdout)
  570. case "zsh":
  571. return rootCmd.GenZshCompletion(os.Stdout)
  572. case "fish":
  573. return rootCmd.GenFishCompletion(os.Stdout, true)
  574. case "powershell":
  575. return rootCmd.GenPowerShellCompletionWithDesc(os.Stdout)
  576. }
  577. return nil
  578. },
  579. }
  580. func main() {
  581. initConfig()
  582. runCmd.Flags().BoolVar(&config.DryRun, "dry", false, "Show what would run without executing")
  583. runCmd.Flags().BoolVarP(&config.Verbose, "verbose", "v", false, "Show script output in terminal")
  584. runCmd.Flags().BoolVarP(&config.Interactive, "interactive", "i", false, "Run script interactively (show output and allow input)")
  585. // This prevents Cobra from consuming -- and everything after it
  586. runCmd.Flags().SetInterspersed(false)
  587. rootCmd.AddCommand(runCmd, listCmd, newCmd, pushCmd, depsCmd, completionCmd)
  588. if err := rootCmd.Execute(); err != nil {
  589. os.Exit(1)
  590. }
  591. }