main.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  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. if err := os.MkdirAll(config.RunsDir, 0o755); err != nil {
  293. return err
  294. }
  295. if !strings.HasSuffix(scriptName, ".sh") {
  296. scriptName += ".sh"
  297. }
  298. scriptPath := filepath.Join(config.RunsDir, scriptName)
  299. if _, err := os.Stat(scriptPath); err == nil {
  300. return fmt.Errorf("script %s already exists", scriptName)
  301. }
  302. template := fmt.Sprintf(`#!/usr/bin/env bash
  303. # NAME: %s script
  304. # REQUIRES: sudo
  305. set -euo pipefail
  306. echo "Running %s script..."
  307. echo "✅ %s completed successfully"
  308. `, strings.TrimSuffix(scriptName, ".sh"), scriptName, strings.TrimSuffix(scriptName, ".sh"))
  309. err := os.WriteFile(scriptPath, []byte(template), 0o755)
  310. if err != nil {
  311. return err
  312. }
  313. log("✅ Created script: %s", scriptPath)
  314. return nil
  315. }
  316. func initConfig() {
  317. wd, _ := os.Getwd()
  318. config.RunsDir = filepath.Join(wd, "runs")
  319. config.LogsDir = filepath.Join(wd, "logs")
  320. }
  321. func ensureRunsDir() error {
  322. if _, err := os.Stat(config.RunsDir); os.IsNotExist(err) {
  323. log("Creating runs directory at: %s", config.RunsDir)
  324. if err := os.MkdirAll(config.RunsDir, 0o755); err != nil {
  325. return err
  326. }
  327. exampleScript := filepath.Join(config.RunsDir, "example.sh")
  328. content := `#!/usr/bin/env bash
  329. # NAME: Example script
  330. echo "Hello from runs/example.sh!"
  331. echo "Edit this script or add your own to runs/"
  332. `
  333. if err := os.WriteFile(exampleScript, []byte(content), 0o755); err != nil {
  334. return err
  335. }
  336. sudoExampleScript := filepath.Join(config.RunsDir, "system-info.sh")
  337. sudoContent := `#!/usr/bin/env bash
  338. # NAME: System information collector
  339. # REQUIRES: sudo
  340. set -euo pipefail
  341. echo "Collecting system information (requires elevated privileges)..."
  342. echo "=== Disk Usage ==="
  343. df -h
  344. echo "=== Memory Info ==="
  345. free -h
  346. echo "=== System Logs (last 10 lines) ==="
  347. tail -n 10 /var/log/syslog 2>/dev/null || tail -n 10 /var/log/messages 2>/dev/null || echo "No accessible system logs"
  348. echo "✅ System info collection completed"
  349. `
  350. if err := os.WriteFile(sudoExampleScript, []byte(sudoContent), 0o755); err != nil {
  351. return err
  352. }
  353. log("✅ Created runs/ directory with example scripts")
  354. return nil
  355. }
  356. return nil
  357. }
  358. var rootCmd = &cobra.Command{
  359. Use: "dev",
  360. Short: "Development script runner",
  361. Long: "A CLI tool for managing and running development scripts",
  362. RunE: func(cmd *cobra.Command, args []string) error {
  363. // Default behavior: list scripts if no subcommand
  364. return listCmd.RunE(cmd, args)
  365. },
  366. }
  367. var runCmd = &cobra.Command{
  368. Use: "run [filters...] [-- script-args...]",
  369. Short: "Run scripts matching filters (or all if no filters)",
  370. Long: `Run scripts matching filters. Use -- to pass arguments to scripts.
  371. Scripts marked with "# REQUIRES: sudo" will automatically run with elevated privileges.
  372. Examples:
  373. dev run tools/dev.sh # Run specific script
  374. dev run tools/dev.sh -- arg1 arg2 # Run with arguments
  375. dev run --verbose install -- --force # Run with flags
  376. dev run system-info # Runs with sudo if marked as required`,
  377. ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
  378. scripts, err := findScripts(nil)
  379. if err != nil {
  380. return nil, cobra.ShellCompDirectiveNoFileComp
  381. }
  382. var completions []string
  383. for _, script := range scripts {
  384. if strings.HasPrefix(script.Name, toComplete) || strings.HasPrefix(script.RelPath, toComplete) {
  385. desc := script.Desc
  386. if script.RequiresSudo {
  387. desc = desc + " [SUDO]"
  388. }
  389. completions = append(completions, fmt.Sprintf("%s\t%s", script.RelPath, desc))
  390. }
  391. }
  392. return completions, cobra.ShellCompDirectiveNoFileComp
  393. },
  394. RunE: func(cmd *cobra.Command, args []string) error {
  395. // Parse arguments manually to handle -- separator
  396. var filters []string
  397. var scriptArgs []string
  398. // Find "run" command position and -- separator in raw args
  399. rawArgs := os.Args[1:] // Skip program name
  400. runIndex := -1
  401. dashDashIndex := -1
  402. for i, arg := range rawArgs {
  403. if arg == "run" {
  404. runIndex = i
  405. }
  406. if arg == "--" && runIndex >= 0 {
  407. dashDashIndex = i
  408. break
  409. }
  410. }
  411. if dashDashIndex >= 0 {
  412. for i := runIndex + 1; i < dashDashIndex; i++ {
  413. arg := rawArgs[i]
  414. if !strings.HasPrefix(arg, "-") {
  415. filters = append(filters, arg)
  416. }
  417. }
  418. scriptArgs = rawArgs[dashDashIndex+1:]
  419. } else {
  420. filters = args
  421. scriptArgs = []string{}
  422. }
  423. if err := ensureRunsDir(); err != nil {
  424. return err
  425. }
  426. if err := os.MkdirAll(config.LogsDir, 0o755); err != nil {
  427. return err
  428. }
  429. scripts, err := findScripts(filters)
  430. if err != nil {
  431. return err
  432. }
  433. if len(scripts) == 0 {
  434. if len(filters) > 0 {
  435. warn("No scripts match filters: %s", strings.Join(filters, ", "))
  436. } else {
  437. warn("No scripts found. Use 'dev new <name>' to create one")
  438. }
  439. return nil
  440. }
  441. for _, script := range scripts {
  442. if config.DryRun {
  443. argsStr := ""
  444. if len(scriptArgs) > 0 {
  445. argsStr = fmt.Sprintf(" with args: %s", strings.Join(scriptArgs, " "))
  446. }
  447. sudoStr := ""
  448. if script.RequiresSudo {
  449. sudoStr = " [SUDO]"
  450. }
  451. fmt.Printf("[DRY] Would run: %s - %s%s%s\n", script.RelPath, script.Desc, sudoStr, argsStr)
  452. continue
  453. }
  454. argsDisplay := ""
  455. if len(scriptArgs) > 0 {
  456. argsDisplay = fmt.Sprintf(" with args: %s", strings.Join(scriptArgs, " "))
  457. }
  458. sudoDisplay := ""
  459. if script.RequiresSudo {
  460. sudoDisplay = " [ELEVATED]"
  461. }
  462. fmt.Printf("Running: %s%s%s\n", script.RelPath, sudoDisplay, argsDisplay)
  463. if err := executeScript(script, scriptArgs, config.Verbose); err != nil {
  464. errorLog("❌ %s failed", script.RelPath)
  465. if !config.Verbose {
  466. fmt.Printf(" Check log: %s\n", filepath.Join(config.LogsDir, strings.TrimSuffix(script.Name, filepath.Ext(script.Name))+".log"))
  467. }
  468. } else {
  469. if script.RequiresSudo {
  470. sudoLog("✅ %s completed (elevated)", script.RelPath)
  471. } else {
  472. log("✅ %s completed", script.RelPath)
  473. }
  474. }
  475. }
  476. return nil
  477. },
  478. }
  479. var listCmd = &cobra.Command{
  480. Use: "ls",
  481. Aliases: []string{"list"},
  482. Short: "List all available scripts",
  483. RunE: func(cmd *cobra.Command, args []string) error {
  484. if err := ensureRunsDir(); err != nil {
  485. return err
  486. }
  487. scripts, err := findScripts(nil)
  488. if err != nil {
  489. return err
  490. }
  491. if len(scripts) == 0 {
  492. warn("No scripts found in %s", config.RunsDir)
  493. fmt.Println("Use 'dev new <name>' to create a new script")
  494. return nil
  495. }
  496. fmt.Printf("Available scripts in %s:\n\n", config.RunsDir)
  497. for _, script := range scripts {
  498. if script.RequiresSudo {
  499. fmt.Printf(" %s%s%s - %s %s[SUDO]%s\n",
  500. Blue, script.RelPath, NC, script.Desc, Purple, NC)
  501. } else {
  502. fmt.Printf(" %s%s%s - %s\n",
  503. Blue, script.RelPath, NC, script.Desc)
  504. }
  505. }
  506. sudoCount := 0
  507. for _, script := range scripts {
  508. if script.RequiresSudo {
  509. sudoCount++
  510. }
  511. }
  512. fmt.Printf("\nTotal: %d scripts", len(scripts))
  513. if sudoCount > 0 {
  514. fmt.Printf(" (%d require elevated privileges)", sudoCount)
  515. }
  516. fmt.Println()
  517. return nil
  518. },
  519. }
  520. var newCmd = &cobra.Command{
  521. Use: "new <name>",
  522. Short: "Create a new script template",
  523. Args: cobra.ExactArgs(1),
  524. RunE: func(cmd *cobra.Command, args []string) error {
  525. return createNewScript(args[0])
  526. },
  527. }
  528. var pushCmd = &cobra.Command{
  529. Use: "push",
  530. Aliases: []string{"u", "ush"},
  531. Short: "Commit, scan for secrets, and push to git origin",
  532. RunE: func(cmd *cobra.Command, args []string) error {
  533. return handlePush()
  534. },
  535. }
  536. var depsCmd = &cobra.Command{
  537. Use: "deps",
  538. Short: "Install dependencies",
  539. RunE: func(cmd *cobra.Command, args []string) error {
  540. return checkDependencies()
  541. },
  542. }
  543. var completionCmd = &cobra.Command{
  544. Use: "completion [bash|zsh|fish|powershell]",
  545. Short: "Generate completion script",
  546. Long: `To load completions:
  547. Bash:
  548. $ source <(dev completion bash)
  549. # To load completions for each session, execute once:
  550. # Linux:
  551. $ dev completion bash > /etc/bash_completion.d/dev
  552. # macOS:
  553. $ dev completion bash > $(brew --prefix)/etc/bash_completion.d/dev
  554. Zsh:
  555. # If shell completion is not already enabled in your environment,
  556. # you will need to enable it. You can execute the following once:
  557. $ echo "autoload -U compinit; compinit" >> ~/.zshrc
  558. # To load completions for each session, execute once:
  559. $ dev completion zsh > "${fpath[1]}/_dev"
  560. # You will need to start a new shell for this setup to take effect.
  561. `,
  562. DisableFlagsInUseLine: true,
  563. ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
  564. Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
  565. RunE: func(cmd *cobra.Command, args []string) error {
  566. switch args[0] {
  567. case "bash":
  568. return rootCmd.GenBashCompletion(os.Stdout)
  569. case "zsh":
  570. return rootCmd.GenZshCompletion(os.Stdout)
  571. case "fish":
  572. return rootCmd.GenFishCompletion(os.Stdout, true)
  573. case "powershell":
  574. return rootCmd.GenPowerShellCompletionWithDesc(os.Stdout)
  575. }
  576. return nil
  577. },
  578. }
  579. func main() {
  580. initConfig()
  581. runCmd.Flags().BoolVar(&config.DryRun, "dry", false, "Show what would run without executing")
  582. runCmd.Flags().BoolVarP(&config.Verbose, "verbose", "v", false, "Show script output in terminal")
  583. runCmd.Flags().BoolVarP(&config.Interactive, "interactive", "i", false, "Run script interactively (show output and allow input)")
  584. // This prevents Cobra from consuming -- and everything after it
  585. runCmd.Flags().SetInterspersed(false)
  586. rootCmd.AddCommand(runCmd, listCmd, newCmd, pushCmd, depsCmd, completionCmd)
  587. if err := rootCmd.Execute(); err != nil {
  588. os.Exit(1)
  589. }
  590. }