Permalink
Browse files

OS-1751 mkzpool should accept -f

  • Loading branch information...
1 parent 397889a commit 6af1162c6da406801f719d2d3d5281e2d5ce7db9 @wesolows wesolows committed Dec 10, 2012
Showing with 36 additions and 9 deletions.
  1. +24 −5 src/mkzpool.js
  2. +12 −4 src/node_modules/zfs.js
View
@@ -6,6 +6,7 @@
var fs = require('fs');
var zfs = require('/usr/node/node_modules/zfs');
+var getopt = require('/usr/node/node_modules/getopt');
function
fatal(msg)
@@ -17,22 +18,40 @@ fatal(msg)
function
usage()
{
- console.log('usage: ' + process.argv[0] + ' <pool> <file.json>');
+ console.log('usage: ' + process.argv[0] + '[-f] <pool> <file.json>');
process.exit(-1);
}
var json;
var config;
var pool;
-if (!process.argv[2] || !process.argv[3])
+var option;
+var opt_f = false;
+var parser = new getopt.BasicParser('f', process.argv);
+
+while ((option = parser.getopt()) !== undefined && !option.error) {
+ switch (option.option) {
+ case 'f':
+ opt_f = true;
+ break;
+ default:
+ usage();
+ break;
+ }
+}
+
+if (option && option.error)
+ usage();
+
+if (!process.argv[parser.optind()] || !process.argv[parser.optind() + 1])
usage();
-pool = process.argv[2];
-json = fs.readFileSync(process.argv[3], 'utf8');
+pool = process.argv[parser.optind()];
+json = fs.readFileSync(process.argv[parser.optind() + 1], 'utf8');
config = JSON.parse(json);
-zfs.zpool.create(pool, config, function (err) {
+zfs.zpool.create(pool, config, opt_f, function (err) {
if (err) {
fatal('pool creation failed: ' + err);
}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 6af1162

Please sign in to comment.