@vexify-org/yaggs 6.4.0 → 6.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +5 -0
- package/lib/parser.js +40 -0
- package/package.json +1 -1
package/index.js
CHANGED
package/lib/parser.js
CHANGED
|
@@ -786,6 +786,46 @@ complete -c ${this.scriptName} `;
|
|
|
786
786
|
}
|
|
787
787
|
}
|
|
788
788
|
|
|
789
|
+
table(data, options = {}) {
|
|
790
|
+
if (!data || data.length === 0) {
|
|
791
|
+
console.log('No data to display');
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
const headers = Object.keys(data[0]);
|
|
796
|
+
const columnWidths = {};
|
|
797
|
+
|
|
798
|
+
for (const header of headers) {
|
|
799
|
+
const maxLen = Math.max(
|
|
800
|
+
header.length,
|
|
801
|
+
...data.map(row => String(row[header] || '').length)
|
|
802
|
+
);
|
|
803
|
+
columnWidths[header] = maxLen + 2;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
const border = '─'.repeat(Object.values(columnWidths).reduce((a, b) => a + b, 0) + headers.length + 1);
|
|
807
|
+
|
|
808
|
+
console.log('\u001b[36m' + border + '\u001b[0m');
|
|
809
|
+
|
|
810
|
+
let headerRow = '│ ';
|
|
811
|
+
for (const header of headers) {
|
|
812
|
+
headerRow += header.padEnd(columnWidths[header]) + '│ ';
|
|
813
|
+
}
|
|
814
|
+
console.log('\u001b[35m' + headerRow + '\u001b[0m');
|
|
815
|
+
|
|
816
|
+
console.log('\u001b[36m' + border + '\u001b[0m');
|
|
817
|
+
|
|
818
|
+
for (const row of data) {
|
|
819
|
+
let rowStr = '│ ';
|
|
820
|
+
for (const header of headers) {
|
|
821
|
+
rowStr += String(row[header] || '').padEnd(columnWidths[header]) + '│ ';
|
|
822
|
+
}
|
|
823
|
+
console.log(rowStr);
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
console.log('\u001b[36m' + border + '\u001b[0m');
|
|
827
|
+
}
|
|
828
|
+
|
|
789
829
|
getHelp() {
|
|
790
830
|
let help = `\u001b[36m${this.scriptName}\u001b[0m`;
|
|
791
831
|
|