Skip to content

Commit

Permalink
Merge pull request #4 from xiaoxin-sky/master
Browse files Browse the repository at this point in the history
docs(command): update cargo run  description
  • Loading branch information
OlingCat authored May 7, 2024
2 parents 4e5f1f6 + 9a2a324 commit 9fa2c68
Showing 1 changed file with 25 additions and 79 deletions.
104 changes: 25 additions & 79 deletions src/commands/cargo-run.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,32 @@
# cargo-run(1)
## 名字

cargo-run —— 运行当前包

## NAME
## 概要(synopsis)

cargo-run - Run the current package
`cargo run` [options] [`--` args]

## SYNOPSIS
### 描述

`cargo run` [_options_] [`--` _args_]
运行一个二进制或者本地包的实例
所有在 两个横线(`--`) 后面的参数都会被传递给二进制程序来运行。如果你需要同时传递一些参数给 Cargo 和二进制程序,那么在 `--` 后面的将会给二进制,在`--`前面的将会给 Cargo。

## DESCRIPTION
## 选项

Run a binary or example of the local package.
### 包选择

All the arguments following the two dashes (`--`) are passed to the binary to
run. If you're passing arguments to both Cargo and the binary, the ones after
`--` go to the binary, the ones before go to Cargo.
默认情况下,选择的是当前工作目录中的包。`-p`标志可以用来选择在工作目录中的一个不同的包。
`-p`spec
`--package` spec
运行包。SPEC 格式参考[cargo-pkgid(1)](https://rustwiki.org/zh-CN/cargo/commands/cargo-pkgid.html)

## OPTIONS

### Package Selection

By default, the package in the current working directory is selected. The `-p`
flag can be used to choose a different package in a workspace.

<dl>

<dt class="option-term" id="option-cargo-run--p"><a class="option-anchor" href="#option-cargo-run--p"></a><code>-p</code> <em>spec</em></dt>
<dt class="option-term" id="option-cargo-run---package"><a class="option-anchor" href="#option-cargo-run---package"></a><code>--package</code> <em>spec</em></dt>
<dd class="option-desc">The package to run. See <a href="cargo-pkgid.html">cargo-pkgid(1)</a> for the SPEC
format.</dd>


</dl>


### Target Selection

When no target selection options are given, `cargo run` will run the binary
target. If there are multiple binary targets, you must pass a target flag to
choose one. Or, the `default-run` field may be specified in the `[package]`
section of `Cargo.toml` to choose the name of the binary to run by default.

<dl>

<dt class="option-term" id="option-cargo-run---bin"><a class="option-anchor" href="#option-cargo-run---bin"></a><code>--bin</code> <em>name</em></dt>
<dd class="option-desc">Run the specified binary.</dd>


<dt class="option-term" id="option-cargo-run---example"><a class="option-anchor" href="#option-cargo-run---example"></a><code>--example</code> <em>name</em></dt>
<dd class="option-desc">Run the specified example.</dd>
### 目标选择

当没有传目标选项,`cargo run`将会运行二进制目标。如果有多个二进制目标,你必须传递一个目标标志来选中他们中的一个。或者 在 `Cargo.toml``[package]` 中的`default-run`字段指定一个运行时候的默认二进制名。
`--bin` name
运行一个特定的二进制
`--example` name
运行特定的例子

</dl>

Expand All @@ -67,18 +43,14 @@ section of `Cargo.toml` to choose the name of the binary to run by default.
<dd class="option-desc">传递以空格或者逗号分隔的列表,其中给出要启用的特性。工作区成员的特性可通过<code>包名/特性名</code>的语法启用。
此参数可多次给定,以分别启用给定的特性。</dd>


<dt class="option-term" id="option-cargo-run---all-features"><a class="option-anchor" href="#option-cargo-run---all-features"></a><code>--all-features</code></dt>
<dd class="option-desc">为给定的包启用全部可用特性</dd>


<dt class="option-term" id="option-cargo-run---no-default-features"><a class="option-anchor" href="#option-cargo-run---no-default-features"></a><code>--no-default-features</code></dt>
<dd class="option-desc">不启用给定包的<code>default</code>特性</dd>


</dl>


### Compilation Options

<dl>
Expand All @@ -91,27 +63,19 @@ section of `Cargo.toml` to choose the name of the binary to run by default.
<p>注意,指定该标志参数会使Cargo产生的构建工件放在与平常不同的目录下。
详情参见<a href="../guide/build-cache.html">build cache</a></dd>



<dt class="option-term" id="option-cargo-run--r"><a class="option-anchor" href="#option-cargo-run--r"></a><code>-r</code></dt>
<dt class="option-term" id="option-cargo-run---release"><a class="option-anchor" href="#option-cargo-run---release"></a><code>--release</code></dt>
<dd class="option-desc">Run optimized artifacts with the <code>release</code> profile.
See also the <code>--profile</code> option for choosing a specific profile by name.</dd>



<dt class="option-term" id="option-cargo-run---profile"><a class="option-anchor" href="#option-cargo-run---profile"></a><code>--profile</code> <em>name</em></dt>
<dd class="option-desc">Run with the given profile.
See the <a href="../reference/profiles.html">the reference</a> for more details on profiles.</dd>



<dt class="option-term" id="option-cargo-run---ignore-rust-version"><a class="option-anchor" href="#option-cargo-run---ignore-rust-version"></a><code>--ignore-rust-version</code></dt>
<dd class="option-desc">Run the target even if the selected Rust compiler is older than the
required Rust version as configured in the project's <code>rust-version</code> field.</dd>



</dl>

### Output Options
Expand All @@ -122,7 +86,6 @@ required Rust version as configured in the project's <code>rust-version</code> f
<code>build.target-dir</code> <a href="../reference/config.html">config value</a>指定。</p>
<p>默认情况下为根工作区中的<code>target</code>目录。</dd>


</dl>

### Display Options
Expand All @@ -135,13 +98,11 @@ required Rust version as configured in the project's <code>rust-version</code> f
也可通过<code>term.verbose</code>指定。
<a href="../reference/config.html">config value</a>.</dd>


<dt class="option-term" id="option-cargo-run--q"><a class="option-anchor" href="#option-cargo-run--q"></a><code>-q</code></dt>
<dt class="option-term" id="option-cargo-run---quiet"><a class="option-anchor" href="#option-cargo-run---quiet"></a><code>--quiet</code></dt>
<dd class="option-desc">不输出Cargo的日志信息。也可通过<code>term.quiet</code>指定。
<a href="../reference/config.html">config value</a>.</dd>


<dt class="option-term" id="option-cargo-run---color"><a class="option-anchor" href="#option-cargo-run---color"></a><code>--color</code> <em>when</em></dt>
<dd class="option-desc">控制输出内容的颜色。有效取值如下:</p>
<ul>
Expand All @@ -152,8 +113,6 @@ required Rust version as configured in the project's <code>rust-version</code> f
<p>也可通过<code>term.color</code>指定。
<a href="../reference/config.html">config value</a>.</dd>



<dt class="option-term" id="option-cargo-run---message-format"><a class="option-anchor" href="#option-cargo-run---message-format"></a><code>--message-format</code> <em>fmt</em></dt>
<dd class="option-desc">The output format for diagnostic messages. Can be specified multiple times
and consists of comma-separated values. Valid values:</p>
Expand All @@ -176,8 +135,6 @@ JSON diagnostics coming from rustc. Cargo's own JSON diagnostics and others
coming from rustc are still emitted. Cannot be used with <code>human</code> or <code>short</code>.</li>
</ul></dd>



</dl>

### Manifest Options
Expand All @@ -187,16 +144,13 @@ coming from rustc are still emitted. Cannot be used with <code>human</code> or <
<dt class="option-term" id="option-cargo-run---manifest-path"><a class="option-anchor" href="#option-cargo-run---manifest-path"></a><code>--manifest-path</code> <em>path</em></dt>
<dd class="option-desc">用于指定<code>Cargo.toml</code>文件的路径。默认情况下,Cargo会在当前目录或上级目录中寻找<code>Cargo.toml</code>文件。</dd>



<dt class="option-term" id="option-cargo-run---frozen"><a class="option-anchor" href="#option-cargo-run---frozen"></a><code>--frozen</code></dt>
<dt class="option-term" id="option-cargo-run---locked"><a class="option-anchor" href="#option-cargo-run---locked"></a><code>--locked</code></dt>
<dd class="option-desc">这两个选项用于保证<code>Cargo.lock</code>文件是最新的。如果该锁文件不存在,或者不是最新的,Cargo
会报错退出。其中<code>--frozen</code>选项会阻止Cargo访问网络以检查锁文件是否是最新的。</p>
<p>这些选项,可用于保证<code>Cargo.lock</code>文件是最新的(比如持续集成的构建过程),
或用于避免联网。</dd>


<dt class="option-term" id="option-cargo-run---offline"><a class="option-anchor" href="#option-cargo-run---offline"></a><code>--offline</code></dt>
<dd class="option-desc">禁止Cargo访问网络。如果不添加此选项,Cargo在需要访问网络但网络不可用的情况下,会报错
并停止工作。添加此选项后,Cargo会尽可能尝试不使用网络来工作。</p>
Expand All @@ -205,8 +159,6 @@ Cargo只会使用本地已下载的crate,即便本地的索引副本中表明
所需依赖的方法,参见 <a href="cargo-fetch.html">cargo-fetch(1)</a> 。</p>
<p>也可以通过 <code>net.offline</code> <a href="../reference/config.html">config value</a>指定。</dd>



</dl>

### Common Options
Expand All @@ -220,19 +172,15 @@ as <code>+stable</code> or <code>+nightly</code>).
See the <a href="https://rust-lang.github.io/rustup/overrides.html">rustup documentation</a>
for more information about how toolchain overrides work.</dd>


<dt class="option-term" id="option-cargo-run--h"><a class="option-anchor" href="#option-cargo-run--h"></a><code>-h</code></dt>
<dt class="option-term" id="option-cargo-run---help"><a class="option-anchor" href="#option-cargo-run---help"></a><code>--help</code></dt>
<dd class="option-desc">Prints help information.</dd>


<dt class="option-term" id="option-cargo-run--Z"><a class="option-anchor" href="#option-cargo-run--Z"></a><code>-Z</code> <em>flag</em></dt>
<dd class="option-desc">Unstable (nightly-only) flags to Cargo. Run <code>cargo -Z help</code> for details.</dd>


</dl>


### Miscellaneous Options

<dl>
Expand All @@ -241,29 +189,27 @@ for more information about how toolchain overrides work.</dd>
<dd class="option-desc">要并行运行的作业数量。也可通过<code>build.jobs</code> <a href="../reference/config.html">config value</a>指定。
默认为CPU数量。</dd>


</dl>

## 环境

关于Cargo所读取的环境变量,可参见[the reference](../reference/environment-variables.html)

关于 Cargo 所读取的环境变量,可参见[the reference](../reference/environment-variables.html)

## 退出状态

* `0`: Cargo命令执行成功
* `101`: Cargo命令未能完成.

- `0`: Cargo 命令执行成功
- `101`: Cargo 命令未能完成.

## EXAMPLES

1. Build the local package and run its main target (assuming only one binary):

cargo run
cargo run

2. Run an example with extra arguments:

cargo run --example exname -- --exoption exarg1 exarg2
cargo run --example exname -- --exoption exarg1 exarg2

## SEE ALSO

[cargo(1)](cargo.html), [cargo-build(1)](cargo-build.html)

0 comments on commit 9fa2c68

Please sign in to comment.