snapshot.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { Snapshot } from "../../../snapshot"
  2. import { bootstrap } from "../../bootstrap"
  3. import { cmd } from "../cmd"
  4. export const SnapshotCommand = cmd({
  5. command: "snapshot",
  6. builder: (yargs) => yargs.command(TrackCommand).command(PatchCommand).command(DiffCommand).demandCommand(),
  7. async handler() {},
  8. })
  9. const TrackCommand = cmd({
  10. command: "track",
  11. async handler() {
  12. await bootstrap(process.cwd(), async () => {
  13. console.log(await Snapshot.track())
  14. })
  15. },
  16. })
  17. const PatchCommand = cmd({
  18. command: "patch <hash>",
  19. builder: (yargs) =>
  20. yargs.positional("hash", {
  21. type: "string",
  22. description: "hash",
  23. demandOption: true,
  24. }),
  25. async handler(args) {
  26. await bootstrap(process.cwd(), async () => {
  27. console.log(await Snapshot.patch(args.hash))
  28. })
  29. },
  30. })
  31. const DiffCommand = cmd({
  32. command: "diff <hash>",
  33. builder: (yargs) =>
  34. yargs.positional("hash", {
  35. type: "string",
  36. description: "hash",
  37. demandOption: true,
  38. }),
  39. async handler(args) {
  40. await bootstrap(process.cwd(), async () => {
  41. console.log(await Snapshot.diff(args.hash))
  42. })
  43. },
  44. })