Skip to content

Commit

Permalink
update 0.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
syui committed May 15, 2020
1 parent 9b1009a commit 55f36da
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
index.xml
news.xml
xq
go.sum
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ before_install:

script:
- gox -output "dist/{{.OS}}_{{.Arch}}_{{.Dir}}"
- ghr --username syui --token $GITHUB_TOKEN --replace --debug 0.3.4 dist/
- ghr --username syui --token $GITHUB_TOKEN --replace --debug 0.3.5 dist/
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module github.com/syui/xq
go 1.13

require (
github.com/PuerkitoBio/goquery v1.5.0 // indirect
github.com/andybalholm/cascadia v1.1.0 // indirect
github.com/PuerkitoBio/goquery v1.5.1 // indirect
github.com/andybalholm/cascadia v1.2.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/mmcdole/gofeed v1.0.0-beta2
github.com/mmcdole/goxpp v0.0.0-20181012175147-0068e33feabf // indirect
github.com/mmcdole/gofeed v1.0.0
github.com/syui/shasumgo v0.0.0-20200305033558-689961db39fd // indirect
github.com/urfave/cli v1.22.2
github.com/urfave/cli/v2 v2.0.0
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 // indirect
github.com/urfave/cli/v2 v2.2.0
golang.org/x/net v0.0.0-20200513185701-a91f0712d120 // indirect
golang.org/x/text v0.3.2 // indirect
)
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ $ xq l p index.xml

# latest item description
$ xq l d index.xml

# latest item author
$ xq l a index.xml
```

## update
Expand All @@ -111,3 +114,5 @@ $ xq l d index.xml
- 0.3.3 : change option/all, $ xq a ./index.xml

- 0.3.4 : change option/update -> latest, $ xq latest ./index.xml

- 0.3.4 : change option/update -> latest, $ xq latest author ./index.xml
38 changes: 37 additions & 1 deletion xq.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,31 @@ import (
"os"
"encoding/json"
"github.com/urfave/cli/v2"
"github.com/mmcdole/gofeed"
"github.com/mmcdole/gofeed/rss"
_ "reflect"
gofeed "github.com/mmcdole/gofeed"
)

type MyCustomTranslator struct {
defaultTranslator *gofeed.DefaultRSSTranslator
}
func NewMyCustomTranslator() *MyCustomTranslator {
t := &MyCustomTranslator{}
t.defaultTranslator = &gofeed.DefaultRSSTranslator{}
return t
}
func (ct* MyCustomTranslator) Translate(feed interface{}) (*gofeed.Feed, error) {
rss, found := feed.(*rss.Feed)
if !found {
return nil, fmt.Errorf("Feed did not match expected type of *rss.Feed")
}
f,err := ct.defaultTranslator.Translate(rss)
if err != nil {
return nil, err
}
return f, nil
}

func App() *cli.App {
app := cli.NewApp()
app.Name = "xq"
Expand Down Expand Up @@ -153,6 +174,21 @@ func main() {
return nil
},
},
{
Name: "author",
Aliases: []string{"a"},
Usage: "xq l published ./index.xml #latest itme author",
Action: func(c *cli.Context) error {
file, _ := os.Open(c.Args().First())
defer file.Close()
fp := gofeed.NewParser()
fp.RSSTranslator = NewMyCustomTranslator()
feed, _ := fp.Parse(file)
item := feed.Items[0].Author
fmt.Printf("%s", item)
return nil
},
},
},
Action: func(c *cli.Context) error {
file, _ := os.Open(c.Args().First())
Expand Down

0 comments on commit 55f36da

Please sign in to comment.