Skip to content

Commit cb82c3a

Browse files
committed
Add defaul console options, remove empty attr
1 parent 1b2394a commit cb82c3a

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

app.js

100644100755
+13-13
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,19 @@ if (program.folder) {
5252

5353
function actionsToDo() {
5454

55-
if (program.output === 'console') {
55+
if (!program.output || program.output === 'console') {
5656
if (program.type === 'xpaths') {
5757
return function (path) {
58-
console.log(`${path} ${results[path].count} ${program.attributes ? JSON.stringify(results[path].attributes) : ''}`)
58+
let nbOfAttr = program.attributes ? Object.keys(results[path].attributes).length : 0;
59+
console.log(`${path} ${results[path].count} ${nbOfAttr ? JSON.stringify(results[path].attributes) : ''}`)
5960
};
6061
}
6162
//tree
6263
return function (path) {
6364
let elements = path.split('/'),
6465
elementName = elements[elements.length-1];
65-
console.log(`${'│ '.repeat(results[path].level)}├── ${elementName} ${results[path].count} ${program.attributes ? JSON.stringify(results[path].attributes) : ''}`)
66+
let nbOfAttr = program.attributes ? Object.keys(results[path].attributes).length : 0;
67+
console.log(`${'│ '.repeat(results[path].level)}├── ${elementName} ${results[path].count} ${nbOfAttr ? JSON.stringify(results[path].attributes) : ''}`)
6668
};
6769
}
6870
// Write file, no output
@@ -75,29 +77,27 @@ function actionsToDo() {
7577
if (program.type === 'xpaths') {
7678
xpathsFile = writeStream('xpaths', program.output, 'csv');
7779
return function (path) {
78-
xpathsFile.write(`${path};${results[path].count}`)
79-
if(program.attributes){
80-
for(var attr in results[path].attributes){
81-
xpathsFile.write(`;"${attr} => ${results[path].attributes[attr].join('\n')}"`)
82-
}
83-
}
84-
xpathsFile.write('\n');
80+
let nbOfAttr = program.attributes ? Object.keys(results[path].attributes).length : 0;
81+
xpathsFile.write(`${path} ${results[path].count} ${nbOfAttr ? JSON.stringify(results[path].attributes) : ''}\n`)
8582
}
8683
}
8784
if (program.type === 'tree') {
8885
treeFile = writeStream('tree', program.output,'txt');
8986
return function (path) {
90-
treeFile.write(`${'│ '.repeat(results[path].level)}├── ${path} ${results[path].count} ${program.attributes ? JSON.stringify(results[path].attributes) : ''}\n`);
87+
let nbOfAttr = program.attributes ? Object.keys(results[path].attributes).length : 0;
88+
treeFile.write(`${'│ '.repeat(results[path].level)}├── ${path} ${results[path].count} ${nbOfAttr ? JSON.stringify(results[path].attributes) : ''}\n`);
9189
}
9290
}
9391
//both
9492
xpathsFile = writeStream('xpaths', program.output,'csv');
9593
treeFile = writeStream('tree', program.output,'txt');
9694
return function (path) {
97-
xpathsFile.write(`${path} ${results[path].count}\n`)
98-
treeFile.write(`${'│ '.repeat(results[path].level)}├── ${path} ${results[path].count}\n`);
95+
let nbOfAttr = program.attributes ? Object.keys(results[path].attributes).length : 0;
96+
xpathsFile.write(`${path} ${results[path].count} ${nbOfAttr ? JSON.stringify(results[path].attributes) : ''}\n`)
97+
treeFile.write(`${'│ '.repeat(results[path].level)}├── ${path} ${results[path].count} ${nbOfAttr ? JSON.stringify(results[path].attributes) : ''}\n`);
9998
}
10099
}
100+
101101
}
102102

103103
function writeStream(type, output, extension) {

readme.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ xpath-generator --help
4141

4242
-a, --attributes //Will return all attributes & uniques values for all paths
4343

44-
-i, --input <path> //An xml input file
44+
-i, --input <"path"> //An xml input file
4545

46-
-f, --folder <path> //A folder containing xml files
46+
-f, --folder <"path"> //A folder containing xml files
4747

48-
-o, --output <path> //Generate files to specific path, default output is terminal
48+
-o, --output <path/"console"> //Generate files to specific folder, default output is terminal
4949

50-
-t, --type <tree/xpaths/both> Type of format output, can be 'tree' 'xpaths' or 'both' for outputdir, 'tree' 'xpaths' for console
50+
-t, --type <"tree"/"xpaths"/"both"> Type of format output, can be 'tree' 'xpaths' or 'both' for outputdir, 'tree' 'xpaths' for console
5151

5252

5353
## Use xpath-generator as API :

0 commit comments

Comments
 (0)