file.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { File } from "../../../file"
  2. import { bootstrap } from "../../bootstrap"
  3. import { cmd } from "../cmd"
  4. const FileReadCommand = cmd({
  5. command: "read <path>",
  6. builder: (yargs) =>
  7. yargs.positional("path", {
  8. type: "string",
  9. demandOption: true,
  10. description: "File path to read",
  11. }),
  12. async handler(args) {
  13. await bootstrap(process.cwd(), async () => {
  14. const content = await File.read(args.path)
  15. console.log(content)
  16. })
  17. },
  18. })
  19. const FileStatusCommand = cmd({
  20. command: "status",
  21. builder: (yargs) => yargs,
  22. async handler() {
  23. await bootstrap(process.cwd(), async () => {
  24. const status = await File.status()
  25. console.log(JSON.stringify(status, null, 2))
  26. })
  27. },
  28. })
  29. const FileListCommand = cmd({
  30. command: "list <path>",
  31. builder: (yargs) =>
  32. yargs.positional("path", {
  33. type: "string",
  34. demandOption: true,
  35. description: "File path to list",
  36. }),
  37. async handler(args) {
  38. await bootstrap(process.cwd(), async () => {
  39. const files = await File.list(args.path)
  40. console.log(JSON.stringify(files, null, 2))
  41. })
  42. },
  43. })
  44. export const FileCommand = cmd({
  45. command: "file",
  46. builder: (yargs) =>
  47. yargs.command(FileReadCommand).command(FileStatusCommand).command(FileListCommand).demandCommand(),
  48. async handler() {},
  49. })