From 03b02fb676f1f7da847c1cfc4372b6677b623a0e Mon Sep 17 00:00:00 2001 From: konoui Date: Wed, 18 Aug 2021 22:22:54 +0900 Subject: [PATCH] fix tests and comment --- cmd/cmd_test.go | 10 +++++++++- cmd/config.go | 4 ++-- cmd/print.go | 14 +++++++------- cmd/workflow.go | 2 +- doc/CONFIGURATION.md | 6 +++--- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/cmd/cmd_test.go b/cmd/cmd_test.go index e690931..bc779e2 100644 --- a/cmd/cmd_test.go +++ b/cmd/cmd_test.go @@ -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"), @@ -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) { diff --git a/cmd/config.go b/cmd/config.go index de59666..756c4bc 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -7,7 +7,7 @@ import ( type envs struct { formatFunc func(string) string - openURLModKey alfred.ModKey + modKeyOpenURL alfred.ModKey isUpdateWorkflowRecommendEnabled bool isUpdateDBRecommendEnabled bool } @@ -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 diff --git a/cmd/print.go b/cmd/print.go index 53f61fc..0557999 100644 --- a/cmd/print.go +++ b/cmd/print.go @@ -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) @@ -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] @@ -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) @@ -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 { @@ -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 } diff --git a/cmd/workflow.go b/cmd/workflow.go index b3d5169..8a1e60b 100644 --- a/cmd/workflow.go +++ b/cmd/workflow.go @@ -53,7 +53,7 @@ func init() { } } -func getOpenURLMod() alfred.ModKey { +func getModKeyOpenURL() alfred.ModKey { v := os.Getenv(envKeyOpenURLMod) switch v { case "alt": diff --git a/doc/CONFIGURATION.md b/doc/CONFIGURATION.md index 175d9c2..52ac2c3 100644 --- a/doc/CONFIGURATION.md +++ b/doc/CONFIGURATION.md @@ -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 @@ -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