json2bash
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -62,3 +62,3 @@ #!/usr/bin/env node | ||
`------------------------- | ||
json2bash | ||
jsonarr2csv | ||
By Guillaume Descoteaux-Isabelle, 2022 | ||
@@ -75,5 +75,5 @@ ----------------------------------------`; | ||
yargs(hideBin(process.argv)) | ||
.scriptName("json2bash") | ||
.scriptName("jsonarr2csv") | ||
// .usage(appStartMessage + helpExample) | ||
.usage('$0 <jsonFile> [objCsvArray] [fileout]', "by " + author + ", 2022", (yargs) => { | ||
.usage('$0 <jsonFile> [idxname] [fileout]', "by " + author + ", 2022", (yargs) => { | ||
yargs.positional('jsonFile', { | ||
@@ -84,6 +84,6 @@ describe: 'json File input (optional when receiving using pipe)', | ||
}), | ||
yargs.positional('objCsvArray', { | ||
describe: 'object to extract in the file as csv', | ||
yargs.positional('idxname', { | ||
describe: 'index name in the file as csv', | ||
type: 'string', | ||
default: '.' | ||
default: 'idx' | ||
}), | ||
@@ -95,56 +95,8 @@ yargs.positional('fileout', { | ||
}) | ||
.example("json2bash sample.json --tolower", "simple output") | ||
.example("json2bash sample.json . outfile.env --tolower", "simple output to file (the dot signify we keep top level element)") | ||
.example("json2bash samplelevel.json \"result\" --tolower", "extract the tag result") | ||
.example("json2bash samplelevel.json \"result\" --tolower --oa --prefix", "extract the tag result only (no top level prop will output)") | ||
.example("json2bash samplelevel.json \"result,stuff\" --tolower --prefix", "Extract the result and stuff object to lowercase and add their object name as prefix to variable") | ||
.example("json2bash samplesublevelon \"result\" -p;./json2bash samplesublevelon \"result\" -p -j |./json2bash \"meta\" -p -l -o", "Complex pipe extracting an object then one of its subobject pipe back to be extracted") | ||
.example("json2bash samplesublevel.json o.txt --all ", "export all sublevel to a file o.txt") | ||
.example("json2bash samplesublevel.json o.txt --all --u", "export all sublevel in upper case to a file o.txt") | ||
.epilogue('for more information, find our manual at https://github.com/GuillaumeIsabelle/json2bashenv#readme') | ||
.example("jsonarr2csv sample.json", "simple output to console") | ||
.example("jsonarr2csv sample.json > outfile.csv", "simple output to file ") | ||
.example("jsonarr2csv sample.json myindex > outfile.csv", "simple output to file renaming idx") | ||
.epilogue('for more information, find our manual at https://github.com/GuillaumeIsabelle/jsonarr2csvenv#readme') | ||
.help() | ||
}) | ||
.option('var2Lower', { | ||
default: false, | ||
type: 'boolean', | ||
alias: ['tolower', 'tl', 'toLowerCase', 'lc','l'], | ||
description: 'Changes env name to lowercase' | ||
}) | ||
.option('var2Cap', { | ||
default: false, | ||
type: 'boolean', | ||
alias: ['tocap', 'tc', 'toUpperCase', 'uc','u'], | ||
description: 'Changes env name to uppercase' | ||
}) | ||
.option('prefix', { | ||
alias: ['p', 'px'], | ||
default: false, | ||
type: 'boolean', | ||
description: 'prefix selected object output to var' | ||
}) | ||
.option('all', { | ||
alias: ['a'], | ||
default: false, | ||
type: 'boolean', | ||
description: 'output all sub object' | ||
}) | ||
.option('exportprefix', { | ||
alias: ['x','export'], | ||
default: false, | ||
type: 'boolean', | ||
description: 'output with export before' | ||
}) | ||
.option('jsonx', { | ||
alias: ['j','jx'], | ||
default: false, | ||
type: 'boolean', | ||
description: 'output sub object as json' | ||
}) | ||
.option('onlyselected', { | ||
alias: ['o', 'os', 'oa', 'os', 'only'], | ||
default: false, | ||
type: 'boolean', | ||
description: 'select only value of obj array as arg 2' | ||
}) | ||
}) | ||
.option('verbose', { | ||
@@ -167,3 +119,3 @@ alias: 'v', | ||
var { var2Lower,var2Cap, prefix, onlyselected, fileout, debug, verbose,all,jsonx,exportprefix } = argv; | ||
var { idxname, fileout, debug, verbose } = argv; | ||
@@ -181,3 +133,3 @@ | ||
config = new Object() | ||
var { json2bashtofile, json2bashtofilepath } = tst.parsed; | ||
var { jsonarr2csvtofile, jsonarr2csvtofilepath } = tst.parsed; | ||
} | ||
@@ -261,2 +213,4 @@ } catch (error) { } | ||
var c = 0; | ||
ls += key + ","; | ||
for (const [key2, value2] of Object.entries(value)) { | ||
@@ -282,3 +236,3 @@ if (key == 1) { | ||
} | ||
return h + "\n" + ls; | ||
return idxname + ","+ h + "\n" + ls; | ||
} | ||
@@ -285,0 +239,0 @@ |
{ | ||
"name": "json2bash", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "A CLI to export json object to bash env. Also json array to csv", | ||
@@ -5,0 +5,0 @@ "main": "json2bash.js", |
Sorry, the diff of this file is not supported yet
112356
3267