Configration file template added

This commit is contained in:
Guillermo Bonet 2022-06-20 20:07:14 +02:00
parent decbf01333
commit cb8fd76e46
2 changed files with 22 additions and 10 deletions

5
.grafana-find.json Normal file
View File

@ -0,0 +1,5 @@
{
"grafanaUrl": "https://grafana.example.com",
"user": "user",
"password": "1234"
}

27
main.js
View File

@ -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;