Exemplo n.º 1
0
func main() {
	var error os.Error
	var inode *os.Dir
	var file *os.File

	flag.Usage = usage
	flag.Parse()
	if flag.NArg() == 0 {
		fmt.Fprintf(os.Stderr, "no files were specified\n")
		os.Exit(ERROR)
	}

	for _, name := range flag.Args() {
		switch inode, error = os.Stat(name); {
		case error != nil:
		case inode.IsRegular():
			if file, error = os.Open(name, os.O_RDONLY, 0); error == nil {
				io.Copy(os.Stdout, file)
			}
		}
	}
	if error != nil {
		os.Exit(ERROR)
	}
	os.Exit(0)
}
Exemplo n.º 2
0
func main() {
	var rendered_content string
	var template []uint8
	var error os.Error
	var inode *os.Dir

	flag.Usage = usage
	flag.Parse()
	if flag.NArg() == 0 {
		fmt.Fprintf(os.Stderr, "no template rules defined\n")
		os.Exit(ERROR)
	}

	rules := make(Dictionary)
	for i := 0; i < flag.NArg(); i++ {
		rules.define(flag.Args()[i])
	}

	if *input_file == "" {
		if template, error = ioutil.ReadAll(os.Stdin); error == nil {
			rendered_content, error = mustache.Render(string(template), rules)
		}
	} else {
		switch inode, error = os.Stat(*input_file); {
		case error != nil:
		case inode.IsRegular():
			rendered_content, error = mustache.RenderFile(*input_file, rules)
		default:
		}
	}
	if error != nil {
		os.Exit(ERROR)
	} else {
		if *write {
			error = ioutil.WriteFile(*input_file, []byte(rendered_content), 0)
		} else {
			_, error = os.Stdout.Write([]byte(rendered_content))
		}
		if error != nil {
			os.Exit(ERROR)
		}
	}
	os.Exit(0)
}
Exemplo n.º 3
0
func walk(path string, d *os.Dir, v Visitor, errors chan<- os.Error) {
	if !d.IsDirectory() {
		v.VisitFile(path, d)
		return
	}

	if !v.VisitDir(path, d) {
		return // skip directory entries
	}

	list, err := io.ReadDir(path)
	if err != nil {
		if errors != nil {
			errors <- err
		}
	}

	for _, e := range list {
		walk(Join(path, e.Name), e, v, errors)
	}
}
Exemplo n.º 4
0
func isGoFile(dir *os.Dir) bool {
	return dir.IsRegular() &&
		!strings.HasPrefix(dir.Name, ".") && // ignore .files
		pathutil.Ext(dir.Name) == ".go"
}
Exemplo n.º 5
0
func isPkgDir(dir *os.Dir) bool {
	return dir.IsDirectory() && len(dir.Name) > 0 && dir.Name[0] != '_'
}
Exemplo n.º 6
0
func isGoFile(d *os.Dir) bool {
	// ignore non-Go files
	return d.IsRegular() && !strings.HasPrefix(d.Name, ".") && strings.HasSuffix(d.Name, ".go")
}