I recently created a Typescript program that converts various .json file formats. However, I realized that I have hardcoded the file path for reading.
const file = readFileSync('./name_of_file_path.json', 'utf-8'); // fixed file path.
file_obj = JSON.parse(file);
// more code ...
I am interested in turning this program into a CLI tool to allow for more flexible file paths.
Users would simply need to type the following in the Command Prompt:
converter_json [-someFlagOption] ./folder/random_json_file_path.json
Then the program should be able to retrieve the user's .json file path like this:
function func_user_file_path(){
return real_user_json_filepath;
}
var file_path_input: string;
file_path_input = func_user_file_path() //dynamic file path (user input)
const file = file_path_input;
file_obj = JSON.parse(file);
// more code ...
My main query is how can I achieve this functionality?