ssh-config 4.1.5 → 4.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Readme.md +3 -1
- package/index.js +13 -8
- package/package.json +1 -1
package/Readme.md
CHANGED
|
@@ -108,12 +108,14 @@ config.find({ Host: 'example1' })
|
|
|
108
108
|
config.find(line => line.param == 'Host' && line.value == 'example1')
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
-
### `.remove` sections by Host or
|
|
111
|
+
### `.remove` sections by Host / Match or function
|
|
112
112
|
|
|
113
113
|
To remove sections, we can pass the section to `.remove(opts)`.
|
|
114
114
|
|
|
115
115
|
```js
|
|
116
116
|
config.remove({ Host: 'example1' })
|
|
117
|
+
// or the ES2015 Array.prototype.find
|
|
118
|
+
config.remove(line => line.param == 'Host' && line.value == 'example1')
|
|
117
119
|
```
|
|
118
120
|
|
|
119
121
|
### `.append` sections
|
package/index.js
CHANGED
|
@@ -79,7 +79,7 @@ class SSHConfig extends Array {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
|
-
* find section by Host or
|
|
82
|
+
* find section by Host / Match or function
|
|
83
83
|
*/
|
|
84
84
|
find(opts = {}) {
|
|
85
85
|
if (typeof opts === 'function') return super.find(opts)
|
|
@@ -92,17 +92,22 @@ class SSHConfig extends Array {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
|
-
* Remove section
|
|
95
|
+
* Remove section by Host / Match or function
|
|
96
96
|
*/
|
|
97
97
|
remove(opts = {}) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
let index;
|
|
99
|
+
|
|
100
|
+
if (typeof opts === 'function') {
|
|
101
|
+
index = super.findIndex(opts);
|
|
102
|
+
|
|
103
|
+
} else if (!(opts && ('Host' in opts || 'Match' in opts))) {
|
|
104
|
+
throw new Error('Can only remove by Host or Match');
|
|
101
105
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
: super.findIndex(line => compare(line, opts))
|
|
106
|
+
} else {
|
|
107
|
+
index = super.findIndex(line => compare(line, opts));
|
|
105
108
|
|
|
109
|
+
}
|
|
110
|
+
|
|
106
111
|
if (index >= 0) return this.splice(index, 1)
|
|
107
112
|
}
|
|
108
113
|
|