Skip to content

Commit 0358ca9

Browse files
authored
Merge pull request #5875 from stephank/feat-cargo-add
Add `cargo add` instruction to crate-sidebar
2 parents 4dbe357 + cae107b commit 0358ca9

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

app/components/crate-sidebar.hbs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,23 @@
3737
<div>
3838
<h2 local-class="heading">Install</h2>
3939

40-
<p local-class="copy-help">Add the following line to your Cargo.toml file:</p>
40+
<p local-class="copy-help">Run the following Cargo command in your project directory:</p>
41+
{{#if (is-clipboard-supported)}}
42+
<CopyButton
43+
@copyText={{this.cargoAddCommand}}
44+
title="Copy command to clipboard"
45+
local-class="copy-button"
46+
>
47+
<span>{{this.cargoAddCommand}}</span>
48+
{{svg-jar "copy" aria-hidden="true" local-class="copy-icon"}}
49+
</CopyButton>
50+
{{else}}
51+
<code local-class="copy-fallback">
52+
{{this.cargoAddCommand}}
53+
</code>
54+
{{/if}}
55+
56+
<p local-class="copy-help">Or add the following line to your Cargo.toml:</p>
4157
{{#if (is-clipboard-supported)}}
4258
<CopyButton
4359
@copyText={{this.tomlSnippet}}

app/components/crate-sidebar.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ export default class CrateSidebar extends Component {
1414
return homepage && (!repository || simplifyUrl(repository) !== simplifyUrl(homepage));
1515
}
1616

17+
get cargoAddCommand() {
18+
return this.args.requestedVersion
19+
? `cargo add ${this.args.crate.name}@${this.args.requestedVersion}`
20+
: `cargo add ${this.args.crate.name}`;
21+
}
22+
1723
get tomlSnippet() {
1824
return `${this.args.crate.name} = "${this.args.version.num}"`;
1925
}

app/templates/crate/version.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<CrateSidebar
4848
@crate={{this.crate}}
4949
@version={{this.currentVersion}}
50+
@requestedVersion={{this.requestedVersion}}
5051
local-class="sidebar"
5152
/>
5253
</div>

0 commit comments

Comments
 (0)