forked from likun7981/hlink
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.ts
executable file
·153 lines (144 loc) · 2.93 KB
/
cli.ts
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env node
import chalk from 'chalk'
import meow from 'meow'
import fs from 'fs-extra'
import { restore, backup } from './bins/qnap.js'
import doctor from './bins/doctor.js'
import prune from './bins/prune/index.js'
import hlink from './bins/main/index.js'
import { log } from './utils.js'
import updateNotifier from 'update-notifier'
import path from 'path'
import { fileURLToPath } from 'url'
const pkg = fs.readJSONSync(
path.resolve(fileURLToPath(import.meta.url), '../../package.json')
)
const notifier = updateNotifier({
pkg,
})
notifier.notify({
isGlobal: true,
message:
'有版本可更新 ' +
chalk.dim('{currentVersion}') +
chalk.reset(' → ') +
chalk.green('{latestVersion}') +
' \n使用命令 ' +
chalk.cyan('{updateCommand}') +
' 进行更新,更新日志:' +
'\nhttps://github.com/likun7981/hlink/releases'
})
const cli = meow({
autoHelp: false,
booleanDefault: undefined,
importMeta: import.meta,
flags: {
saveMode: {
type: 'number',
alias: 's'
},
includeExtname: {
type: 'string',
default: '',
alias: 'i'
},
excludeExtname: {
type: 'string',
default: '',
alias: 'e'
},
openCache: {
type: 'boolean',
alias: 'o'
},
mkdirIfSingle: {
type: 'boolean',
alias: 'm'
},
del: {
type: 'boolean',
alias: 'd'
},
generateConfig: {
type: 'string',
alias: 'g'
},
removeConfig: {
type: 'boolean',
alias: 'r'
},
configPath: {
type: 'string',
alias: 'c'
},
pruneDir: {
type: 'boolean',
alias: 'p'
},
withoutConfirm: {
type: 'boolean',
alias: 'w',
default: false
},
reverse: {
type: 'boolean',
alias: 'r',
default: false
}
}
})
const { help, del, ...flags } = cli.flags as IHlink.Flags
const [_command, ...inputs] = cli.input
function logDeprecatedRm() {
log.info(`${chalk.gray('rm')} 命令彻底废除,使用体感特别差,没有存在的意义`)
log.info(
`如果你只是简单想删除硬链,请使用系统自带的 rm 命令,用法可以参考${chalk.cyan(
'https://www.linuxcool.com/rm'
)}`
)
log.info(
`如果你只是在移除源文件后,检测多余的硬链,可以使用 ${chalk.cyan(
'hlink prune'
)} 来进行`
)
}
/**
* @deprecated
*/
if (del) {
logDeprecatedRm
process.exit(0)
}
switch (_command) {
case 'backup':
backup(inputs[0])
break
case 'restore':
restore(inputs[0])
break
case 'doctor':
doctor()
break
case 'remove':
case 'rm':
logDeprecatedRm()
break
case 'prune':
prune(inputs[0], inputs[1], {
help,
...flags
})
break
default:
hlink(cli.input, {
...flags,
help
})
}
process.on('SIGINT', () => {
if (global.printOnExit) {
console.log()
global.printOnExit()
}
process.exit(0)
})