Skip to content

Commit d0e313c

Browse files
committed
refactor: reorganize
1 parent c3f353a commit d0e313c

File tree

15 files changed

+41
-41
lines changed

15 files changed

+41
-41
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"editor.formatOnSave": true
2+
"editor.formatOnSave": true,
3+
"cSpell.words": ["jike"]
34
}

src/command/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { program } from 'commander'
2+
import { versionNumber } from '../constants'
3+
import { version } from './version'
4+
import { user } from './user'
5+
import { post } from './post'
6+
import { msg } from './msg'
7+
8+
export function run() {
9+
program
10+
.name('jike')
11+
.option('-u, --user <users...>', 'specify users')
12+
.option('-r, --raw', 'output raw data', false)
13+
.option('-P, --pretty', 'format raw data', false)
14+
.addCommand(user)
15+
.addCommand(post)
16+
.addCommand(msg)
17+
.addCommand(version)
18+
.version(versionNumber)
19+
.parse()
20+
}

src/modules/msg.ts renamed to src/command/msg.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { logger } from '@poppinss/cliui'
22
import { createCommand } from 'commander'
33
import { JikeClient, limit } from 'jike-sdk/node'
44
import { format } from 'date-fns'
5-
import { displayImage } from '../utils/terminal'
5+
import { displayImage, printRaw } from '../utils/terminal'
66
import { displayUser, filterUsers } from '../utils/user'
77
import type { Spinner } from '@poppinss/cliui/build/src/Logger/Spinner'
88
import type { Entity } from 'jike-sdk/node'
@@ -11,16 +11,11 @@ interface NotificationOptions {
1111
avatar?: boolean
1212
image?: boolean
1313
count?: number
14-
// TODO move to global options
15-
raw?: number
16-
pretty?: number
1714
}
1815

1916
export const msg = createCommand('msg')
2017
.description('display notifications')
2118
.aliases(['message', 'notification'])
22-
.option('-r, --raw', 'output raw data', false)
23-
.option('-p, --pretty', 'format raw data', false)
2419
.option('--no-avatar', 'do not show avatar')
2520
.option('--no-image', 'do not show image')
2621
.option('-c, --count <count>', 'notification max count', '30')
@@ -51,12 +46,7 @@ const showNotifications = async (opts: NotificationOptions) => {
5146

5247
logger.success('Loading notifications done!')
5348

54-
if (opts.raw) {
55-
process.stdout.write(
56-
`${JSON.stringify(notifications, null, opts.pretty ? 2 : 0)}\n`
57-
)
58-
return
59-
}
49+
printRaw(notifications)
6050

6151
{
6252
const divider = logger.colors.gray('─'.repeat(process.stdout.columns || 30))
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/modules/user/profile.ts renamed to src/command/user/profile.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,21 @@ import { logger, sticker, table } from '@poppinss/cliui'
44
import { format } from 'date-fns'
55
import { JikeClient } from 'jike-sdk/node'
66
import { filterUsers } from '../../utils/user'
7-
import { displayImage } from '../../utils/terminal'
7+
import { displayImage, printRaw as printIfRaw } from '../../utils/terminal'
88
import { PROFILE_URL } from '../../constants'
99
import type { ApiResponses } from 'jike-sdk/node'
1010

1111
const { colors } = logger
1212

1313
export interface ProfileOptions {
1414
username?: string
15-
raw?: boolean
16-
pretty?: boolean
1715
table?: boolean
1816
}
1917

2018
export const profile = createCommand('profile')
2119
.alias('p')
2220
.argument('[username]', 'the username of user')
2321
.description('query user profile')
24-
.option('-r, --raw', 'output raw data')
25-
.option('-p, --pretty', 'pretty raw data')
2622
.option('-t, --table', 'display data in table')
2723
.action((username: string) => {
2824
const opts = profile.opts<Omit<ProfileOptions, 'username'>>()
@@ -31,8 +27,6 @@ export const profile = createCommand('profile')
3127

3228
export const queryProfile = async ({
3329
username,
34-
raw,
35-
pretty,
3630
table: isTable,
3731
}: ProfileOptions) => {
3832
const [user] = filterUsers()
@@ -45,11 +39,7 @@ export const queryProfile = async ({
4539
result = await client.getSelf().queryProfile()
4640
}
4741

48-
if (raw) {
49-
process.stdout.write(JSON.stringify(result, null, pretty ? 2 : 0))
50-
return
51-
}
52-
42+
printIfRaw(result)
5343
;(await displayImage(result.user.avatarImage.middlePicUrl)).render()
5444

5545
const createdAt = new Date(result.user.createdAt)

0 commit comments

Comments
 (0)