Skip to content

Commit 03b37e9

Browse files
authored
Merge pull request #12 from hellt/fix-empty-cmd
Fix empty cmd set via cli from resetting inventory commands
2 parents 935ea72 + dc9b3a1 commit 03b37e9

File tree

7 files changed

+20
-32
lines changed

7 files changed

+20
-32
lines changed

.github/workflows/cicd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: set up go lint
3030
uses: golangci/golangci-lint-action@v2
3131
with:
32-
version: v1.40.1
32+
version: v1.43.0
3333

3434
build-and-release:
3535
runs-on: ubuntu-20.04

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
outputs*
44
dist
55
cmdo
6-
private
6+
private
7+
# ignore clab dirs
8+
clab-*
9+
.*.clab.y?ml

.golangci.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,13 @@ linters:
104104
- testpackage
105105
- wsl
106106

107-
issues:
108-
# Excluding configuration per-path, per-linter, per-text and per-source
109-
exclude-rules:
110-
- path: _test\.go
111-
linters:
112-
- gomnd
113-
114107
run:
115108
skip-dirs:
116109
- private
117110

118111
# golangci.com configuration
119112
# https://github.com/golangci/golangci/wiki/Configuration
120113
service:
121-
golangci-lint-version: 1.39.x # use the fixed version to not introduce new linters unexpectedly
114+
golangci-lint-version: 1.43.x # use the fixed version to not introduce new linters unexpectedly
122115
prepare:
123116
- echo "here I can run custom commands, but no preparation needed for this repo"

CHANGELOG.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
lint:
2-
docker run -it --rm -v $$(pwd):/app -w /app golangci/golangci-lint:v1.40.1 golangci-lint run -v
2+
docker run -it --rm -v $$(pwd):/work ghcr.io/hellt/golines:0.8.0 golines -w .
3+
docker run -it --rm -v $$(pwd):/app -w /app golangci/golangci-lint:v1.43.0 golangci-lint run -v

commando/inventory.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package commando
22

33
import (
4-
"io/ioutil"
4+
"os"
55
"regexp"
66
"strings"
77

@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
func (app *appCfg) loadInventoryFromYAML(i *inventory) error {
13-
yamlFile, err := ioutil.ReadFile(app.inventory)
13+
yamlFile, err := os.ReadFile(app.inventory)
1414
if err != nil {
1515
return err
1616
}
@@ -29,10 +29,13 @@ func (app *appCfg) loadInventoryFromYAML(i *inventory) error {
2929
app.credentials = i.Credentials
3030
app.transports = i.Transports
3131

32-
cmds := strings.Split(app.commands, "::")
32+
// user-provided commands (via cli flag) take precedence over inventory
33+
if app.commands != "" {
34+
cmds := strings.Split(app.commands, "::")
3335

34-
for _, device := range i.Devices {
35-
device.SendCommands = cmds
36+
for _, device := range i.Devices {
37+
device.SendCommands = cmds
38+
}
3639
}
3740

3841
return nil
@@ -85,7 +88,7 @@ func filterDevices(i *inventory, f string) {
8588
fRe := regexp.MustCompile(f)
8689

8790
for n := range i.Devices {
88-
if !fRe.Match([]byte(n)) {
91+
if !fRe.MatchString(n) {
8992
delete(i.Devices, n)
9093
}
9194
}

commando/respwriter.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package commando
22

33
import (
44
"fmt"
5-
"io/ioutil"
65
"os"
76
"path"
87
"strings"
@@ -124,21 +123,21 @@ func (w *fileWriter) WriteResponse(r []interface{}, name string) error {
124123
c := sanitizeCmd(resp.ChannelInput)
125124

126125
rb := []byte(resp.Result)
127-
if err := ioutil.WriteFile(path.Join(outDir, c), rb, filePermissions); err != nil {
126+
if err := os.WriteFile(path.Join(outDir, c), rb, filePermissions); err != nil {
128127
return err
129128
}
130129
}
131130
case *cfg.Response:
132131
rb := []byte(respObj.Result)
133-
if err := ioutil.WriteFile(path.Join(outDir, respObj.OperationType), rb, filePermissions); err != nil {
132+
if err := os.WriteFile(path.Join(outDir, respObj.OperationType), rb, filePermissions); err != nil {
134133
return err
135134
}
136135
case *cfg.DiffResponse:
137136
rb := []byte(
138137
fmt.Sprintf("Device Diff:\n%s\n\nSide By Side Diff:\n%s\n\nUnified Diff:\n%s",
139138
respObj.DeviceDiff, respObj.SideBySideDiff(), respObj.UnifiedDiff()),
140139
)
141-
if err := ioutil.WriteFile(path.Join(outDir, respObj.OperationType), rb, filePermissions); err != nil {
140+
if err := os.WriteFile(path.Join(outDir, respObj.OperationType), rb, filePermissions); err != nil {
142141
return err
143142
}
144143
}

0 commit comments

Comments
 (0)