Skip to content

Commit

Permalink
feat: use oclif/table (#932)
Browse files Browse the repository at this point in the history
* feat: use oclif/table

* chore: bump oclif/table

* chore: code review
  • Loading branch information
mdonnalley authored Oct 4, 2024
1 parent 9522b93 commit 280b6ed
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 192 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
"dependencies": {
"@inquirer/select": "^2.5.0",
"@oclif/core": "^4",
"@oclif/table": "^0.1.12",
"ansis": "^3.3.2",
"debug": "^4.3.7",
"filesize": "^6.1.0",
"got": "^13",
"proxy-agent": "^6.4.0",
"semver": "^7.6.3",
"tar-fs": "^2.1.1",
"tty-table": "^4.2.3"
"tar-fs": "^2.1.1"
},
"devDependencies": {
"@commitlint/config-conventional": "^19",
Expand Down
61 changes: 34 additions & 27 deletions src/commands/update.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import select from '@inquirer/select'
import {Args, Command, Flags, Interfaces, ux} from '@oclif/core'
import {printTable} from '@oclif/table'
import {got} from 'got'
import {basename} from 'node:path'
import {sort} from 'semver'
import TtyTable from 'tty-table'

import {Updater} from '../update.js'

Expand Down Expand Up @@ -49,6 +49,11 @@ export default class UpdateCommand extends Command {
description: 'Interactively select version to install. This is ignored if a channel is provided.',
exclusive: ['version'],
}),
verbose: Flags.boolean({
char: 'b',
dependsOn: ['available'],
description: 'Show more details about the available versions.',
}),
version: Flags.string({
char: 'v',
description: 'Install a specific version.',
Expand All @@ -62,32 +67,34 @@ export default class UpdateCommand extends Command {
if (flags.available) {
const {distTags, index, localVersions} = await lookupVersions(updater, this.config)

const headers = [
{align: 'left', value: 'Location'},
{align: 'left', value: 'Version'},
]

if (distTags) {
headers.push({align: 'left', value: 'Channel'})
}

// eslint-disable-next-line new-cap
const t = TtyTable(
headers,
sort(Object.keys(index))
.reverse()
.map((version) => {
const location = localVersions.find((l) => basename(l).startsWith(version)) || index[version]
if (distTags) {
return [location, version, distTags[version] ?? '']
}

return [location, version]
}),
{compact: true},
)

ux.stdout(t.render())
const data = Object.keys(index).map((version) => {
const location = localVersions.find((l) => basename(l).startsWith(version)) || index[version]
const channel =
distTags[version] === 'latest'
? 'stable'
: distTags[version] === 'latest-rc'
? 'stable-rc'
: distTags[version]
return {
channel,
downloaded: location.includes('http') ? '' : 'true',
location,
version: this.config.version === version ? `${ux.colorize('yellowBright', version)} (current)` : version,
}
})

printTable({
borderStyle: 'vertical-with-outline',
columns: flags.verbose
? ['version', 'channel', 'downloaded', 'location']
: ['version', 'channel', 'downloaded'],
data,
headerOptions: {
formatter: 'capitalCase',
},
overflow: 'wrap',
})

return
}

Expand Down
2 changes: 1 addition & 1 deletion src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ ${binPathEnvVar}="\$DIR/${bin}" ${redirectedEnvVar}=1 "$DIR/../${version}/bin/${
}

private async refreshConfig(version: string): Promise<void> {
this.config = (await Config.load({root: join(this.clientRoot, version)})) as Config
this.config = await Config.load({root: join(this.clientRoot, version)})
}

// removes any unused CLIs
Expand Down
Loading

0 comments on commit 280b6ed

Please sign in to comment.