@wavyx/pdcli 0.1.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/CHANGELOG.md +24 -0
- package/LICENSE +21 -0
- package/README.md +32 -0
- package/bin/run.js +20 -0
- package/oclif.manifest.json +2308 -0
- package/package.json +128 -0
- package/src/base-command.js +99 -0
- package/src/commands/activity/get.js +41 -0
- package/src/commands/activity/list.js +61 -0
- package/src/commands/api.js +60 -0
- package/src/commands/auth/login.js +79 -0
- package/src/commands/auth/logout.js +24 -0
- package/src/commands/auth/status.js +62 -0
- package/src/commands/config/get.js +30 -0
- package/src/commands/config/list.js +25 -0
- package/src/commands/config/set.js +29 -0
- package/src/commands/deal/get.js +43 -0
- package/src/commands/deal/list.js +62 -0
- package/src/commands/doctor.js +123 -0
- package/src/commands/field/get.js +58 -0
- package/src/commands/field/list.js +41 -0
- package/src/commands/org/get.js +41 -0
- package/src/commands/org/list.js +40 -0
- package/src/commands/person/get.js +41 -0
- package/src/commands/person/list.js +49 -0
- package/src/commands/profile/current.js +16 -0
- package/src/commands/profile/list.js +36 -0
- package/src/commands/profile/use.js +26 -0
- package/src/commands/search.js +67 -0
- package/src/commands/user/me.js +26 -0
- package/src/commands/version.js +24 -0
- package/src/hooks/command-not-found.js +15 -0
- package/src/hooks/init.js +7 -0
- package/src/hooks/prerun.js +7 -0
- package/src/lib/auth.js +95 -0
- package/src/lib/body.js +26 -0
- package/src/lib/client.js +184 -0
- package/src/lib/config.js +71 -0
- package/src/lib/errors.js +118 -0
- package/src/lib/fields.js +120 -0
- package/src/lib/keychain.js +69 -0
- package/src/lib/output/index.js +22 -0
- package/src/lib/output/json.js +7 -0
- package/src/lib/output/record.js +27 -0
- package/src/lib/output/table.js +40 -0
- package/src/lib/pagination.js +14 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { formatTable } from './table.js'
|
|
2
|
+
import { formatJson } from './json.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {object | object[]} data
|
|
6
|
+
* @param {Record<string, import('./table.js').Column>} columns
|
|
7
|
+
* @param {'table' | 'json'} format
|
|
8
|
+
* @param {import('@oclif/core').Command} cmd
|
|
9
|
+
*/
|
|
10
|
+
export function formatOutput(data, columns, format, cmd) {
|
|
11
|
+
const items = Array.isArray(data) ? data : [data]
|
|
12
|
+
|
|
13
|
+
switch (format) {
|
|
14
|
+
case 'json':
|
|
15
|
+
cmd.log(formatJson(data))
|
|
16
|
+
break
|
|
17
|
+
case 'table':
|
|
18
|
+
default:
|
|
19
|
+
cmd.log(formatTable(items, columns))
|
|
20
|
+
break
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flatten a single record into [{ field, value }] rows for a transposed
|
|
3
|
+
* key/value table view. custom_fields entries are hoisted to the top level
|
|
4
|
+
* (callers resolve hash keys to names first via fields.makeResolver).
|
|
5
|
+
* @param {object} record
|
|
6
|
+
* @returns {{ field: string, value: string }[]}
|
|
7
|
+
*/
|
|
8
|
+
export function flattenRecord(record) {
|
|
9
|
+
const rows = []
|
|
10
|
+
for (const [field, value] of Object.entries(record)) {
|
|
11
|
+
if (field === 'custom_fields' && value && typeof value === 'object') {
|
|
12
|
+
for (const [name, customValue] of Object.entries(value)) {
|
|
13
|
+
rows.push({ field: name, value: renderValue(customValue) })
|
|
14
|
+
}
|
|
15
|
+
continue
|
|
16
|
+
}
|
|
17
|
+
rows.push({ field, value: renderValue(value) })
|
|
18
|
+
}
|
|
19
|
+
return rows
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function renderValue(value) {
|
|
23
|
+
if (value == null) return ''
|
|
24
|
+
if (Array.isArray(value)) return value.map(renderValue).join(', ')
|
|
25
|
+
if (typeof value === 'object') return JSON.stringify(value)
|
|
26
|
+
return String(value)
|
|
27
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import Table from 'cli-table3'
|
|
2
|
+
import chalk from 'chalk'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {object} Column
|
|
6
|
+
* @property {string} header
|
|
7
|
+
* @property {(row: object) => string} [get]
|
|
8
|
+
* @property {string} [key]
|
|
9
|
+
* @property {number} [minWidth]
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {object[]} data
|
|
14
|
+
* @param {Record<string, Column>} columns
|
|
15
|
+
* @returns {string}
|
|
16
|
+
*/
|
|
17
|
+
export function formatTable(data, columns) {
|
|
18
|
+
if (!data || data.length === 0) {
|
|
19
|
+
return chalk.dim('No results found.')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const entries = Object.entries(columns)
|
|
23
|
+
|
|
24
|
+
const table = new Table({
|
|
25
|
+
head: entries.map(([, col]) => chalk.bold(col.header)),
|
|
26
|
+
style: { head: [], border: [] },
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
for (const row of data) {
|
|
30
|
+
table.push(
|
|
31
|
+
entries.map(([fieldKey, col]) => {
|
|
32
|
+
if (col.get) return String(col.get(row) ?? '')
|
|
33
|
+
const value = row[col.key ?? fieldKey]
|
|
34
|
+
return value != null ? String(value) : ''
|
|
35
|
+
}),
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return table.toString()
|
|
40
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @template T
|
|
3
|
+
* @param {AsyncGenerator<T>} generator
|
|
4
|
+
* @param {number} [limit]
|
|
5
|
+
* @returns {Promise<T[]>}
|
|
6
|
+
*/
|
|
7
|
+
export async function collectPages(generator, limit) {
|
|
8
|
+
const results = []
|
|
9
|
+
for await (const item of generator) {
|
|
10
|
+
results.push(item)
|
|
11
|
+
if (limit && results.length >= limit) break
|
|
12
|
+
}
|
|
13
|
+
return results
|
|
14
|
+
}
|