Configration file template added
This commit is contained in:
parent
decbf01333
commit
cb8fd76e46
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"grafanaUrl": "https://grafana.example.com",
|
||||
"user": "user",
|
||||
"password": "1234"
|
||||
}
|
27
main.js
27
main.js
|
@ -7,8 +7,6 @@ const os = require('os');
|
|||
const fs = require('fs');
|
||||
const getopts = require('getopts');
|
||||
|
||||
const homeDir = os.homedir();
|
||||
const configFile = `${homeDir}/.grafana-find.json`;
|
||||
const error = `[ERROR]: `.bold;
|
||||
|
||||
console.log(
|
||||
|
@ -16,11 +14,6 @@ console.log(
|
|||
`v${packageJson.version}`.cyan.bold
|
||||
);
|
||||
|
||||
if (!fs.existsSync(configFile)) {
|
||||
console.error(`${error}Configuration file not found: ${configFile}\n`.red);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const usage = {
|
||||
description: 'Utility to find strings in dashboards',
|
||||
params: {
|
||||
|
@ -58,10 +51,24 @@ if (opts._.length > 1) {
|
|||
process.exit(1);
|
||||
}
|
||||
|
||||
let config;
|
||||
const configPaths = [
|
||||
os.homedir(),
|
||||
`${__dirname}`
|
||||
];
|
||||
for (const configPath of configPaths) {
|
||||
const configFile = `${configPath}/.grafana-find.json`;
|
||||
if (fs.existsSync(configFile)) {
|
||||
config = require(configFile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!config) {
|
||||
console.error(`${error}Configuration file not found, search paths: .grafana-find.json: ${configPaths.join(':')}\n`.red);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const findAll = opts._[0];
|
||||
|
||||
const config = require(configFile);
|
||||
|
||||
const grafanaUrl = config.grafanaUrl;
|
||||
let user = config.user;
|
||||
let passw = config.password;
|
||||
|
|
Loading…
Reference in New Issue