소스 검색

Prevented issues.go from running tui on path that is dir

arianagiroux 2 주 전
부모
커밋
c03ba77675
1개의 변경된 파일14개의 추가작업 그리고 1개의 파일을 삭제
  1. 14 1
      cmd/issues.go

+ 14 - 1
cmd/issues.go

@@ -17,10 +17,23 @@ func main() {
 	arg := flag.Args()
 
 	if len(arg) == 0 {
-		fmt.Println("Not enough args:", arg)
+		fmt.Println("Not enough arguments:", arg)
 		os.Exit(1)
 	}
 
+	fileInfo, err := os.Stat(arg[0])
+	if err != nil {
+		fmt.Println("could not run program:", err)
+		os.Exit(1)
+	}
+
+	if fileInfo.IsDir() {
+		if !issues.IsIssueCollection(fileInfo.Name()) {
+			fmt.Printf("%s is a directory...\n", arg[0])
+			os.Exit(1)
+		}
+	}
+
 	p := tea.NewProgram(
 		issues.Model{Path: arg[0]},
 		tea.WithAltScreen(), // use the full size of the terminal in its "alternate screen buffer"