-
Notifications
You must be signed in to change notification settings - Fork 620
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8883 from Turbo87/install-snippet
Show `cargo install` for crates with binaries
- Loading branch information
Showing
8 changed files
with
179 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
{{#if @binNames}} | ||
{{#if (is-clipboard-supported)}} | ||
<CopyButton | ||
@copyText={{this.cargoInstallCommand}} | ||
title="Copy command to clipboard" | ||
local-class="copy-button" | ||
> | ||
<span local-class="selectable">{{this.cargoInstallCommand}}</span> | ||
{{svg-jar "copy" aria-hidden="true" local-class="copy-icon"}} | ||
</CopyButton> | ||
{{else}} | ||
<code local-class="copy-fallback"> | ||
{{this.cargoInstallCommand}} | ||
</code> | ||
{{/if}} | ||
|
||
<p local-class="copy-help"> | ||
{{#if (eq @binNames.length 1)}} | ||
Running the above command will globally install the | ||
<span local-class="bin-name">{{get @binNames 0}}</span> | ||
binary. | ||
{{else if (eq @binNames.length 2)}} | ||
Running the above command will globally install the | ||
<span local-class="bin-name">{{get @binNames 0}}</span> | ||
and | ||
<span local-class="bin-name">{{get @binNames 1}}</span> | ||
binaries. | ||
{{else}} | ||
Running the above command will globally install these binaries: | ||
{{#each @binNames as |binName index|~}} | ||
{{~#if (eq index 0)~}} | ||
<span local-class="bin-name">{{binName}}</span> | ||
{{~else if (eq index (sum @binNames.length -1))}} | ||
and <span local-class="bin-name">{{binName}}</span> | ||
{{~else~}} | ||
, <span local-class="bin-name">{{binName}}</span> | ||
{{~/if}} | ||
{{~/each}} | ||
{{/if}} | ||
</p> | ||
|
||
{{/if}} | ||
|
||
{{#if (and @hasLib @binNames)}} | ||
<h3>Install as library</h3> | ||
{{/if}} | ||
|
||
{{#if @hasLib}} | ||
<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 local-class="selectable">{{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}} | ||
title="Copy Cargo.toml snippet to clipboard" | ||
local-class="copy-button" | ||
> | ||
<span local-class="selectable">{{this.tomlSnippet}}</span> | ||
{{svg-jar "copy" aria-hidden="true" local-class="copy-icon"}} | ||
</CopyButton> | ||
{{else}} | ||
<code local-class="copy-fallback"> | ||
{{this.tomlSnippet}} | ||
</code> | ||
{{/if}} | ||
{{/if}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Component from '@glimmer/component'; | ||
|
||
export default class InstallInstructions extends Component { | ||
get cargoInstallCommand() { | ||
return this.args.exactVersion | ||
? `cargo install ${this.args.crate}@${this.args.version}` | ||
: `cargo install ${this.args.crate}`; | ||
} | ||
|
||
get cargoAddCommand() { | ||
return this.args.exactVersion | ||
? `cargo add ${this.args.crate}@=${this.args.version}` | ||
: `cargo add ${this.args.crate}`; | ||
} | ||
|
||
get tomlSnippet() { | ||
let version = this.args.version.split('+')[0]; | ||
let exact = this.args.exactVersion ? '=' : ''; | ||
return `${this.args.crate} = "${exact}${version}"`; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
app/components/crate-sidebar/install-instructions.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
.copy-help { | ||
font-size: 12px; | ||
overflow-wrap: break-word; | ||
} | ||
|
||
.copy-button, | ||
.copy-fallback { | ||
display: flex; | ||
width: 100%; | ||
align-items: center; | ||
justify-content: space-between; | ||
padding: var(--space-2xs) var(--space-xs); | ||
font-family: var(--font-monospace); | ||
font-size: 14px; | ||
line-height: 1.5em; | ||
color: var(--main-color); | ||
background: transparent; | ||
border-radius: var(--space-3xs); | ||
border: solid var(--space-4xs) var(--gray-border); | ||
|
||
span { | ||
flex: auto; | ||
display: block; | ||
word-break: break-word; | ||
} | ||
} | ||
|
||
.copy-button { | ||
text-align: start; | ||
cursor: pointer; | ||
|
||
&:hover { | ||
background-color: light-dark(white, #141413); | ||
} | ||
} | ||
|
||
.copy-icon { | ||
flex-shrink: 0; | ||
height: 1.1em; | ||
width: auto; | ||
/* for slightly nicer alignment... */ | ||
margin-top: -3px; | ||
margin-left: var(--space-2xs); | ||
opacity: 0; | ||
transition: opacity var(--transition-fast); | ||
|
||
.copy-button:hover & { | ||
opacity: 1; | ||
} | ||
} | ||
|
||
.selectable { | ||
user-select: text; | ||
} | ||
|
||
.bin-name { | ||
font-family: var(--font-monospace); | ||
font-weight: bold; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { helper } from '@ember/component/helper'; | ||
|
||
export default helper(function ([...values]) { | ||
return values.reduce((a, b) => a + b, 0); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters