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:
parent
d39374885b
commit
7edf34aafe
42
main.go
42
main.go
@ -1,15 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"code.google.com/p/go.net/html"
|
||||
"code.google.com/p/go.net/html/charset"
|
||||
"fmt"
|
||||
"github.com/ericchiang/pup/funcs"
|
||||
"github.com/ericchiang/pup/selector"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
"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"
|
||||
@ -113,20 +114,8 @@ func ProcessFlags(cmds []string) []string {
|
||||
return nonFlagCmds[:n]
|
||||
}
|
||||
|
||||
// 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()
|
||||
func ApplySelectors(cmds []string, root *html.Node) {
|
||||
var err error
|
||||
if len(cmds) == 0 {
|
||||
PrintNode(root, 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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user