issues.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "issues"
  6. "os"
  7. tea "github.com/charmbracelet/bubbletea"
  8. )
  9. func main() {
  10. flag.Parse()
  11. arg := flag.Args()
  12. var path string
  13. if len(arg) == 0 {
  14. _, err := os.Stat("issues")
  15. if err == nil {
  16. if issues.IsIssueCollection("issues") {
  17. path = "issues"
  18. } else {
  19. fmt.Println("Could not load issues directory...")
  20. os.Exit(1)
  21. }
  22. } else {
  23. fmt.Println("No issues folder detected.\nNot enough arguments:", arg)
  24. os.Exit(1)
  25. }
  26. }
  27. if len(path) == 0 {
  28. path = arg[0]
  29. }
  30. if len(arg) > 1 {
  31. fmt.Println("Too many arguments:", arg)
  32. os.Exit(1)
  33. }
  34. fileInfo, err := os.Stat(path)
  35. if err == nil { // file exists
  36. if fileInfo.IsDir() { // file is dir
  37. if !issues.IsIssueCollection(path) && !issues.IsIssue(path) { // file is not issue collection and not issue
  38. fmt.Printf("%s is a directory...\n", path)
  39. os.Exit(1)
  40. }
  41. } else {
  42. fmt.Printf("%s is an existing file...\n", path)
  43. os.Exit(1)
  44. }
  45. }
  46. p := tea.NewProgram(
  47. issues.Model{Path: path},
  48. tea.WithAltScreen(), // use the full size of the terminal in its "alternate screen buffer"
  49. // tea.WithMouseCellMotion(), // turn on mouse support so we can track the mouse wheel
  50. )
  51. if _, e := p.Run(); e != nil {
  52. fmt.Println("could not run program:", err)
  53. os.Exit(1)
  54. }
  55. }