1
0
mirror of https://github.com/ericchiang/pup synced 2025-01-15 10:11:16 +00:00

Add ApplySelectors so we can reuse it.

This commit is contained in:
Chih-Wei (Bert) Chang 2014-09-24 00:43:25 +08:00
parent d39374885b
commit 7edf34aafe

42
main.go
View File

@ -1,15 +1,16 @@
package main package main
import ( import (
"code.google.com/p/go.net/html"
"code.google.com/p/go.net/html/charset"
"fmt" "fmt"
"github.com/ericchiang/pup/funcs"
"github.com/ericchiang/pup/selector"
"io" "io"
"os" "os"
"strconv" "strconv"
"strings" "strings"
"code.google.com/p/go.net/html"
"code.google.com/p/go.net/html/charset"
"github.com/ericchiang/pup/funcs"
"github.com/ericchiang/pup/selector"
) )
const VERSION string = "0.2.2" const VERSION string = "0.2.2"
@ -113,20 +114,8 @@ func ProcessFlags(cmds []string) []string {
return nonFlagCmds[:n] return nonFlagCmds[:n]
} }
// pup func ApplySelectors(cmds []string, root *html.Node) {
func main() { var err error
cmds := ProcessFlags(os.Args[1:])
cr, err := charset.NewReader(inputStream, "")
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(2)
}
root, err := html.Parse(cr)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(2)
}
inputStream.Close()
if len(cmds) == 0 { if len(cmds) == 0 {
PrintNode(root, 0) PrintNode(root, 0)
os.Exit(0) os.Exit(0)
@ -163,3 +152,20 @@ func main() {
} }
} }
} }
// pup
func main() {
cmds := ProcessFlags(os.Args[1:])
cr, err := charset.NewReader(inputStream, "")
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(2)
}
root, err := html.Parse(cr)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(2)
}
inputStream.Close()
ApplySelectors(cmds, root)
}