Skip to content

Commit 6185b40

Browse files
authored
Merge partition arguments helper (#33)
1 parent bac0950 commit 6185b40

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

scripts/helpers/utils.mts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,18 @@ export function popArgument(args: string[], arg: string) {
111111

112112
export function partitionArguments(
113113
args: string[],
114-
delimiter: string
114+
delimiter: string,
115+
defaultArgs?: string[]
115116
): [string[], string[]] {
116117
const index = args.indexOf(delimiter);
117-
return index >= 0
118-
? [args.slice(0, index), args.slice(index + 1)]
119-
: [args, []];
120-
}
118+
const [providedCargoArgs, providedCommandArgs] =
119+
index >= 0 ? [args.slice(0, index), args.slice(index + 1)] : [args, []];
121120

122-
export function partitionArgumentsWithDefaultArgs(
123-
args: string[],
124-
delimiter: string,
125-
defaultArgs?: string[],
126-
): [string[], string[]] {
127-
const [providedCargoArgs, providedCommandArgs] = partitionArguments(args, delimiter);
128121
if (defaultArgs) {
129-
const [defaultCargoArgs, defaultCommandArgs] = partitionArguments(defaultArgs, delimiter);
122+
const [defaultCargoArgs, defaultCommandArgs] = partitionArguments(
123+
defaultArgs,
124+
delimiter
125+
);
130126
return [
131127
[...defaultCargoArgs, ...providedCargoArgs],
132128
[...defaultCommandArgs, ...providedCommandArgs],
@@ -144,10 +140,14 @@ export async function getInstalledSolanaVersion(): Promise<string | undefined> {
144140
}
145141
}
146142

147-
export function parseCliArguments(): { command: string, libraryPath: string; args: string[] } {
143+
export function parseCliArguments(): {
144+
command: string;
145+
libraryPath: string;
146+
args: string[];
147+
} {
148148
const command = process.argv[2];
149149
const args = process.argv.slice(3);
150-
150+
151151
// Extract the relative crate directory from the command-line arguments. This
152152
// is the only required argument.
153153
const relativePath = args.shift();

scripts/js.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import 'zx/globals';
66
import {
77
parseCliArguments,
8-
partitionArgumentsWithDefaultArgs,
8+
partitionArguments,
99
} from './helpers/utils.mts';
1010

1111
enum Command {
@@ -21,7 +21,7 @@ async function pnpm(
2121
command: string,
2222
build = false,
2323
) {
24-
const [pnpmArgs, commandArgs] = partitionArgumentsWithDefaultArgs(args, '--');
24+
const [pnpmArgs, commandArgs] = partitionArguments(args, '--');
2525
cd(libraryPath);
2626
await $`pnpm install`;
2727
if (build) {

scripts/rust.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
getCargo,
88
getToolchainArgument,
99
parseCliArguments,
10-
partitionArgumentsWithDefaultArgs,
10+
partitionArguments,
1111
popArgument,
1212
workingDirectory,
1313
} from './helpers/utils.mts';
@@ -32,7 +32,7 @@ async function cargo(
3232
defaultArgs?: string[],
3333
variables?: [string, string][],
3434
) {
35-
const [cargoArgs, commandArgs] = partitionArgumentsWithDefaultArgs(args, '--', defaultArgs);
35+
const [cargoArgs, commandArgs] = partitionArguments(args, '--', defaultArgs);
3636
variables?.forEach(([k, v]) => $.env[k] = v);
3737
await $`cargo ${toolchain} ${command} --manifest-path ${manifestPath} ${cargoArgs} -- ${commandArgs}`;
3838
}

0 commit comments

Comments
 (0)