Skip to content

Commit 14d87b8

Browse files
Better output support
- Support 'json', 'table', 'yaml', 'tsv' formats - Support JSONPATH property filtering - Support excluding empty results
1 parent a472603 commit 14d87b8

File tree

7 files changed

+265
-109
lines changed

7 files changed

+265
-109
lines changed

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
ARG DOCKER_USER=bun
22

3-
FROM oven/bun:1 as base
3+
FROM oven/bun:1 AS base
44
ARG DOCKER_USER
55
RUN apt-get update && apt-get install -y wget
66
RUN mkdir -p /tmp && chown ${DOCKER_USER} -R /tmp
77
RUN mkdir -p /build && chown ${DOCKER_USER} -R /build
88
RUN mkdir -p /src && chown ${DOCKER_USER} -R /src
99
USER ${DOCKER_USER}
1010

11-
FROM base as source
11+
FROM base AS source
1212
ARG DOCKER_USER
1313
WORKDIR /src
1414
COPY package.json bun.lockb ./
@@ -17,10 +17,10 @@ RUN bun install \
1717
--production
1818
COPY . .
1919

20-
FROM source as build
20+
FROM source AS build
2121
ARG DOCKER_USER
2222
ENTRYPOINT ["bun", "build", "--compile", "--file", "./index.ts", "--outfile", "./bin/dotnetman"]
2323

24-
FROM source as run
24+
FROM source AS run
2525
ARG DOCKER_USER
2626
ENTRYPOINT ["bun", "run", "index.ts"]

bun.lockb

46.2 KB
Binary file not shown.

commands/list.ts

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,80 @@
1-
import yargs, { ArgumentsCamelCase, Argv, CommandBuilder, CommandModule } from 'yargs'
1+
import type { Arguments, Argv, CommandModule } from 'yargs'
22
import { getInstalledRuntimeVersions, getInstalledSdkVersions } from '../util/dotnet'
3-
import { getListPreference, outputList } from '../util/lists'
4-
import chalk from 'chalk'
3+
import { output, toPropertyOptions, type OutputArgs } from '../util/output'
4+
5+
export type ListCommandArgs = {
6+
}
7+
& OutputArgs
8+
& Arguments
59

610
export const listCommand: CommandModule = {
711
command: 'list',
812
describe: 'List .NET software',
913
aliases: ['ls', 'get'],
10-
builder: (command: CommandBuilder) => command
11-
.option('with-lifecycle', {
12-
type: 'boolean'
14+
builder: (args: Argv<{}>) => args
15+
.option('output', {
16+
alias: 'o',
17+
type: 'string',
18+
describe: 'Output format.'
19+
})
20+
.option('property', {
21+
alias: 'p',
22+
type: 'array',
23+
describe: 'Filter properties using JSON path.'
24+
})
25+
.option('exclude-empty', {
26+
type: 'boolean',
27+
describe: 'Exclude empty values from result.'
1328
})
1429
.command(getSdkCommand)
1530
.command(getRuntimeCommand),
16-
handler: async (argv: Argv) => {
17-
console.log(`${chalk.bold.bgBlue.white('Installed sdks')}`)
31+
handler: async (args: ListCommandArgs) => {
1832
const installedSdks = await getInstalledSdkVersions()
19-
outputList(
20-
installedSdks,
21-
getListPreference(argv))
2233

23-
console.log(`${chalk.bold.bgBlue.white('Installed runtimes')}`)
2434
const installedRuntimes = await getInstalledRuntimeVersions()
25-
outputList(installedRuntimes, getListPreference(argv))
35+
36+
output(
37+
{
38+
'sdks': installedSdks,
39+
'runtimes': installedRuntimes
40+
},
41+
args.output,
42+
toPropertyOptions(args))
2643
}
2744
}
2845

46+
export type GetSdkCommandArgs = {
47+
}
48+
& ListCommandArgs
49+
& Arguments
50+
2951
const getSdkCommand: CommandModule = {
3052
command: 'sdk',
3153
describe: 'Get installed SDKs',
32-
handler: async (argv: Argv) => {
54+
handler: async (args: GetSdkCommandArgs) => {
3355
const installedSdks = await getInstalledSdkVersions()
3456

35-
outputList(installedSdks, getListPreference(argv))
57+
output(
58+
installedSdks,
59+
args.output,
60+
toPropertyOptions(args))
3661
}
3762
}
3863

64+
export type GetRuntimeCommandArgs = {
65+
}
66+
& ListCommandArgs
67+
& Arguments
68+
3969
const getRuntimeCommand: CommandModule = {
4070
command: 'runtime',
4171
describe: 'Get installed runtimes',
42-
handler: async (argv: Argv) => {
72+
handler: async (args: GetRuntimeCommandArgs) => {
4373
const installedRuntimes = await getInstalledRuntimeVersions()
4474

45-
outputList(installedRuntimes, getListPreference(argv))
75+
output(
76+
installedRuntimes,
77+
args.output,
78+
toPropertyOptions(args))
4679
}
4780
}

commands/sync.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
import yargs, { ArgumentsCamelCase, Argv, CommandBuilder, CommandModule } from 'yargs'
1+
import type { Arguments, Argv, CommandModule } from 'yargs'
22
import { getChannelFromVersion, getInstalledRuntimeVersions, getInstalledSdkVersions, syncRuntimeChannel, syncSdkChannel, type DotnetVersionConfig, syncVersionConfig } from '../util/dotnet'
3-
import { exists } from 'node:fs'
3+
4+
export type SyncCommandArgs = {
5+
target?: 'all' | 'sdk' | 'runtime'
6+
file?: string
7+
}
8+
& Arguments
49

510
export const syncCommand: CommandModule = {
611
command: 'sync [target]',
712
describe: 'Synchronize .NET software',
813
aliases: ['s'],
9-
builder: (command: CommandBuilder) => command
14+
builder: (command: Argv<{}>) => command
1015
.positional('target', {
1116
type: 'string',
1217
describe: 'The target to sync.',
@@ -26,7 +31,7 @@ export const syncCommand: CommandModule = {
2631
type: 'string',
2732
describe: 'Channel to sync.'
2833
}),
29-
handler: async (argv: Argv) => {
34+
handler: async (argv: SyncCommandArgs) => {
3035
if (argv.file) {
3136
const file = Bun.file(argv.file)
3237
if (!(await file.exists())) {

package.json

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,35 @@
88
},
99
"devDependencies": {
1010
"@types/bun": "latest",
11+
"@types/js-yaml": "^4.0.9",
12+
"@types/json-pointer": "^1.0.34",
13+
"@types/lodash": "^4.17.20",
1114
"@types/node": "^20.11.17",
12-
"@types/yargs": "^17.0.32"
15+
"@types/yargs": "^17.0.34",
16+
"eslint": "^9.39.1",
17+
"typescript-eslint": "^8.46.4"
1318
},
1419
"peerDependencies": {
1520
"typescript": "^5.0.0"
1621
},
1722
"dependencies": {
1823
"chalk": "^5.3.0",
24+
"js-yaml": "^4.1.1",
25+
"json-pointer": "^0.6.2",
26+
"lodash": "^4.17.21",
1927
"yargs": "^17.7.2"
28+
},
29+
"signale": {
30+
"displayScope": false,
31+
"displayBadge": true,
32+
"displayDate": false,
33+
"displayFilename": false,
34+
"displayLabel": false,
35+
"displayTimestamp": false,
36+
"underlineLabel": false,
37+
"underlineMessage": false,
38+
"underlinePrefix": false,
39+
"underlineSuffix": false,
40+
"uppercaseLabel": true
2041
}
2142
}

util/lists.ts

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)