Commits

Josh Rickmar  committed 629bc12

Various style changes

Move functions around so file can be read top down starting with
main(), use CamelCase for function names, and remove an unneeded error
variable.

  • Participants
  • Parent commits f1e7bef

Comments (0)

Files changed (1)

 	Main     template.HTML
 }
 
-func getdest(path string) (destpath string, dest *os.File) {
-	parts := strings.Split(path, string(filepath.Separator))
-	parts[0] = parts[0] + `.static`
-	last := &parts[len(parts)-1]
-	re := regexp.MustCompile(`\.md$`)
-	*last = re.ReplaceAllLiteralString(*last, `.html`)
-	destpath = strings.Join(parts, string(filepath.Separator))
-	fi, err := os.Stat(path)
-	if err == nil && !fi.IsDir() {
-		dest, err = os.Create(destpath)
+func main() {
+	flag.Parse()
+	fi, err := os.Stat(*dirFlag)
+	if err != nil || !fi.IsDir() {
+		fmt.Fprintln(os.Stderr, `Fatal: -in flag unset or not a directory`)
+		flag.Usage()
+		os.Exit(1)
+	}
+	if *tmplFlag == "" {
+		fmt.Fprintln(os.Stderr, `Fatal: -tmpl flag unset or not a file`)
+		flag.Usage()
+		os.Exit(1)
+	}
+
+	abs, _ := filepath.Abs(*dirFlag)
+	dir, inDir := filepath.Split(abs)
+	outDir := filepath.Join(dir, inDir+`.static`)
+	err = os.Chdir(dir)
+	if err != nil {
+		panic(err)
+	}
+
+	fi, err = os.Stat(outDir)
+	if err == nil {
+		err = os.RemoveAll(outDir)
 		if err != nil {
 			panic(err)
 		}
 	}
-	return
+
+	filepath.Walk(filepath.Base(*dirFlag), mkPage)
+	os.Exit(0)
 }
 
-func mkpage(srcPath string, info os.FileInfo, err error) error {
+func mkPage(srcPath string, info os.FileInfo, err error) error {
 	skip, err := regexp.MatchString(*ignoreRegExp, filepath.Base(srcPath))
 	if err != nil {
 		panic(err)
 	if err != nil {
 		panic(err)
 	}
-	destPath, dest := getdest(srcPath)
+	destPath, dest := getDest(srcPath)
 	if dest != nil {
 		defer dest.Close()
 	}
 	return nil
 }
 
-func main() {
-	flag.Parse()
-	fi, err := os.Stat(*dirFlag)
-	if err != nil || !fi.IsDir() {
-		fmt.Fprintln(os.Stderr, `Fatal: -in flag unset or not a directory`)
-		flag.Usage()
-		os.Exit(1)
-	}
-	if *tmplFlag == "" {
-		fmt.Fprintln(os.Stderr, `Fatal: -tmpl flag unset or not a file`)
-		flag.Usage()
-		os.Exit(1)
-	}
-
-	abs, _ := filepath.Abs(*dirFlag)
-	dir, inDir := filepath.Split(abs)
-	outDir := filepath.Join(dir, inDir+`.static`)
-	err = os.Chdir(dir)
-	if err != nil {
-		panic(err)
-	}
-
-	fi, err = os.Stat(outDir)
-	if err == nil {
-		rerr := os.RemoveAll(outDir)
-		if rerr != nil {
-			panic(rerr)
+func getDest(path string) (destPath string, dest *os.File) {
+	parts := strings.Split(path, string(filepath.Separator))
+	parts[0] = parts[0] + `.static`
+	last := &parts[len(parts)-1]
+	re := regexp.MustCompile(`\.md$`)
+	*last = re.ReplaceAllLiteralString(*last, `.html`)
+	destPath = strings.Join(parts, string(filepath.Separator))
+	fi, err := os.Stat(path)
+	if err == nil && !fi.IsDir() {
+		dest, err = os.Create(destPath)
+		if err != nil {
+			panic(err)
 		}
 	}
-
-	filepath.Walk(filepath.Base(*dirFlag), mkpage)
-	os.Exit(0)
+	return destPath, dest
 }