62 lines
1.0 KiB
Go
Executable File
62 lines
1.0 KiB
Go
Executable File
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"jack/models"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func walk(rootDir string) ([]string, error) {
|
|
var files []string
|
|
|
|
err := filepath.Walk(rootDir, func(path string, info os.FileInfo, err error) error {
|
|
_, file := filepath.Split(path)
|
|
ext := filepath.Ext(file)
|
|
if !info.IsDir() && ext == ".md" {
|
|
files = append(files, path)
|
|
}
|
|
return nil
|
|
})
|
|
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
|
|
return files, err
|
|
}
|
|
|
|
func main() {
|
|
|
|
var rootDir *string
|
|
var outputDir *string
|
|
|
|
defaultOutputDir, err := os.MkdirTemp("", "go-jack")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
rootDir = flag.String("dir", ".", "Specify the directory to parse.")
|
|
outputDir = flag.String("out", defaultOutputDir, "Specify the output directory")
|
|
flag.Usage = func() {
|
|
fmt.Printf("Jack expects: \n")
|
|
fmt.Printf("./jack -dir <rootDir>\n")
|
|
}
|
|
flag.Parse()
|
|
|
|
files, _ := walk(*rootDir)
|
|
|
|
for _, file := range files {
|
|
fmt.Println(file)
|
|
article := models.Article{
|
|
File: file,
|
|
}
|
|
article.ReadFile()
|
|
fmt.Println(article)
|
|
}
|
|
|
|
fmt.Println(*outputDir)
|
|
}
|