目录

ohpm run

Runs a user-defined script.

Command Format

ohpm run [options] <script_name> [-- <args...>]

Description

[h2]Transferring Parameters

[h2]Supporting Multiple Commands

Two types of command connectors are supported: && and ||. (&& and || are not prioritized. Commands are executed from left to right. Parentheses cannot be used to change the priority of each subcommand.) For details, see Example.

[h2]Constraints

Item

Description

Constraint on scriptKey naming

A valid scriptKey name can contain uppercase and lowercase letters, digits, ASCII colons (:), ASCII underscores (_), and ASCII hyphens (-), and must start with a lowercase letter.

Constraint on scriptContent

A valid scriptContent cannot reference any ohpm commands except ohpm run.

Constraint on using ohpm run in scriptContent

1. Aliases of other scripts on which ohpm run depends must exist in the same oh-package.json5 file.

2. The reference relationship of ohpm run is a DAG and does not support recursive or circular reference.

Options

[h2]prefix

You can use --prefix to specify the root directory of the package. The root directory must contain the oh-package.json5 file. The script alias in the dependency package cannot be invoked by running the following command:

ohpm run --prefix <path> <script alias >

[h2]log_level

In ohpm 6.0.2.636 and later versions, you can append the --log_level <string> parameter to the command to specify the log level (info, debug, warn, or error) for the execution of the current command. If this parameter is not set, the log_level setting in the .ohpmrc file is applied.

[h2]debug

In ohpm 6.0.2.636 and later versions, you can append the --debug parameter to the command to set the log level to debug for execution of the current command. This configuration takes effect only on the current command line and does not alter the log level configured in the .ohpmrc file. If this parameter is not set, the log_level setting in the .ohpmrc file is applied.

Example

The scripts configurations in the sample code are all from the oh-package.json5 file:

{
  "name": "example",
  "version": "1.0.0",
  "description": "this is an example for ohpm run.",
  "main": "./src/index.ets",
  "author": "oh",
  "license": "ISC",
  "scripts": {
    "testLogic": "ohpm run testFail || ohpm run testSuc && ohpm run testSuc",
    "testFail": "test1",
    "testSuc": "echo hello"
  }
}

[h2]Example of Parameter Transfer

ohpm run script_name -- -arg1=1 --arg2=2 -arg3 3 --arg4 4

Execute the script_name script and set the values of arg1, arg2, arg3, and arg4 to 1, 2, 3, and 4, respectively. In the preceding code, all the four forms are valid and equivalent in effect.

[h2]Success Example

Run the following command to execute the testSuc script:

ohpm run testSuc

The execution result is as follows:

[h2]Failure Example

Run the following command to execute the testFail script:

ohpm run testFail

The execution result is as follows:

[h2]Example of Using Logical Operators (&& and ||)

Run the following command to execute the testLogic script:

ohpm run testLogic

The execution result is as follows: