Skip to content

Commit

Permalink
fix tests and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
konoui committed Aug 20, 2021
1 parent 54916b0 commit 03b02fb
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
10 changes: 9 additions & 1 deletion cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestExecute(t *testing.T) {
down: func() { os.Unsetenv(envKeyCommandFormat) },
},
{
name: "tar with remove format",
name: "tar and open url with ctrl mod key",
args: args{
command: "tar",
filepath: testdataPath("test_output_tar_with_ctrl_mod_key.json"),
Expand Down Expand Up @@ -496,6 +496,14 @@ func Test_choicePlatform(t *testing.T) {
},
want: tldr.PlatformCommon,
},
{
name: "returns commond when empty pts",
args: args{
pts: []tldr.Platform{},
selected: tldr.PlatformCommon,
},
want: tldr.PlatformCommon,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

type envs struct {
formatFunc func(string) string
openURLModKey alfred.ModKey
modKeyOpenURL alfred.ModKey
isUpdateWorkflowRecommendEnabled bool
isUpdateDBRecommendEnabled bool
}
Expand All @@ -27,7 +27,7 @@ type config struct {
func newConfig() *config {
cfg := new(config)
cfg.fromEnv.formatFunc = getCommandFormatFunc()
cfg.fromEnv.openURLModKey = getOpenURLMod()
cfg.fromEnv.modKeyOpenURL = getModKeyOpenURL()
cfg.fromEnv.isUpdateDBRecommendEnabled = isUpdateDBRecommendEnabled()
cfg.fromEnv.isUpdateWorkflowRecommendEnabled = isUpdateWorkflowRecommendEnabled()
return cfg
Expand Down
14 changes: 7 additions & 7 deletions cmd/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (cfg *config) printPage(cmds []string) error {
}

awf.Append(
makeDescriptionItem(p, cfg.fromEnv.openURLModKey),
makeDescriptionItem(p, cfg.fromEnv.modKeyOpenURL),
)
for _, cmd := range p.CmdExamples {
command := cfg.fromEnv.formatFunc(cmd.Cmd)
Expand All @@ -85,7 +85,7 @@ func (cfg *config) printPage(cmds []string) error {
return nil
}

func makeDescriptionItem(p *tldr.Page, openURLModKey alfred.ModKey) *alfred.Item {
func makeDescriptionItem(p *tldr.Page, modKey alfred.ModKey) *alfred.Item {
// Note descriptions has one line at least
// see: https://github.com/tldr-pages/tldr/blob/master/contributing-guides/style-guide.md
title := p.CmdDescriptions[0]
Expand All @@ -94,15 +94,15 @@ func makeDescriptionItem(p *tldr.Page, openURLModKey alfred.ModKey) *alfred.Item
subtitle = p.CmdDescriptions[1]
}

mod := alfred.NewMod()
openMod := alfred.NewMod()
u, err := parseDetailURL(p.CmdDescriptions)
if err != nil {
awf.Logger().Warnln(err)
mod.
openMod.
Valid(false).
Subtitle("no action")
} else {
mod.
openMod.
Arg(u).
Subtitle("open more information url").
Variable(nextActionKey, nextActionOpenURL)
Expand All @@ -116,7 +116,7 @@ func makeDescriptionItem(p *tldr.Page, openURLModKey alfred.ModKey) *alfred.Item
alfred.NewIcon().
Path("description.png"),
).
Mod(openURLModKey, mod)
Mod(modKey, openMod)
}

func (cfg *config) printFuzzyPages(cmds []string) error {
Expand Down Expand Up @@ -179,7 +179,7 @@ func choicePlatform(pts []tldr.Platform, selected tldr.Platform) tldr.Platform {
}
}

// Note: unexpected case, we assume one pts at least but if zero return common
// Note: unexpected case, we assume one platform in pts at least but if empty, return common
if len(pts) == 0 {
return tldr.PlatformCommon
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func init() {
}
}

func getOpenURLMod() alfred.ModKey {
func getModKeyOpenURL() alfred.ModKey {
v := os.Getenv(envKeyOpenURLMod)
switch v {
case "alt":
Expand Down
6 changes: 3 additions & 3 deletions doc/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ The workflow provides some configurations via [workflow environment variables](h

### Open URL Modifier Key

`TLDR_MOD_KEY_OPEN_URL` is variable that configures to open detail command url with default web browser.
`TLDR_MOD_KEY_OPEN_URL` is variable that configures keys to open detail command url with web browser.

By default, you can open url with pressing `cmd` + `enter` if a specified command has related URL.
By default, you can open url with pressing `cmd(⌘)` + `enter` if a specified command has related URL.

Available variables are the followings

Expand All @@ -16,7 +16,7 @@ Available variables are the followings
- `fn`
- `shift`

For example, if you specified `ctrl` for `TLDR_MOD_KEY_OPEN_URL`, you can open url with pressing `ctrl` + `enter`.
For example, if you specified `ctrl` for `TLDR_MOD_KEY_OPEN_URL`, you can open url with pressing `ctrl(^)` + `enter`.

### Command Format

Expand Down

0 comments on commit 03b02fb

Please sign in to comment.