cli.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { invokeTauriCommand } from './helpers/tauri.js';
  2. // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
  3. // SPDX-License-Identifier: Apache-2.0
  4. // SPDX-License-Identifier: MIT
  5. /**
  6. * Parse arguments from your Command Line Interface.
  7. *
  8. * This package is also accessible with `window.__TAURI__.cli` when [`build.withGlobalTauri`](https://tauri.app/v1/api/config/#buildconfig.withglobaltauri) in `tauri.conf.json` is set to `true`.
  9. * @module
  10. */
  11. /**
  12. * 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`
  13. * @example
  14. * ```typescript
  15. * import { getMatches } from '@tauri-apps/api/cli';
  16. * const matches = await getMatches();
  17. * if (matches.subcommand?.name === 'run') {
  18. * // `./your-app run $ARGS` was executed
  19. * const args = matches.subcommand?.matches.args
  20. * if ('debug' in args) {
  21. * // `./your-app run --debug` was executed
  22. * }
  23. * } else {
  24. * const args = matches.args
  25. * // `./your-app $ARGS` was executed
  26. * }
  27. * ```
  28. *
  29. * @since 1.0.0
  30. */
  31. async function getMatches() {
  32. return invokeTauriCommand({
  33. __tauriModule: 'Cli',
  34. message: {
  35. cmd: 'cliMatches'
  36. }
  37. });
  38. }
  39. export { getMatches };