-
Notifications
You must be signed in to change notification settings - Fork 0
/
sh.js
executable file
·134 lines (131 loc) · 3.34 KB
/
sh.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env node
'use strict';
const {
initHandler
} = require('./initHandler')
const {
channelHandler
} = require('./channelHandler')
const {
testHandler
} = require('./testHandler')
const {
listHandler
} = require('./listHandler')
const {
postHandler
} = require('./postHandler')
const {
cancelHandler
} = require('./cancelHandler')
require('yargs')
.command({
command: 'config',
desc: 'display configure',
builder: (yargs) => yargs,
handler: async (argv) => {
const {
readConfig,
} = require('./config');
const config = await readConfig();
console.log(config)
}
})
.command({
command: 'init',
aliases: ['i'],
desc: 'configure',
builder: (yargs) => yargs,
handler: initHandler,
})
.command({
command: 'channel',
aliases: ['c'],
desc: 'change channel',
builder: (yargs) => yargs,
handler: channelHandler,
})
.command({
command: 'test',
aliases: ['t'],
desc: 'connection test',
builder: (yargs) => yargs,
handler: testHandler,
})
.command({
command: 'list',
aliases: ['l'],
desc: 'show timeline',
builder: (yargs) => yargs
.option('channel', {
alias: 'c',
describe: 'specify target channel',
type: 'string'
})
.group('channel', 'Flags:')
.example('$0 list', 'show CURRENT timeline')
.example('$0 list --channel hogehoge', 'show timeline of channel hogehoge'),
handler: listHandler
})
.command({
command: 'draft',
aliases: ['d'],
desc: false,
builder: (yargs) => yargs,
handler: (argv) => {
console.log('$(idbt draft) executed with', argv);
}
})
.command({
command: 'post',
aliases: ['p'],
desc: 'create new post',
builder: (yargs) => yargs
.option('channel', {
alias: 'c',
describe: 'specify target channel',
type: 'string'
})
.option('yes', {
alias: 'y',
describe: 'mode "yesman". no longer confirm before posting.',
type: 'boolean'
})
.option('file', {
alias: 'f',
describe: 'read from file',
default: '~/.idbt/draft.md',
type: 'string'
})
.option('emacs', {
alias: 'e',
describe: 'open with emacs',
type: 'boolean'
})
.group(['channel', 'yes', 'file'], 'Flags:')
.example('$0 post "hello!"', 'post "hello!" to CURRENT channel? (y/n)')
.example('$0 post --yes "hello!"', 'post "hello!" to CURRENT channel')
.example('$0 post -y --channel hogehoge "hello!"', 'post "hello!" to channel hogehoge')
.example('$0 post -y --file ./draft.txt', 'post $(cat ./draft.txt) to CURRENT channel'),
handler: postHandler,
})
.command({
command: 'cancel',
aliases: ['undo'],
desc: 'delete latest your post',
builder: (yargs) => yargs
.option('yes', {
alias: 'y',
describe: 'mode "yesman". no longer confirm before deletion.',
type: 'boolean'
})
.group(['yes'], 'Flags:')
.example('$0 cancel', 'delete your last post start with "****"')
.example('$0 cancel --yes', 'delete your last post start with "****"? (y/n)'),
handler: cancelHandler,
})
.usage('$0 [init|test|list|post|cancel] [--flags]')
.help('help')
.epilogue('need more help? see document on github.')
.version('v0.1')
.argv;