Update man to add the manual guide
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
async function run(ctx, argv) {
|
||||
let del = false
|
||||
const sets = []
|
||||
for (let i = 1; i < argv.length; i++) {
|
||||
if (argv[i] === '-d' || argv[i] === '--delete') del = true
|
||||
else if (argv[i] !== '--') sets.push(argv[i])
|
||||
}
|
||||
if (!sets.length || (!del && sets.length < 2)) {
|
||||
ctx.console.error('usage: tr [-d] SET1 [SET2]')
|
||||
ctx.exitCode = 1
|
||||
return
|
||||
}
|
||||
const s = bareStdin(ctx)
|
||||
if (del) {
|
||||
const kill = new Set(sets[0].split(''))
|
||||
let o = ''
|
||||
for (const ch of s) if (!kill.has(ch)) o += ch
|
||||
ctx.console.log(o)
|
||||
return
|
||||
}
|
||||
const from = sets[0]
|
||||
const to = sets[1]
|
||||
const map = Object.create(null)
|
||||
const n = Math.max(from.length, to.length)
|
||||
for (let i = 0; i < n; i++) {
|
||||
const fc = from[i] || from[from.length - 1]
|
||||
const tc = to[i] != null ? to[i] : to[to.length - 1] || ''
|
||||
map[fc] = tc
|
||||
}
|
||||
let o = ''
|
||||
for (const ch of s) o += map[ch] != null ? map[ch] : ch
|
||||
ctx.console.log(o)
|
||||
}
|
||||
Reference in New Issue
Block a user