Skip to content

Commit c0c993f

Browse files
committed
refactor: proper cli with commander
fix: fix path in "checkBroadcast"
1 parent c461449 commit c0c993f

File tree

10 files changed

+112
-95
lines changed

10 files changed

+112
-95
lines changed

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@
1010
"source.fixAll.biome": "explicit",
1111
"source.organizeImports.biome": "explicit"
1212
},
13+
"search.exclude": {
14+
"**/data": true,
15+
"**/node_modules": true
16+
},
1317
"typescript.tsdk": "node_modules/typescript/lib"
1418
}

bun.lock

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"": {
55
"name": "@sablier/deployments",
66
"dependencies": {
7+
"commander": "^14.0.0",
78
"lodash": "^4.17",
89
"viem": "^2.31",
910
},
@@ -165,7 +166,7 @@
165166

166167
"@rollup/rollup-win32-x64-msvc": ["@rollup/[email protected]", "", { "os": "win32", "cpu": "x64" }, "sha512-lpPE1cLfP5oPzVjKMx10pgBmKELQnFJXHgvtHCtuJWOv8MxqdEIMNtgHgBFf7Ea2/7EuVwa9fodWUfXAlXZLZQ=="],
167168

168-
"@sablier/devkit": ["@sablier/devkit@github:sablier-labs/devkit#f40cb57", {}, "sablier-labs-devkit-f40cb57"],
169+
"@sablier/devkit": ["@sablier/devkit@github:sablier-labs/devkit#61ae1a5", {}, "sablier-labs-devkit-61ae1a5"],
169170

170171
"@scure/base": ["@scure/[email protected]", "", {}, "sha512-9rE6EOVeIQzt5TSu4v+K523F8u6DhBsoZWPGKlnCshhlDhy0kJzUX4V+tr2dWmzF1GdekvThABoEQBGBQI7xZw=="],
171172

@@ -261,7 +262,7 @@
261262

262263
"combined-stream": ["[email protected]", "", { "dependencies": { "delayed-stream": "~1.0.0" } }, "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg=="],
263264

264-
"commander": ["commander@13.1.0", "", {}, "sha512-/rFeCpNJQbhSZjGVwO9RFV3xPqbnERS8MmIQzCtD/zl6gpJuV/bMLuN92oG3F7d8oDEHHRrujSXNUr8fpjntKw=="],
265+
"commander": ["commander@14.0.0", "", {}, "sha512-2uM9rYjPvyq39NwLRqaiLtWHyDC1FvryJDa2ATTVims5YAS4PupsEQsDvP14FqhFr0P49CYDugi59xaxJlTXRA=="],
265266

266267
"cross-spawn": ["[email protected]", "", { "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", "which": "^2.0.1" } }, "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA=="],
267268

@@ -609,6 +610,8 @@
609610

610611
"execa/is-stream": ["[email protected]", "", {}, "sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA=="],
611612

613+
"lint-staged/commander": ["[email protected]", "", {}, "sha512-/rFeCpNJQbhSZjGVwO9RFV3xPqbnERS8MmIQzCtD/zl6gpJuV/bMLuN92oG3F7d8oDEHHRrujSXNUr8fpjntKw=="],
614+
612615
"log-update/slice-ansi": ["[email protected]", "", { "dependencies": { "ansi-styles": "^6.2.1", "is-fullwidth-code-point": "^5.0.0" } }, "sha512-bSiSngZ/jWeX93BqeIAbImyTbEihizcwNjFoRUIY/T1wWQsfsm2Vw1agPKylXvQTU7iASGdHhyqRlqQzfz+Htg=="],
613616

614617
"micromatch/picomatch": ["[email protected]", "", {}, "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA=="],

cli/print/aliases.ts renamed to cli/commands/print/aliases.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { logger } from "@src/internal/logger";
22
import { sablier } from "@src/sablier";
3+
import { Command } from "commander";
34
import _ from "lodash";
45

56
type AliasRow = {
@@ -8,7 +9,7 @@ type AliasRow = {
89
releaseName: string;
910
};
1011

11-
async function main(): Promise<void> {
12+
async function printAliases(): Promise<void> {
1213
const rows: AliasRow[] = [];
1314

1415
for (const release of sablier.releases.getAll()) {
@@ -55,4 +56,6 @@ async function main(): Promise<void> {
5556
}
5657
}
5758

58-
main();
59+
export const aliasesCommand = new Command("aliases")
60+
.description("Display all contract aliases across releases")
61+
.action(printAliases);

cli/commands/print/chains.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { mainnets, testnets } from "@src/chains";
2+
import { Command } from "commander";
3+
import _ from "lodash";
4+
5+
export const chainCommand = new Command("chains")
6+
.description("List all supported mainnet and testnet chains")
7+
.action(() => {
8+
console.log("🌐 Mainnets:");
9+
console.log(
10+
_.values(mainnets)
11+
.map((c) => `• ${c.slug}`)
12+
.join("\n"),
13+
);
14+
15+
console.log("\n🧪 Testnets:");
16+
console.log(
17+
_.values(testnets)
18+
.map((c) => `• ${c.slug}`)
19+
.join("\n"),
20+
);
21+
});

cli/print/missing-broadcasts.ts renamed to cli/commands/print/missing-broadcasts.ts

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
1-
/**
2-
* @file This script checks for missing broadcasts for a given protocol. It will look at the releases
3-
* and check if the associated broadcasts exist in the data directory. The script does not check
4-
* for all chains, only the ones listed in the releases.
5-
*
6-
* Usage:
7-
* bun run cli/print/missing-broadcasts.ts airdrops
8-
* bun run cli/print/missing-broadcasts.ts flow
9-
* bun run cli/print/missing-broadcasts.ts lockup
10-
*/
11-
121
import { Protocol } from "@src/enums";
132
import { checkBroadcast } from "@src/internal/helpers";
143
import { logger } from "@src/internal/logger";
154
import { sablier } from "@src/sablier";
165
import type { Sablier } from "@src/types";
6+
import { Command } from "commander";
177
import _ from "lodash";
188

199
const EMOJIS = {
@@ -26,17 +16,12 @@ const EMOJIS = {
2616
warning: "⚠️",
2717
} as const;
2818

29-
/* -------------------------------------------------------------------------- */
30-
/* MAIN */
31-
/* -------------------------------------------------------------------------- */
32-
33-
async function main(): Promise<void> {
19+
async function checkMissingBroadcasts(protocol: Sablier.Protocol): Promise<void> {
3420
const missing: Record<string, Sablier.Chain[]> = {};
35-
const protocolArg = parseArgs();
3621

37-
console.log(`${EMOJIS.folder} Checking ${protocolArg} broadcasts...\n`);
22+
console.log(`${EMOJIS.folder} Checking ${protocol} broadcasts...\n`);
3823

39-
const releases = sablier.releases.getAll({ protocol: protocolArg });
24+
const releases = sablier.releases.getAll({ protocol });
4025
for (const r of releases) {
4126
for (const d of r.deployments) {
4227
const chain = sablier.chains.getOrThrow(d.chainId);
@@ -103,7 +88,6 @@ async function main(): Promise<void> {
10388
console.log(); // Empty line between versions
10489
}
10590

106-
// Print summary
10791
const totalMissing = _.values(missing).flat().length;
10892
const mainnetCount = _.values(missing)
10993
.flat()
@@ -118,27 +102,27 @@ async function main(): Promise<void> {
118102
console.log(`${EMOJIS.testnet} Missing testnet broadcasts: ${testnetCount}\n`);
119103
}
120104

121-
main();
122-
123-
/* -------------------------------------------------------------------------- */
124-
/* HELPERS */
125-
/* -------------------------------------------------------------------------- */
126-
127-
function parseArgs(): Sablier.Protocol {
128-
const protocolArg = process.argv[2] as Sablier.Protocol;
129-
const available = _.values(Protocol);
130-
if (!protocolArg || !available.includes(protocolArg)) {
131-
const msg = `Error: Please provide one of these protocols: ${available.join(", ")}`;
132-
logger.error(msg);
133-
throw new Error(msg);
134-
}
135-
136-
return protocolArg;
137-
}
138-
139105
function printSectionHeader(text: string): void {
140106
const separator = "═".repeat(50);
141107
console.log(`\n${separator}`);
142108
console.log(text);
143109
console.log(`${separator}\n`);
144110
}
111+
112+
export const missingBroadcastsCommand = new Command("missing-broadcasts")
113+
.description("Check for missing broadcasts for a given protocol")
114+
.option("-p, --protocol <protocol>", `Protocol to check (${_.values(Protocol).join(", ")})`)
115+
.action(async (options: { protocol?: Sablier.Protocol }) => {
116+
if (!options.protocol) {
117+
logger.error("Error: Protocol is required. Use -p or --protocol to specify.");
118+
process.exit(1);
119+
}
120+
121+
const available = _.values(Protocol);
122+
if (!available.includes(options.protocol)) {
123+
logger.error(`Error: Please provide one of these protocols: ${available.join(", ")}`);
124+
process.exit(1);
125+
}
126+
127+
await checkMissingBroadcasts(options.protocol);
128+
});

cli/index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env node
2+
3+
import { Command } from "commander";
4+
import { aliasesCommand } from "./commands/print/aliases";
5+
import { chainCommand } from "./commands/print/chains";
6+
import { missingBroadcastsCommand } from "./commands/print/missing-broadcasts";
7+
8+
const program = new Command();
9+
10+
program.name("sablier-cli").description("CLI for Sablier deployment utilities");
11+
12+
// Create the print subcommand
13+
const printCommand = new Command("print").description("Print various deployment information");
14+
15+
// Add commands to the print subcommand
16+
printCommand.addCommand(aliasesCommand);
17+
printCommand.addCommand(chainCommand);
18+
printCommand.addCommand(missingBroadcastsCommand);
19+
20+
// Add the print command to the main program
21+
program.addCommand(printCommand);
22+
23+
// Parse command line arguments
24+
program.parse();

cli/print/chains.ts

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

justfile

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
set shell := ["bash", "-euo", "pipefail", "-c"]
1+
# See https://github.com/sablier-labs/devkit/blob/main/just/base.just
2+
import "./node_modules/@sablier/devkit/just/base.just"
23

34
# ---------------------------------------------------------------------------- #
45
# RECIPES #
@@ -8,15 +9,6 @@ set shell := ["bash", "-euo", "pipefail", "-c"]
89
default:
910
just --list
1011

11-
# Check code with Biome
12-
biome-check:
13-
bun biome check .
14-
15-
# Fix code with Biome and update imports
16-
biome-write:
17-
bun biome check --write .
18-
bun biome lint --write --only correctness/noUnusedImports .
19-
2012
# Build the project
2113
build: clean tsc-build
2214
alias b := build
@@ -25,29 +17,20 @@ alias b := build
2517
clean:
2618
bunx rimraf dist
2719

28-
# Run all code checks
29-
full-check: biome-check prettier-check tsc-check
30-
alias c := full-check
31-
alias fc := full-check
32-
33-
# Run all code fixes
34-
full-write: biome-write prettier-write
35-
36-
# Install dependencies
37-
install *args:
38-
bun install {{ args }}
39-
40-
# Check markdown and yaml files with Prettier
41-
prettier-check:
42-
bun prettier --cache --check "**/*.{md,yml}"
20+
# Run print CLI commands.
21+
[group("print")]
22+
@print-aliases:
23+
just cli print aliases
4324

44-
# Fix markdown and yaml files with Prettier
45-
prettier-write:
46-
bun prettier --cache --write "**/*.{md,yml}"
25+
# Run print CLI commands.
26+
[group("print")]
27+
@print-chains:
28+
just cli print chains
4729

48-
# Run print CLI script. See the files under ./cli/print for available scripts
49-
@print script *args:
50-
bun run cli/print/{{ script }}.ts {{ args }}
30+
# Run print CLI commands.
31+
[group("print")]
32+
@print-missing-broadcasts protocol:
33+
just cli print missing-broadcasts --protocol {{ protocol }}
5134

5235
# Setup Husky
5336
setup:
@@ -71,6 +54,13 @@ tsc-build:
7154
bun tsc -p tsconfig.build.json
7255
bun tsc-alias -p tsconfig.build.json
7356

74-
# Type check TypeScript
75-
tsc-check:
76-
bun tsc -p tsconfig.json --noEmit
57+
58+
# ---------------------------------------------------------------------------- #
59+
# RECIPES: PRIVATE #
60+
# ---------------------------------------------------------------------------- #
61+
62+
63+
# Run CLI commands. Usage: just cli <command> [args]
64+
[private]
65+
@cli *args:
66+
bun run cli {{ args }}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@types/node": "^22.14",
1919
"@vitest/ui": "^3.1",
2020
"axios": "^1.8",
21+
"commander": "^14.0.0",
2122
"fs-extra": "^11.3",
2223
"globby": "^14.1",
2324
"husky": "^9.1",

src/internal/helpers.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ import type { Sablier } from "@src/types";
33
import * as fs from "fs-extra";
44
import { log } from "./logger";
55

6-
const ROOT_DIR = path.join(__dirname, "..");
6+
const ROOT_DIR = path.join(__dirname, "..", "..");
77
const DATA_DIR = path.join(ROOT_DIR, "data");
88

9+
// Ensuring that the `ROOT_DIR` is correctly set.
10+
if (!fs.existsSync(path.join(ROOT_DIR, "package.json"))) {
11+
throw new Error("ROOT_DIR is not correctly set");
12+
}
13+
914
/**
1015
* @example
1116
* data/

0 commit comments

Comments
 (0)