Skip to content

Add cargo add instruction to crate-sidebar #5875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion app/components/crate-sidebar.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,23 @@
<div>
<h2 local-class="heading">Install</h2>

<p local-class="copy-help">Add the following line to your Cargo.toml file:</p>
<p local-class="copy-help">Run the following Cargo command in your project directory:</p>
{{#if (is-clipboard-supported)}}
<CopyButton
@copyText={{this.cargoAddCommand}}
title="Copy command to clipboard"
local-class="copy-button"
>
<span>{{this.cargoAddCommand}}</span>
{{svg-jar "copy" aria-hidden="true" local-class="copy-icon"}}
</CopyButton>
{{else}}
<code local-class="copy-fallback">
{{this.cargoAddCommand}}
</code>
{{/if}}

<p local-class="copy-help">Or add the following line to your Cargo.toml:</p>
{{#if (is-clipboard-supported)}}
<CopyButton
@copyText={{this.tomlSnippet}}
Expand Down
6 changes: 6 additions & 0 deletions app/components/crate-sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ export default class CrateSidebar extends Component {
return homepage && (!repository || simplifyUrl(repository) !== simplifyUrl(homepage));
}

get cargoAddCommand() {
return this.args.requestedVersion
? `cargo add ${this.args.crate.name}@${this.args.requestedVersion}`
: `cargo add ${this.args.crate.name}`;
}

get tomlSnippet() {
return `${this.args.crate.name} = "${this.args.version.num}"`;
}
Expand Down
1 change: 1 addition & 0 deletions app/templates/crate/version.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<CrateSidebar
@crate={{this.crate}}
@version={{this.currentVersion}}
@requestedVersion={{this.requestedVersion}}
local-class="sidebar"
/>
</div>
Expand Down