-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.ts
More file actions
95 lines (89 loc) · 2.83 KB
/
main.ts
File metadata and controls
95 lines (89 loc) · 2.83 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
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
import {debuglog, format} from 'node:util'
import {CompletionsCommand, MZMCommand, Table, Cell, colors} from '@mzm/core'
import {info} from '@mzm/core/release'
import {LogCommand} from '@mzm/command-log'
import {ConfigCommand} from '@mzm/command-config'
import GetCommand from '@mzm/command-get'
import CreateCommand from '@mzm/command-create'
import DeleteCommand from '@mzm/command-delete'
import EditCommand from '@mzm/command-edit'
import AskCommand from '@mzm/command-ask'
import VersionCommand from '@mzm/command-version'
import {GithubReleasesUpgradeCommand} from '@mzm/command-upgrade'
import {providers} from '@mzm/core/update'
import {logo} from '@mzm/core/assets'
import {storage} from '@mzm/config'
const debug = debuglog('core:command:entry')
const upgrade = new GithubReleasesUpgradeCommand({
provider: new providers.GithubReleaseProvider({
spinner: true
, repository: 'mezmo/cli'
, asset_map: {
linux: {
['x86_64']: 'mzm-linux-x86_64'
, ['aarch64']: 'mzm-linux-aarch64'
}
, darwin: {
['x86_64']: 'mzm-darwin-x86_64'
, ['aarch64']: 'mzm-darwin-aarch64'
}
, windows: {
['x86_64']: 'mzm-windows-x86_64.exe'
, ['aarch64']: null
}
}
})
})
// Learn more at https://docs.deno.com/runtime/manual/examples/module_metadata#concepts
if (import.meta.main) {
const previous_version: string | null = await storage.getOne('upgrade.cleanup.file') as string | null
if (previous_version) {
debug('previous version cleanup: %s', previous_version)
Deno
.remove(previous_version)
.catch((error) => {
debug('unable to remove previous version', error)
})
.finally(() => {
return storage.unset('upgrade.cleanup.file')
debug('previous version cleanup complete')
})
}
const cmd = new MZMCommand()
.action(function () {
const output = new Table().padding(8)
const body = []
body.push(['', new Cell(logo())])
body.push([])
body.push([
new Cell(
format('%s %s @ %s', colors.yellow('mezmo'), 'cli', colors.bold(info().version))
).colSpan(2).align('center')
, ''
])
console.log(output.body(body).toString())
this.showHelp()
})
.command('ask', AskCommand)
.command('completions', new CompletionsCommand())
.command('config', ConfigCommand)
.command('create', CreateCommand)
.command('delete', DeleteCommand)
.command('edit', EditCommand)
.command('get', GetCommand)
.command('log', LogCommand)
.command('upgrade', upgrade)
.command('version', VersionCommand)
try {
await cmd.parse(Deno.args)
} catch (err: any) {
if (debug.enabled) console.dir(err)
cmd.showHelp()
if (err.cause?.help) {
console.error(String(err))
Deno.exitCode = err.exit_code ?? 1
} else {
throw err
}
}
}