cli.d.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * @since 1.0.0
  3. */
  4. interface ArgMatch {
  5. /**
  6. * string if takes value
  7. * boolean if flag
  8. * string[] or null if takes multiple values
  9. */
  10. value: string | boolean | string[] | null;
  11. /**
  12. * Number of occurrences
  13. */
  14. occurrences: number;
  15. }
  16. /**
  17. * @since 1.0.0
  18. */
  19. interface SubcommandMatch {
  20. name: string;
  21. matches: CliMatches;
  22. }
  23. /**
  24. * @since 1.0.0
  25. */
  26. interface CliMatches {
  27. args: Record<string, ArgMatch>;
  28. subcommand: SubcommandMatch | null;
  29. }
  30. /**
  31. * Parse the arguments provided to the current process and get the matches using the configuration defined [`tauri.cli`](https://tauri.app/v1/api/config/#tauriconfig.cli) in `tauri.conf.json`
  32. * @example
  33. * ```typescript
  34. * import { getMatches } from '@tauri-apps/api/cli';
  35. * const matches = await getMatches();
  36. * if (matches.subcommand?.name === 'run') {
  37. * // `./your-app run $ARGS` was executed
  38. * const args = matches.subcommand?.matches.args
  39. * if ('debug' in args) {
  40. * // `./your-app run --debug` was executed
  41. * }
  42. * } else {
  43. * const args = matches.args
  44. * // `./your-app $ARGS` was executed
  45. * }
  46. * ```
  47. *
  48. * @since 1.0.0
  49. */
  50. declare function getMatches(): Promise<CliMatches>;
  51. export type { ArgMatch, SubcommandMatch, CliMatches };
  52. export { getMatches };