Skip to content

Commit 09096d7

Browse files
committed
feat(jike-client): add user info
1 parent 43721d7 commit 09096d7

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/command/user/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createCommand } from 'commander'
2+
import { info } from './info'
23
import { list } from './list'
34
import { login } from './login'
45
import { logout } from './logout'
@@ -17,12 +18,14 @@ Example call:
1718
$ jike-cli user profile 82D23B32-CF36-4C59-AD6F-D05E3552CBF3
1819
$ jike-cli user renew
1920
$ jike-cli user view 82D23B32-CF36-4C59-AD6F-D05E3552CBF3
21+
$ jike-cli user info
2022
`
2123
)
2224
.usage('<command> [flags]')
2325
.addCommand(renew)
2426
.addCommand(login)
2527
.addCommand(logout)
2628
.addCommand(list)
29+
.addCommand(info)
2730
.addCommand(profile)
2831
.addCommand(view)

src/command/user/info.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { table } from '@poppinss/cliui'
2+
import { createCommand } from 'commander'
3+
import { printIfRaw } from '../../utils/terminal'
4+
import { filterUsers } from '../../utils/user'
5+
6+
export const info = createCommand('info')
7+
.alias('i')
8+
.description('print user info')
9+
.action(() => userInfo())
10+
11+
export const userInfo = () => {
12+
const [user] = filterUsers()
13+
printIfRaw(user)
14+
15+
const breakLine = (str: string, width = 68) =>
16+
Array.from(str.matchAll(new RegExp(`.{1,${width}}`, 'g')))
17+
.map(([match]) => match)
18+
.join('\n')
19+
20+
const rows = [
21+
['Alias', user.alias],
22+
['Username', user.username],
23+
['Nickname', user.screenName],
24+
['Endpoint', `${user.endpointUrl} (ID: ${user.endpointId})`],
25+
['Bundle ID', user.bundleId],
26+
['APP Version', user.appVersion],
27+
['Build Number', user.buildNo],
28+
['Device ID', user.deviceId],
29+
['IDFV', user.idfv],
30+
['User Agent', user.userAgent],
31+
['Access Token', user.accessToken],
32+
['Refresh Token', user.refreshToken],
33+
]
34+
35+
const t = table().columnWidths([20, 70])
36+
rows.forEach((row) =>
37+
t.row([{ content: `${row[0]}:`, hAlign: 'right' }, breakLine(row[1])])
38+
)
39+
t.render()
40+
}

0 commit comments

Comments
 (0)