format.mjs 695 B

123456789101112131415161718192021222324
  1. #!/usr/bin/env zx
  2. import 'zx/globals';
  3. import {
  4. cliArguments,
  5. getToolchainArgument,
  6. partitionArguments,
  7. popArgument,
  8. workingDirectory,
  9. } from '../utils.mjs';
  10. const [folder, ...formatArgs] = cliArguments();
  11. const fix = popArgument(formatArgs, '--fix');
  12. const [cargoArgs, fmtArgs] = partitionArguments(formatArgs, '--');
  13. const toolchain = getToolchainArgument('format');
  14. const manifestPath = path.join(workingDirectory, folder, 'Cargo.toml');
  15. // Format the client.
  16. if (fix) {
  17. await $`cargo ${toolchain} fmt --manifest-path ${manifestPath} ${cargoArgs} -- ${fmtArgs}`;
  18. } else {
  19. await $`cargo ${toolchain} fmt --manifest-path ${manifestPath} ${cargoArgs} -- --check ${fmtArgs}`;
  20. }