freechat/freechat-client/src/config.js
shockrah e37d51f549 Making the navbar more responsive to screen changes
! Bootstrap doesn't behave so dropdowns are borked but they'r theoretically there

LMAO at this example config update btw its gonna keep changing so I'm not updating its patch notes from here out until its a proper looking example
2021-01-01 20:04:11 -08:00

42 lines
1.1 KiB
JavaScript

const { ArgumentParser } = require('argparse')
const fs = require('fs')
/**
* @param {ArgumentParset} parser
* @returns {Config} { path }
*/
function get_config(parser) {
const a = parser.parse_args()
const defaultcfg = `${process.env.HOME || process.env.USERPROFILE}/.config/freechat/config.json`
// we'll just assume that the config is there as per the installation process
const path = (a['config']) ? a['config'] : defaultcfg
const file_contents = fs.readFileSync(path)
const file_json = JSON.parse(file_contents)
// now we'll just blindly construct the config object from here on out
let ret = { path: path }
for(const key of Object.keys(file_json)) {
if(key == 'path') { continue } // don't overwrite the old path
else {
ret[key] = file_json[key]
}
}
return ret
}
/**
* Loads the parse with the various arguments that the program takes
* @param {ArgumentParser} parser
*/
function load_parser() {
const parser = new ArgumentParser({
description: 'Freechat Electron Client'
})
parser.add_argument('-c', '--config', {help: 'Specify config path'})
return parser
}
exports.load_parser = load_parser
exports.get_config = get_config