Skip to content

Commit 172e4e4

Browse files
committed
refactor: change username option to argument
1 parent 8ebf5bd commit 172e4e4

File tree

4 files changed

+43
-9
lines changed

4 files changed

+43
-9
lines changed

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,30 @@
22

33
[![Unit Test](https://github.com/open-jike/jike-cli/actions/workflows/unit-test.yml/badge.svg)](https://github.com/open-jike/jike-cli/actions/workflows/unit-test.yml)
44

5-
## Install
5+
## Installation
66

77
```bash
8-
npm i jike-cli
8+
$ npm i -g jike-cli
99
```
1010

11+
## Usage
12+
13+
```bash
14+
$ jike-cli --help
15+
```
16+
17+
### User
18+
19+
```bash
20+
$ jike-cli user login # 登录
21+
$ jike-cli user logout # 退出
22+
$ jike-cli user renew # 刷新 token
23+
$ jike-cli user profile # 查看用户主页
24+
$ jike-cli user view # 在浏览器中打开网页版
25+
```
26+
27+
For more details, please use `help` command.
28+
1129
## License
1230

1331
[AGPL-3.0](./LICENSE) License © 2022-PRESENT [三咲智子](https://github.com/sxzz)

src/modules/user/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,18 @@ import { renew } from './renew'
77
import { view } from './view'
88

99
export const user = createCommand('user')
10-
.description('manager users')
10+
.description('user-related operations')
11+
.addHelpText(
12+
'after',
13+
`
14+
15+
Example call:
16+
$ jike-cli user login
17+
$ jike-cli user profile 82D23B32-CF36-4C59-AD6F-D05E3552CBF3
18+
$ jike-cli user renew
19+
$ jike-cli user view 82D23B32-CF36-4C59-AD6F-D05E3552CBF3
20+
`
21+
)
1122
.usage('<command> [flags]')
1223
.addCommand(renew)
1324
.addCommand(login)

src/modules/user/profile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface ProfileOptions {
1717
}
1818

1919
export const profile = createCommand('profile')
20-
.argument('[username]')
20+
.argument('[username]', 'the username of user')
2121
.description('query user profile')
2222
.option('-r, --raw', 'output raw data')
2323
.option('-p, --pretty', 'pretty raw data')

src/modules/user/view.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@ import { createCommand } from 'commander'
33
import open from 'open'
44
import { createClient, filterUsers } from '../../utils/user'
55

6+
interface ViewOptions {
7+
username: string
8+
mobile: boolean
9+
}
10+
611
export const view = createCommand('view')
7-
.description('query user view')
8-
.option('-U, --username <username>', 'the username of user')
12+
.argument('[username]', 'the username of user')
13+
.description('open user profile in browser')
914
.option('-m, --mobile', 'view page for mobile phone')
10-
.action(() => viewUser())
15+
.action((username?: string) => viewUser(username))
1116

12-
export const viewUser = async () => {
13-
let { username, mobile } = view.opts<{ username: string; mobile: boolean }>()
17+
export const viewUser = async (username?: string) => {
18+
const { mobile } = view.opts<Omit<ViewOptions, 'username'>>()
1419
if (!username) {
1520
const [user] = filterUsers()
1621
const client = createClient(user)

0 commit comments

Comments
 (0)