All pages
Powered by GitBook
1 of 1

Loading...

printTable Command

CommandBox has a helper for printing ASCII Art tables in your custom commands and task runners called print.table(). We've taken this a step further and wrapped the table printer utility in a new command so you can use it from the CLI directly. The printTable command will accept ANY data in as JSON and it will marshal it into a query for you. This means it can be a query, an array of structs, an array or arrays, and more. You can now get quick and easy visualization of any data right from the CLI or in builds.

Parameters

  • data - JSON serialized query, array of structs, or array of arrays to represent in table form

  • includeHeaders - A list of headers to include.

  • headerNames - A list/array of column headers to use instead of the default specifically for array of arrays

  • debug - Only print out the names of the columns and the first row values

When using an array of arrays and not specifying headerNames, the columns will be named col_1, col_2, col_3, etc...

Examples

Terminal Width

If you are running inside a build server, the terminal width will use a default setting, which may be smaller than you wish. Terminal width can be overridden for entire CLI

or for a specific printTable command

or for a specific print.table() call

# array of structs
printTable [{a:1,b:2},{a:3,b:4},{a:5,b:6}]

╔═══╀═══╗
β•‘ a β”‚ b β•‘
╠═══β•ͺ═══╣
β•‘ 1 β”‚ 2 β•‘
β•Ÿβ”€β”€β”€β”Όβ”€β”€β”€β•’
β•‘ 3 β”‚ 4 β•‘
β•Ÿβ”€β”€β”€β”Όβ”€β”€β”€β•’
β•‘ 5 β”‚ 6 β•‘
β•šβ•β•β•β•§β•β•β•β•
# array of arrays
printTable data=[[1,2],[3,4],[5,6]] headerNames=foo,bar

╔═════╀═════╗
β•‘ foo β”‚bar β•‘
╠═════β•ͺ═════╣
β•‘ 1   β”‚2   β•‘
β•Ÿβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β•’
β•‘ 3   β”‚4   β•‘
β•Ÿβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β•’
β•‘ 5   β”‚6   β•‘
β•šβ•β•β•β•β•β•§β•β•β•β•β•β•
# Query object
#extensionlist | printTable name,version

╔═════════════════════════════════════════╀═══════════════════╗
β•‘ name                                 β”‚ version         β•‘
╠═════════════════════════════════════════β•ͺ═══════════════════╣
β•‘ MySQL                                β”‚ 8.0.19          β•‘
β•Ÿβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β•’
β•‘ Microsoft SQL Server                 β”‚ 6.5.4           β•‘
β•Ÿβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β•’
β•‘ PostgreSQL                           β”‚ 9.4.1212        β•‘
β•Ÿβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β•’
β•‘ Ajax Extension                       β”‚ 1.0.0.3         β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•§β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
# JSON list of all servers
server list --json | printTable name,host,port,status

╔══════════════════════════════╀═════════════════════════════╀═══════╀══════════╗
β•‘ name                       β”‚ host                     β”‚ port  β”‚ status  β•‘
╠══════════════════════════════β•ͺ═════════════════════════════β•ͺ═══════β•ͺ══════════╣
β•‘ servicetest                β”‚ 127.0.0.1                β”‚ 54427 β”‚ stopped β•‘
β•Ÿβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β•’
β•‘ servicetest2               β”‚ 127.0.0.1                β”‚ 52919 β”‚ stopped β•‘
β•Ÿβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β•’
β•‘ FRDemos                    β”‚ 127.0.0.1                β”‚ 50458 β”‚ stopped β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•§β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•§β•β•β•β•β•β•β•β•§β•β•β•β•β•β•β•β•β•β•β•
config set terminalWidth=150
#extensionlist | printTable width=150
print.table( data=qry, width=150 )