generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.ts
33 lines (29 loc) · 1004 Bytes
/
list.ts
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
import {Errors} from '@oclif/core'
import groupBy from 'lodash/groupBy.js'
import terminalLink from 'terminal-link'
import BaseCommand from '../base-command.js'
import {Repos} from '../repos.js'
import {printTables} from '../table.js'
export default class List extends BaseCommand {
public static aliases = ['ls']
public static description = 'List all repositories.'
public async run(): Promise<void> {
const repositories = (await new Repos().init()).getContents()
if (Object.keys(repositories).length === 0) {
throw new Errors.CLIError('No repositories have been added yet.')
}
printTables(
Object.entries(groupBy(repositories, 'org')).map(([org, repos]) => ({
columns: ['name', 'location'] as const,
data: Object.values(repos).map((r) => ({
location: r.location,
name: terminalLink(r.name, r.urls.html),
})),
sort: {
name: 'asc',
},
title: `${org} Repositories`,
})),
)
}
}