-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathformat.mjs
More file actions
26 lines (22 loc) · 791 Bytes
/
format.mjs
File metadata and controls
26 lines (22 loc) · 791 Bytes
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
#!/usr/bin/env zx
import 'zx/globals';
import {
cliArguments,
getToolchainArgument,
partitionArguments,
popArgument,
workingDirectory,
} from '../utils.mjs';
const [folder, ...formatArgs] = cliArguments();
const fix = popArgument(formatArgs, '--fix');
const [cargoArgs, fmtArgs] = partitionArguments(formatArgs, '--');
const toolchain = getToolchainArgument('format');
const manifestPath = path.join(workingDirectory, folder, 'Cargo.toml');
// Format the client.
if (fix) {
await $`tombi format ${formatArgs} ${folder}`;
await $`cargo ${toolchain} fmt --manifest-path ${manifestPath} ${cargoArgs} -- ${fmtArgs}`;
} else {
await $`tombi lint ${formatArgs} ${folder}`;
await $`cargo ${toolchain} fmt --manifest-path ${manifestPath} ${cargoArgs} -- --check ${fmtArgs}`;
}