issues.go 1.3 KB

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