format-rust.mjs 791 B

123456789101112131415161718192021222324252627282930
  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. // Configure additional arguments here, e.g.:
  11. // ['--arg1', '--arg2', ...cliArguments()]
  12. const formatArgs = cliArguments();
  13. const fix = popArgument(formatArgs, '--fix');
  14. const [cargoArgs, fmtArgs] = partitionArguments(formatArgs, '--');
  15. const toolchain = getToolchainArgument('format');
  16. const manifestPath = path.join(
  17. workingDirectory,
  18. 'clients',
  19. 'rust',
  20. 'Cargo.toml'
  21. );
  22. // Format the client.
  23. if (fix) {
  24. await $`cargo ${toolchain} fmt --manifest-path ${manifestPath} ${cargoArgs} -- ${fmtArgs}`;
  25. } else {
  26. await $`cargo ${toolchain} fmt --manifest-path ${manifestPath} ${cargoArgs} -- --check ${fmtArgs}`;
  27. }