Browse Source

Enabled attempting to load ./issues on no args

arianagiroux 2 weeks ago
parent
commit
ccc4d9e843
3 changed files with 25 additions and 14 deletions
  1. 1 2
      Readme.md
  2. 24 10
      cmd/issues.go
  3. 0 2
      tui.go

+ 1 - 2
Readme.md

@@ -14,8 +14,7 @@ go install cmd/issues.go
 
 ## TODO
 
-- `cmd/issues.go:// TODO implement edit/delete funcs`
-- `cmd/issues.go:// TODO implement attempt to auto load issues folder if no arg specified`
+- `cmd/issues.go:// TODO implement edit/delete functions`
 - `io.go:func readPath(path string) (output string, err error) { // TODO DEPRECATE`
 - `io.go:func DeleteIssue(issue Issue) (success bool, err error) { return false, nil } // TODO: implement`
 - `tui.go:// TODO enable collection recursing (i.e, embedded collections)`

+ 24 - 10
cmd/issues.go

@@ -1,6 +1,4 @@
-// TODO implement edit/delete funcs
-//
-// TODO implement attempt to auto load issues folder if no arg specified
+// TODO implement edit/delete functions
 package main
 
 import (
@@ -16,30 +14,46 @@ func main() {
 	flag.Parse()
 	arg := flag.Args()
 
+	var path string
 	if len(arg) == 0 {
-		fmt.Println("Not enough arguments:", arg)
-		os.Exit(1)
+		_, err := os.Stat("issues")
+		if err == nil {
+			if issues.IsIssueCollection("issues") {
+				path = "issues"
+			} else {
+				fmt.Println("Could not load issues directory...")
+				os.Exit(1)
+			}
+		} else {
+			fmt.Println("Not enough arguments:", arg)
+			os.Exit(1)
+		}
+	}
+
+	if len(path) == 0 {
+		path = arg[0]
 	}
+
 	if len(arg) > 1 {
 		fmt.Println("Too many arguments:", arg)
 		os.Exit(1)
 	}
 
-	fileInfo, err := os.Stat(arg[0])
+	fileInfo, err := os.Stat(path)
 	if err == nil { // file exists
 		if fileInfo.IsDir() { // file is dir
-			if !issues.IsIssueCollection(arg[0]) && !issues.IsIssue(arg[0]) { // file is not issue collection and not issue
-				fmt.Printf("%s is a directory...\n", arg[0])
+			if !issues.IsIssueCollection(path) && !issues.IsIssue(path) { // file is not issue collection and not issue
+				fmt.Printf("%s is a directory...\n", path)
 				os.Exit(1)
 			}
 		} else {
-			fmt.Printf("%s is an existing file...\n", arg[0])
+			fmt.Printf("%s is an existing file...\n", path)
 			os.Exit(1)
 		}
 	}
 
 	p := tea.NewProgram(
-		issues.Model{Path: arg[0]},
+		issues.Model{Path: path},
 		tea.WithAltScreen(), // use the full size of the terminal in its "alternate screen buffer"
 		// tea.WithMouseCellMotion(), // turn on mouse support so we can track the mouse wheel
 	)

+ 0 - 2
tui.go

@@ -5,8 +5,6 @@
 // TODO enable collection recursing (i.e, embedded collections)
 //
 // TODO enable scroll/viewport logic
-//
-// TODO enable create new issue from collection browser
 package issues
 
 import (