Skip to content

Commit 7862000

Browse files
greguzgreguz
authored andcommitted
added dep chalk
added dep minimist created cli interface updated README
1 parent 9a9ad56 commit 7862000

3 files changed

Lines changed: 135 additions & 6 deletions

File tree

README.md

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
npm install --save raidar
99
```
1010

11-
## Example
12-
13-
### Code
11+
### Code example
1412

1513
``` js
1614
var raidar = require('raidar');
@@ -30,7 +28,7 @@ raidar.request('192.168.1.160', function(err, device) {
3028
});
3129
```
3230

33-
### Output
31+
### Output example
3432

3533
```
3634
Waiting...
@@ -145,6 +143,51 @@ the most common parts are `fan`, `ups`, `volume`, `disk` and `model`.
145143
for example `device.status('disk', 1)` return the second hdd (if present),
146144
otherwise `device.status('disk')` return a Collection (if exists more than one disk).
147145

146+
## Installing globally
147+
148+
```
149+
npm install -g raidar
150+
```
151+
152+
### Command line example
153+
154+
```
155+
$ raidar -t 5 -p
156+
```
157+
158+
### Command line output example
159+
160+
```
161+
version=4.1.14,time=1412273301
162+
ip: 192.168.1.160
163+
mac: 0:0d:a2:02:2e:1d
164+
fan
165+
status ok
166+
descr 1704RPM
167+
ups
168+
status not_present
169+
descr Not present
170+
volume
171+
status warn
172+
descr Volume C: RAID Level 1, Not redundant. A disk failure will render this volume dead.; 750 GB (81%) of 921 GB used
173+
disk
174+
status dead
175+
descr Channel 1: Seagate ST31000528AS 931 GB, 0C/32F[Dead]
176+
disk
177+
status ok
178+
descr Channel 2: Seagate ST31000528AS 931 GB, 36C/96F
179+
model
180+
mode home
181+
descr ReadyNAS Duo
182+
arch nsp
183+
```
184+
185+
## CLI arguments
186+
187+
- `-t` or `--timeout`
188+
- `-p` or `--part`
189+
- `-i` or `--index`
190+
148191
## Running test
149192

150193
```

lib/cli.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#! /usr/bin/env node
2+
3+
4+
// dependencies
5+
6+
var chalk = require('chalk'),
7+
minimist = require('minimist'),
8+
raidar = require('./raidar'),
9+
_ = require('lodash');
10+
11+
12+
// print with tabs utility
13+
14+
var print = function() {
15+
console.log(_.values(arguments).join('\t'));
16+
};
17+
18+
19+
// exit from process
20+
21+
var exit = function(err) {
22+
if (err) console.log(chalk.red(err));
23+
print();
24+
raidar.close();
25+
process.exit(err ? 1 : 0);
26+
};
27+
28+
29+
// status print utility
30+
31+
var printStatus = function(status) {
32+
print(chalk.yellow(status.name));
33+
34+
for (var field in status) {
35+
if (field[0] === '_' || field === 'name') continue;
36+
print(field, status[field])
37+
}
38+
};
39+
40+
41+
// vars
42+
43+
var argv = minimist(process.argv.slice(2)),
44+
timeout = (argv.timeout || argv.t || 10) * 1000,
45+
part = argv.part || argv.p,
46+
index = argv.index || argv.i;
47+
48+
49+
// start request
50+
51+
raidar.request(timeout, exit);
52+
53+
54+
// on error end
55+
56+
raidar.on('error', exit);
57+
58+
59+
// print info
60+
61+
raidar.on('device', function(device) {
62+
print();
63+
print(chalk.bold.yellow(device.hostname()));
64+
print(device.info());
65+
print('ip:', device.ip());
66+
print('mac:', device.mac());
67+
68+
var status = device.status(part, index);
69+
70+
if (status instanceof Array) {
71+
status.forEach(printStatus);
72+
} else if (status) {
73+
printStatus(status);
74+
}
75+
76+
if (part === true) {
77+
for (var name in device._data) {
78+
device._data[name].forEach(printStatus);
79+
}
80+
}
81+
});

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "raidar",
3-
"version": "0.5.1",
3+
"version": "0.6.0",
44
"description": "NetGear RAIDar node.js implementation",
55
"main": "./lib/raidar.js",
66
"scripts": {
@@ -17,14 +17,19 @@
1717
"url": "https://github.com/greguz/node-raidar/issues"
1818
},
1919
"dependencies": {
20-
"lodash": "^3.4.0"
20+
"chalk": "^1.0.0",
21+
"lodash": "^3.4.0",
22+
"minimist": "^1.1.1"
2123
},
2224
"devDependencies": {
2325
"grunt": "^0.4.5",
2426
"grunt-contrib-jshint": "^0.11.2",
2527
"grunt-mocha-test": "^0.12.7",
2628
"mocha": "^2.2.4"
2729
},
30+
"bin": {
31+
"raidar": "./lib/cli.js"
32+
},
2833
"keywords": [
2934
"netgear",
3035
"raidar",

0 commit comments

Comments
 (0)