未验证 提交 4abf6fd4 编写于 作者: LinuxSuRen's avatar LinuxSuRen 提交者: GitHub

Fix the bash completion error which caused by refactoring (#294)

* Fix the bash completion error which caused by refactoring

* Fix the failure test cases caused by list filter
上级 0f300927
......@@ -3,13 +3,14 @@ package cmd
import (
"encoding/json"
"fmt"
"go.uber.org/zap"
"gopkg.in/yaml.v2"
"io"
"net/http"
"reflect"
"strings"
"go.uber.org/zap"
"github.com/AlecAivazis/survey/v2"
"github.com/jenkins-zh/jenkins-cli/app/i18n"
"github.com/jenkins-zh/jenkins-cli/client"
......@@ -130,10 +131,6 @@ func (o *OutputOption) ListFilter(obj interface{}) interface{} {
// Match filter an item
func (o *OutputOption) Match(item reflect.Value) bool {
if len(o.Filter) == 0 {
return true
}
for _, f := range o.Filter {
arr := strings.Split(f, "=")
if len(arr) < 2 {
......@@ -144,12 +141,10 @@ func (o *OutputOption) Match(item reflect.Value) bool {
val := arr[1]
if !strings.Contains(util.ReflectFieldValueAsString(item, key), val) {
continue
} else {
return true
return false
}
}
return false
return true
}
// GetLine returns the line of a table
......
......@@ -148,7 +148,7 @@ foo-1
Expect(result).To(BeTrue())
})
Context("invalid filter", func() {
Context("ignore invalid filter", func() {
BeforeEach(func() {
outputOption = cmd.OutputOption{
Filter: []string{"Name"},
......@@ -156,7 +156,7 @@ foo-1
})
It("not matched", func() {
Expect(result).To(BeFalse())
Expect(result).To(BeTrue())
})
})
})
......
......@@ -126,7 +126,7 @@ fake 1.0 true
request.SetBasicAuth("admin", "111e3a2f0231198855dceaff96f20540a9")
rootCmd.SetArgs([]string{"plugin", "list", "fake", "--output", "yaml", "--filter", "HasUpdate=true",
"--filter", "Name=fake", "--filter", "Enable=true", "--filter", "Active=true"})
"--filter", "ShortName=fake", "--filter", "Enable=true", "--filter", "Active=true"})
buf := new(bytes.Buffer)
rootCmd.SetOutput(buf)
......
......@@ -275,8 +275,8 @@ const (
jcliBashCompletionFunc = `__plugin_name_parse_get()
{
local jcli_output out
if jcli_output=$(jcli plugin list --filter hasUpdate --no-headers --filter name="$1" 2>/dev/null); then
out=($(echo "${jcli_output}" | awk '{print $2}'))
if jcli_output=$(jcli plugin list --filter HasUpdate=true --no-headers --filter ShortName="$1" 2>/dev/null); then
out=($(echo "${jcli_output}" | awk '{print $1}'))
COMPREPLY=( $( compgen -W "${out[*]}" -- "$cur" ) )
fi
}
......@@ -293,7 +293,7 @@ __config_name_parse_get()
{
local jcli_output out
if jcli_output=$(jcli config list --no-headers 2>/dev/null); then
out=($(echo "${jcli_output}" | awk '{print $2}'))
out=($(echo "${jcli_output}" | awk '{print $1}'))
COMPREPLY=( $( compgen -W "${out[*]}" -- "$cur" ) )
fi
}
......@@ -309,7 +309,7 @@ __jcli_get_config_name()
__job_name_parse_get()
{
local jcli_output out
if jcli_output=$(jcli job search -o path "$cur" 2>/dev/null); then
if jcli_output=$(jcli job search --columns URL --no-headers "$cur" 2>/dev/null); then
out=($(echo "${jcli_output}"))
COMPREPLY=( ${out} )
fi
......@@ -323,6 +323,23 @@ __jcli_get_job_name()
fi
}
__computer_name_parse_get()
{
local jcli_output out
if jcli_output=$(jcli computer list --no-headers --columns DisplayName 2>/dev/null); then
out=($(echo "${jcli_output}"))
COMPREPLY=( ${out} )
fi
}
__jcli_get_computer_name()
{
__computer_name_parse_get
if [[ $? -eq 0 ]]; then
return 0
fi
}
__jcli_custom_func() {
case ${last_command} in
jcli_plugin_upgrade | jcli_plugin_uninstall)
......@@ -333,6 +350,10 @@ __jcli_custom_func() {
__jcli_get_config_name
return
;;
jcli_computer_delete | jcli_computer_delete | jcli_computer_launch)
__jcli_get_computer_name
return
;;
jcli_job_build | jcli_job_stop | jcli_job_log | jcli_job_delete | jcli_job_history | jcli_job_artifact | jcli_job_input)
__jcli_get_job_name
return
......
......@@ -2,6 +2,7 @@ package cmd
import (
"fmt"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
"os/exec"
......@@ -10,8 +11,6 @@ import (
"go.uber.org/zap"
"gopkg.in/yaml.v2"
"github.com/jenkins-zh/jenkins-cli/app/i18n"
"github.com/spf13/cobra"
......@@ -32,6 +31,7 @@ fi
if type -t __start_jcli >/dev/null; then true; else
source <(jcli completion)
fi
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
`
zshRcFile = `
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册