-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathindex.ts
More file actions
executable file
·63 lines (57 loc) · 1.79 KB
/
index.ts
File metadata and controls
executable file
·63 lines (57 loc) · 1.79 KB
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
#!/usr/bin/env node
import { Command, CommanderError } from '@commander-js/extra-typings'
import { prettifyError, ZodError } from 'zod'
import { analyze } from './commands/analyze.ts'
import { attach } from './commands/attach.ts'
import { annotation } from './commands/annotation.ts'
import { script } from './commands/script.ts'
import { fetch } from './commands/fetch.ts'
import { frame } from './commands/frame.ts'
import { open } from './commands/open.ts'
import { id } from './commands/id.ts'
import { iiif } from './commands/iiif.ts'
import { transform } from './commands/transform.ts'
const fixedWidth = process.env.NODE_ENV === 'test'
const program = new Command()
.name('allmaps')
.exitOverride()
.addCommand(annotation())
.addCommand(analyze())
.addCommand(attach())
.addCommand(fetch())
.addCommand(frame())
.addCommand(iiif())
.addCommand(id())
.addCommand(open())
.addCommand(script())
.addCommand(transform())
.configureHelp({
helpWidth: fixedWidth ? 80 : undefined
})
.addHelpText('beforeAll', `Allmaps CLI\n`)
.addHelpText(
'afterAll',
`\nFor more details about Allmaps, see https://allmaps.org`
)
async function parse() {
try {
await program.parseAsync(process.argv)
} catch (err: unknown) {
if (err instanceof CommanderError) {
// TODO: I probably don't completely understand how errors should be handled
// Ignore these errors!
} else if (err instanceof Error) {
if ('code' in err && err.code === 'ENOENT' && 'path' in err) {
console.error(`File not found "${err.path}"`)
} else if (err instanceof ZodError) {
console.error(prettifyError(err))
} else {
console.error('Error:', err.message)
}
} else {
console.error('Unkown error:', err)
}
process.exit(1)
}
}
parse()