Commits

Miki Tebeka committed d99f13f

verbose flag

Comments (0)

Files changed (2)

 	info os.FileInfo
 }
 
+var verbose bool
+
 // iterfiles iterats of directory tree, returns a channel with files to process
 func iterfiles(root string) chan *File {
 	out := make(chan *File)
 	os.Exit(1)
 }
 
+// info prints some information to os.Stdout if global "verbose" is true
+func info(format string, args ...interface{}) {
+	if !verbose {
+		return
+	}
+	fmt.Printf(format, args...)
+}
+
 // dirExists return true if path exists and is a directory
 func dirExists(path string) bool {
 	info, err := os.Stat(path)
 	fmt.Fprintf(out, "var resources = map[string]Resource {\n")
 
 	for file := range iterfiles(root) {
+		info("adding %s\n", file.path)
 		if err := writeResource(prefix, file, out); err != nil {
 			return fmt.Errorf("can't write %s - %s", file.path, err)
 		}
 	var showVersion bool
 
 	flag.BoolVar(&showVersion, "version", false, "show version and exit")
+	flag.BoolVar(&verbose, "v", false, "be verbose")
 	flag.Usage = func() {
 		fmt.Fprintf(os.Stderr, "usage: %s RESOURCE_DIR\n", os.Args[0])
 		flag.PrintDefaults()
 	}()
 
 	outfile := fmt.Sprintf("%s/nrsc.go", outdir)
+	info("creating %s\n", outfile)
 	err := ioutil.WriteFile(outfile, []byte(iface), 0666)
 	if err != nil {
 		die("can't create %s - %s", outfile, err)
 	}
 
 	outfile = fmt.Sprintf("%s/data.go", outdir)
+	info("creating %s\n", outfile)
 	out, err := os.Create(outfile)
 	if err != nil {
 		die("can't create %s - %s", outfile, err)
 	"net/http"
 	"os"
 	"os/exec"
+	"strings"
 	"testing"
 	"time"
 )
 func TestText(t *testing.T) {
 	expected := map[string]string{
 		"Content-Size": "12",
-		"Content-Type": "text/plain; charset=utf-8",
+		"Content-Type": "text/plain",
 	}
 	checkPath(t, "ht.txt", expected)
 }
 func TestSub(t *testing.T) {
 	expected := map[string]string{
 		"Content-Size": "1150",
-		"Content-Type": "image/x-icon",
+		"Content-Type": "image/",
 	}
 	checkPath(t, "sub/favicon.ico", expected)
 }
 	for key := range expected {
 		v1 := expected[key]
 		v2 := headers.Get(key)
-		if v1 != v2 {
+		if !strings.HasPrefix(v2, v1) {
 			t.Fatalf("bad header %s: %s <-> %s", key, v1, v2)
 		}
 	}