Skip to content

Commit

Permalink
Add: -R, --recache
Browse files Browse the repository at this point in the history
  • Loading branch information
chinanf-boy committed Nov 3, 2018
1 parent e01b4e3 commit 9ddfcd6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
8 changes: 5 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ go get -v -u github.com/chinanf-boy/howdoi
- [x] **go** func with questions
- [x] colorful Code text with shell env `-c`/`-T`, [chroma](https://godoc.org/github.com/alecthomas/chroma)
- [x] cache Result `-C` [useful refs](https://github.com/chinanf-boy/howdoi/issues/3)
- [ ] ReCache Result ?
- [x] ReCache Result ?
- [ ] test file
- [ ] [Issue me anything](https://github.com/chinanf-boy/howdoi/issues/new)

> **Notes:** , cli-name Over the Python version cli
Expand Down Expand Up @@ -66,7 +67,7 @@ About the `ENV`
```js
usage: howdoi [-h|--help] [-c|--color] [-v|--version] [-n|--num <integer>]
-q|--query "<value>" [-q|--query "<value>" ...] [-D|--debug]
[-T|--theme "<value>"] [-C|--cache]
[-T|--theme "<value>"] [-C|--cache] [-R|--recache]

cli to Ask the question

Expand All @@ -79,7 +80,8 @@ Arguments:
-q --query query what
-D --debug debug *
-T --theme chrome styles. Default: pygments
-C --cache cache response? . Default: false
-C --cache cache response?. Default: false
-R --recache ReCache response?. Default: false
```

### Why rewrite
Expand Down
5 changes: 4 additions & 1 deletion src/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Cli struct {
Debug bool
Theme string
Cache bool
ReCache bool
}

// ArgsPar : get me parse OS.args with howdoi.Cli struct
Expand All @@ -29,6 +30,7 @@ func ArgsPar() (Cli, error) {
debug := parser.Flag("D", "debug", &argparse.Options{Required: false, Help: "debug *"})
theme := parser.String("T", "theme", &argparse.Options{Required: false, Help: "chrome styles", Default: "pygments"})
cache := parser.Flag("C", "cache", &argparse.Options{Required: false, Help: "cache response?", Default: false})
reCache := parser.Flag("R", "recache", &argparse.Options{Required: false, Help: "ReCache response?", Default: false})

// Parse input
err := parser.Parse(os.Args)
Expand All @@ -44,7 +46,8 @@ func ArgsPar() (Cli, error) {
Version: *version,
Debug: *debug,
Theme: *theme,
Cache: *cache}
Cache: *cache,
ReCache: *reCache}

return res, errStr
}
6 changes: 3 additions & 3 deletions src/howdoi.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ var (
scheme string
uRL string
starHeader string
userAgents []string
searchUrls map[string]string
answerHeader string
noAnswerMsg string
howdoiSession string
searchEngine string
)

Expand All @@ -48,6 +46,7 @@ func init() {
"google": scheme + "www.google.com/search?q=%s site:%s",
}

// format output
starHeader = "\u2605"
answerHeader = "%s Answer from " + aurora.Green("%s").String() + "\n\n%s"
noAnswerMsg = "< no answer given >"
Expand Down Expand Up @@ -206,7 +205,7 @@ func (clis Cli) getResult(u string) *goquery.Document {
cacheHandle := CacheHowdoi{cacheDir} // Get Cache
cacheBoby, ok := cacheHandle.cached(u)
// TODO ? clis.ReCache
if ok {
if ok && !clis.ReCache {
// resp from Cache
gLog(gree("0. Resq from Cache"))

Expand All @@ -216,6 +215,7 @@ func (clis Cli) getResult(u string) *goquery.Document {
log.Fatal(err)
}
} else { // GET URL
gLog(red("ReCache:%v"), clis.ReCache)
gLog(cyan("0. Resq from GET URL"))
var req *http.Request

Expand Down

0 comments on commit 9ddfcd6

Please sign in to comment.