Skip to content

Commit

Permalink
Merge pull request #2 from konoui/dev
Browse files Browse the repository at this point in the history
update workflow icon in fuzzy searching
  • Loading branch information
oui authored Jan 28, 2020
2 parents bd625d4 + bb08cb2 commit b115c6a
Show file tree
Hide file tree
Showing 13 changed files with 330 additions and 51 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![Generic badge](https://github.com/konoui/tldr/workflows/test/badge.svg)

## alfred tldr
tldr alfred workflow written in go.
This tldr also works as cli.
Expand Down
Binary file added assets/candidate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func renderToWorkflow(t *tldr.Tldr, cmds []string, enableFuzzy bool) {

p, _ := t.FindPage(cmds)
for _, cmd := range p.CmdExamples {
awf.Append(alfred.Item{
awf.Append(&alfred.Item{
Title: cmd.Cmd,
Subtitle: cmd.Description,
Arg: cmd.Cmd,
Expand All @@ -150,20 +150,23 @@ func renderToWorkflow(t *tldr.Tldr, cmds []string, enableFuzzy bool) {
if enableFuzzy && len(p.CmdExamples) == 0 {
index, err := t.LoadIndexFile()
if err != nil {
awf.Fatal(fmt.Sprintf("an error occurs: %s", err), "")
awf.Fatal("fatal error occurs", err.Error())
return
}

suggestions := index.Commands.Search(cmds)
for _, cmd := range suggestions {
awf.Append(alfred.Item{
awf.Append(&alfred.Item{
Title: cmd.Name,
Subtitle: fmt.Sprintf("Platforms: %s", strings.Join(cmd.Platform, ",")),
Autocomplete: cmd.Name,
Variables: map[string]string{
nextActionKey: nextActionCmd,
},
Arg: fmt.Sprintf("%s --platform %s", cmd.Name, cmd.Platform[0]),
Icon: &alfred.Icon{
Path: "candidate.png",
},
})
}
}
Expand Down
18 changes: 9 additions & 9 deletions cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,58 +48,58 @@ func TestExecute(t *testing.T) {
errMsg string
}{
{
description: "text output tests with lsof",
description: "text output. lsof",
expectErr: false,
command: "lsof --update",
filepath: "./test_output_lsof.txt",
tldrMaxAge: tldrMaxAge,
},
{
description: "text output tests sub cmd tests with git checkout",
description: "text output. sub command git checkout",
expectErr: false,
command: "git checkout",
filepath: "./test_output_git-checkout.txt",
tldrMaxAge: tldrMaxAge,
},
{
description: "text output tests with expired cache with lsof.",
description: "text output. expired cache",
expectErr: false,
command: "lsof",
filepath: "./test_output_lsof.txt",
errMsg: "more than a week passed, should update tldr using --update\n",
tldrMaxAge: 0 * time.Hour,
},
{
description: "page not found",
description: "text output. page not found",
expectErr: false,
command: "lsoff",
filepath: "./test_output_no_page.txt",
errMsg: "This page doesn't exist yet!\nSubmit new pages here: https://github.com/tldr-pages/tldr\n",
tldrMaxAge: tldrMaxAge,
},
{
description: "alfred workflow tests with lsof",
description: "alfred workflow. lsof",
expectErr: false,
command: "lsof --update --workflow",
filepath: "./test_output_lsof.json",
tldrMaxAge: tldrMaxAge,
},
{
description: "alfred workflow sub cmd tests with git checkout",
description: "alfred workflow. sub command git checkout",
expectErr: false,
command: "git checkout --workflow",
filepath: "./test_output_git-checkout.json",
tldrMaxAge: tldrMaxAge,
},
{
description: "alfred workflow fuzzy search",
description: "alfred workflow. fuzzy search",
expectErr: false,
command: " gitchec --workflow --fuzzy",
filepath: "./test_output_git-checkout_with_fuzzy.json",
tldrMaxAge: tldrMaxAge,
},
{
description: "alfred workflow tests with expired cache with lsof. alfred workflow show no error",
description: "alfred workflow. show no error when cache expired",
expectErr: false,
command: "lsof --workflow",
filepath: "./test_output_lsof.json",
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestExecute(t *testing.T) {
}

if !tt.expectErr && err != nil {
t.Errorf("unexpected error got: %+v", err.Error())
t.Errorf("unexpected error got: %+v", err)
}

outGotData := outBuf.Bytes()
Expand Down
9 changes: 9 additions & 0 deletions cmd/test_output_git-checkout_with_fuzzy.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"title": "git checkout",
"subtitle": "Platforms: common",
"arg": "git checkout --platform common",
"icon": {
"path": "candidate.png"
},
"autocomplete": "git checkout"
},
{
Expand All @@ -16,6 +19,9 @@
"title": "git check ignore",
"subtitle": "Platforms: common",
"arg": "git check ignore --platform common",
"icon": {
"path": "candidate.png"
},
"autocomplete": "git check ignore"
},
{
Expand All @@ -25,6 +31,9 @@
"title": "git cherry pick",
"subtitle": "Platforms: common",
"arg": "git cherry pick --platform common",
"icon": {
"path": "candidate.png"
},
"autocomplete": "git cherry pick"
}
]
Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ module github.com/konoui/tldr
go 1.13

require (
github.com/konoui/go-alfred v0.0.0-20200104065011-50d164695438
github.com/mattn/go-shellwords v1.0.6
github.com/google/go-cmp v0.3.1
github.com/konoui/go-alfred v0.0.0-20200127135617-de16667a28fe
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/mattn/go-shellwords v1.0.9
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/errors v0.9.1
github.com/sahilm/fuzzy v0.1.0
Expand Down
Loading

0 comments on commit b115c6a

Please sign in to comment.