adamocomp/data-tool.js

192 lines
3.4 KiB
JavaScript
Raw Normal View History

2020-05-21 12:08:44 +00:00
#!/usr/bin/node
const Parser = require('./parser.js');
var parser = new Parser();
const yargs = require('yargs')
.scriptName("node data_tool.js")
.usage('$0 <cmd> [options] [args]')
.command(
'valid_deal [query]',
'Returns with exit code 0 if [query] matches'
+ ' at least one deal, otherwise 2.',
(yargs) => {
yargs.positional('query', {
type: 'string',
default: '',
describe: 'Key path.'
})
},
function(argv) {
parser.test
.valid_deal(argv.query)
.then(function(result) {
if (result) {
process.exit(0);
}
process.exit(2);
})
}
)
.command(
'valid_cluster [query]',
'Returns with exit code 0 if [query] matches'
+ ' at least one cluster, otherwise 2.',
(yargs) => {
yargs.positional('query', {
type: 'string',
default: '',
describe: 'Key path.'
})
},
function(argv) {
parser.test
.valid_cluster(argv.query)
.then(function(result) {
if (result) {
process.exit(0);
}
process.exit(2);
})
}
)
.command(
'valid_host [query]',
'Returns with exit code 0 if [query] matches'
+ ' at least one host, otherwise 2.',
(yargs) => {
yargs.positional('query', {
type: 'string',
default: '',
describe: 'Key path.'
})
},
function(argv) {
parser.test
.valid_host(argv.query)
.then(function(result) {
if (result) {
process.exit(0);
}
process.exit(2);
})
}
)
.command(
'get [query]',
'Prints an array of '.concat(
' paths matched by [query], or returns [].'
),
(yargs) => {
yargs.positional('query', {
type: 'string',
default: '',
describe: 'The key path to a datanode.'
})
},
function(argv) {
parser.get
.data(argv.query)
.then(function(arr) {
console.log(JSON.stringify(arr));
})
}
)
.command(
'root [query]',
'Returns json array of arrays of keys in order '.concat(
'locating query matches'
),
(yargs) => {
yargs.positional('query', {
type: 'string',
default: '',
describe: 'The key path to a datanode.'
})
},
function(argv) {
parser.get
.root(argv.query)
.then(function(arr) {
console.log(JSON.stringify(arr));
})
}
)
.command(
'path [query]',
'Returns array of paths under NAAS_HOME'
+ ' for each matching deal.',
(yargs) => {
yargs.positional('query', {
type: 'string',
default: '',
describe: 'The key path to a datanode.'
})
},
function(argv) {
parser.get
.path(argv.query)
.then(function(arr) {
console.log(JSON.stringify(arr));
})
}
)
.command(
'deals',
'Returns list of deals.',
function(argv) {
parser.get
.deals()
.then(function(arr) {
console.log(JSON.stringify(arr));
})
}
)
.command(
'hosts [query]',
'Returns list of hosts.',
(yargs) => {
yargs.positional('query', {
type: 'string',
default: '',
describe: 'The key path to a datanode.'
})
},
function(argv) {
parser.get
.host_list(argv.query)
.then(function(arr) {
console.log(JSON.stringify(arr));
})
}
)
.option(
'debug',
{
alias: 'd',
description: 'Print debug output (very verbose!)',
type: 'boolean',
global: true,
}
)
.option(
'path',
{
alias: 'p',
description: 'Path to data file.',
type: 'string',
global: true,
default: "/etc/adamocomp/data.json"
}
)
.help()
.argv;
if (yargs.path) {
parser.params.path = yargs.path;
}
if (yargs.debug) {
parser.params.debug_mode = yargs.debug;
}