Skip to content

Commit b92d224

Browse files
authored
Merge pull request #300 from capralifecycle/add-feedback-messages
feat: add status messages for network operations
2 parents 4fac213 + c3dd798 commit b92d224

File tree

6 files changed

+65
-22
lines changed

6 files changed

+65
-22
lines changed

src/cli/commands/clone.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ import { hideBin } from "yargs/helpers"
66
import type { Config } from "../../config"
77
import { createGitHubService, type GitHubService } from "../../github"
88
import { getGroupedRepos, includesTopic } from "../../github/util"
9-
import { createCacheProvider, createConfig } from "../util"
9+
import type { Reporter } from "../reporter"
10+
import { createCacheProvider, createConfig, createReporter } from "../util"
1011

1112
async function generateCloneCommands({
1213
config,
1314
github,
15+
reporter,
1416
org,
1517
...opt
1618
}: {
1719
config: Config
1820
github: GitHubService
21+
reporter: Reporter
1922
all: boolean
2023
skipCloned: boolean
2124
group: string | undefined
@@ -29,6 +32,7 @@ async function generateCloneCommands({
2932
return
3033
}
3134

35+
reporter.status(`Fetching repositories from ${org}...`)
3236
const repos = await github.getOrgRepoList({ org })
3337
const groups = getGroupedRepos(repos)
3438

@@ -103,6 +107,7 @@ const command: CommandModule = {
103107
github: await createGitHubService({
104108
cache: createCacheProvider(config, argv),
105109
}),
110+
reporter: createReporter(),
106111
all: !!argv.all,
107112
includeArchived: !!argv["include-archived"],
108113
name: argv.name as string | undefined,

src/cli/commands/groups.ts

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,58 @@
1+
import fs from "node:fs"
2+
import path from "node:path"
3+
import process from "node:process"
4+
import { findUp } from "find-up"
5+
import yaml from "js-yaml"
16
import type { CommandModule } from "yargs"
2-
import { createGitHubService } from "../../github"
3-
import { getGroupedRepos } from "../../github/util"
4-
import { createCacheProvider, createConfig, createReporter } from "../util"
7+
import { DefinitionFile } from "../../definition"
8+
import { createReporter } from "../util"
9+
10+
const CALS_YAML = ".cals.yaml"
11+
12+
interface CalsManifest {
13+
version: 2
14+
githubOrganization: string
15+
resourcesDefinition: {
16+
path: string
17+
}
18+
}
519

620
const command: CommandModule = {
721
command: "groups",
8-
describe: "List available repository groups in a GitHub organization",
9-
builder: (yargs) =>
10-
yargs.options("org", {
11-
alias: "o",
12-
default: "capralifecycle",
13-
requiresArg: true,
14-
describe: "GitHub organization",
15-
type: "string",
16-
}),
17-
handler: async (argv) => {
18-
const config = createConfig()
22+
describe: "List available project groups from the definition file",
23+
builder: (yargs) => yargs,
24+
handler: async () => {
1925
const reporter = createReporter()
20-
const github = await createGitHubService({
21-
cache: createCacheProvider(config, argv),
22-
})
2326

24-
const repos = await github.getOrgRepoList({ org: argv.org as string })
25-
const groups = getGroupedRepos(repos)
27+
const manifestPath = await findUp(CALS_YAML)
28+
if (manifestPath === undefined) {
29+
reporter.error(`File ${CALS_YAML} not found`)
30+
process.exitCode = 1
31+
return
32+
}
33+
34+
const manifest: CalsManifest = yaml.load(
35+
fs.readFileSync(manifestPath, "utf-8"),
36+
) as CalsManifest
37+
38+
const definitionPath = path.resolve(
39+
path.dirname(manifestPath),
40+
manifest.resourcesDefinition.path,
41+
)
42+
43+
if (!fs.existsSync(definitionPath)) {
44+
reporter.error(`Definition file not found: ${definitionPath}`)
45+
process.exitCode = 1
46+
return
47+
}
48+
49+
const definition = await new DefinitionFile(definitionPath).getDefinition()
50+
const projectNames = definition.projects
51+
.map((p) => p.name)
52+
.sort((a, b) => a.localeCompare(b))
2653

27-
for (const group of groups) {
28-
reporter.log(group.name)
54+
for (const name of projectNames) {
55+
reporter.log(name)
2956
}
3057
},
3158
}

src/cli/commands/repos.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ async function listRepos({
4141
csv: boolean
4242
org: string
4343
}) {
44+
reporter.status(`Fetching repositories from ${org}...`)
4445
let repos = await github.getOrgRepoList({ org })
4546

4647
if (!includeArchived) {

src/cli/commands/sync.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ async function getExpectedRepos(
300300
expectedRepos: ExpectedRepo[]
301301
definitionRepo: ExpectedRepo | null
302302
}> {
303+
reporter.status(`Fetching repositories from ${cals.githubOrganization}...`)
303304
const githubRepos = await github.getOrgRepoList({
304305
org: cals.githubOrganization,
305306
})

src/cli/commands/topics.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const command: CommandModule = {
2020
cache: createCacheProvider(config, argv),
2121
})
2222

23+
reporter.status(`Fetching repositories from ${argv.org}...`)
2324
const repos = await github.getOrgRepoList({ org: argv.org as string })
2425

2526
const topics = new Set<string>()

src/cli/reporter.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,12 @@ export class Reporter {
105105
clearLine(this.stdout)
106106
this.stdout.write(`${this.format.blue("info")} ${msg}\n`)
107107
}
108+
109+
/**
110+
* Write a status message to stderr for feedback during long-running operations.
111+
* Writing to stderr ensures it doesn't interfere with piped stdout.
112+
*/
113+
public status(msg: string): void {
114+
this.stderr.write(`${this.format.dim(msg)}\n`)
115+
}
108116
}

0 commit comments

Comments
 (0)