format.mjs 852 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env zx
  2. import 'zx/globals';
  3. import {
  4. cliArguments,
  5. getProgramFolders,
  6. getToolchainArgument,
  7. partitionArguments,
  8. popArgument,
  9. workingDirectory,
  10. } from '../utils.mjs';
  11. // Configure additional arguments here, e.g.:
  12. // ['--arg1', '--arg2', ...cliArguments()]
  13. const formatArgs = cliArguments();
  14. const fix = popArgument(formatArgs, '--fix');
  15. const [cargoArgs, fmtArgs] = partitionArguments(formatArgs, '--');
  16. const toolchain = getToolchainArgument('format');
  17. // Format the programs.
  18. for (const folder of getProgramFolders()) {
  19. const manifestPath = path.join(workingDirectory, folder, 'Cargo.toml');
  20. if (fix) {
  21. await $`cargo ${toolchain} fmt --manifest-path ${manifestPath} ${cargoArgs} -- ${fmtArgs}`;
  22. } else {
  23. await $`cargo ${toolchain} fmt --manifest-path ${manifestPath} ${cargoArgs} -- --check ${fmtArgs}`;
  24. }
  25. }