cli.cjs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. var tauri = require('./helpers/tauri.cjs');
  3. // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
  4. // SPDX-License-Identifier: Apache-2.0
  5. // SPDX-License-Identifier: MIT
  6. /**
  7. * Parse arguments from your Command Line Interface.
  8. *
  9. * 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`.
  10. * @module
  11. */
  12. /**
  13. * 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`
  14. * @example
  15. * ```typescript
  16. * import { getMatches } from '@tauri-apps/api/cli';
  17. * const matches = await getMatches();
  18. * if (matches.subcommand?.name === 'run') {
  19. * // `./your-app run $ARGS` was executed
  20. * const args = matches.subcommand?.matches.args
  21. * if ('debug' in args) {
  22. * // `./your-app run --debug` was executed
  23. * }
  24. * } else {
  25. * const args = matches.args
  26. * // `./your-app $ARGS` was executed
  27. * }
  28. * ```
  29. *
  30. * @since 1.0.0
  31. */
  32. async function getMatches() {
  33. return tauri.invokeTauriCommand({
  34. __tauriModule: 'Cli',
  35. message: {
  36. cmd: 'cliMatches'
  37. }
  38. });
  39. }
  40. exports.getMatches = getMatches;