Skip to content

Commit

Permalink
Fix behavior when openocd does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
sago35 committed May 11, 2022
1 parent 90af47d commit b86e2b7
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions autocmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var flagCompleteMap = map[string][]string{
"o": {},
"ocd-commands": {},
"ocd-output": nil,
"ocd-verify": nil,
"opt": {"0", "1", "2", "s", "z"},
"p": {},
"panic": {"print", "trap"},
Expand Down Expand Up @@ -311,20 +312,18 @@ func getProgrammers() ([]string, error) {
programmers := []string{}

p, err := exec.LookPath(`openocd`)
if err != nil {
return nil, err
}

b := filepath.Dir(p)
matches, err := filepath.Glob(fmt.Sprintf("%s/../share/openocd/scripts/interface/*.cfg", b))
if err != nil {
return nil, err
}
if err == nil {
b := filepath.Dir(p)
matches, err := filepath.Glob(fmt.Sprintf("%s/../share/openocd/scripts/interface/*.cfg", b))
if err != nil {
return nil, err
}

for _, m := range matches {
programmer := strings.TrimSuffix(m, filepath.Ext(m))
programmer = filepath.Base(programmer)
programmers = append(programmers, programmer)
for _, m := range matches {
programmer := strings.TrimSuffix(m, filepath.Ext(m))
programmer = filepath.Base(programmer)
programmers = append(programmers, programmer)
}
}

if len(programmers) == 0 {
Expand Down

0 comments on commit b86e2b7

Please sign in to comment.