Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Improve command line parsing #4

Merged
merged 2 commits into from
Feb 24, 2021
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
36 changes: 29 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,49 @@ npm install -g cargo-cp-artifact
## Usage

```
cargo-cp-artifact [crate-name=artifact-kind=output-file] -- [wrapped-command]
cargo-cp-artifact --artifact artifact-kind crate-name output-file -- wrapped-command
```

`cargo-cp-artifact` accepts a list of crate name and artifact kind to output file mappings and a command to wrap.`cargo-cp-artifact` will read `stdout` of the wrapped command and parse it as [cargo metadata](https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages). Compiler artifacts that match arguments provided will be copied to the target destination.

When wrapping a `cargo` command, it is necessary to include a `json` format to `--message-format`.

### Arguments

Multiple arguments are allowed to copy multiple build artifacts.

#### `--artifact`

_Alias: `-a`_

Followed by *three* arguments: `artifact-kind crate-name output-file`

#### `--npm`

_Alias: `-n`_

Followed by *two* arguments: `artifact-kind output-file`

The crate name will be read from the `npm_package_name` environment variable.

### Artifact Kind

Valid artifact kinds are `bin`, `cdylib`, and `dylib`. They may be abbreviated as `b`, `c`, and `d` respectively.

For example, `-ac` is the equivalent of `--artifact cdylib`.

## Examples

### Wrapping cargo

```sh
cargo-cp-artifact my-crate=cdylib=lib/index.node -- cargo build --message-format=json-render-diagnostics
cargo-cp-artifact -a cdylib my-crate lib/index.node -- cargo build --message-format=json-render-diagnostics
```

### Parsing a file

```sh
cargo-cp-artifact my-crate=cdylib=lib/index.node -- cat build-output.txt
cargo-cp-artifact -a cdylib my-crate lib/index.node -- cat build-output.txt
```

### `npm` script
Expand All @@ -39,17 +63,15 @@ cargo-cp-artifact my-crate=cdylib=lib/index.node -- cat build-output.txt
{
"name": "my-crate",
"scripts": {
"build": "cargo-cp-artifact $npm_package_name=cdylib=lib/index.node -- cargo build --message-format=json-render-diagnostics"
"build": "cargo-cp-artifact -nc lib/index.node -- cargo build --message-format=json-render-diagnostics"
}
}
```

_Note: `cargo-cp-artifact` will interpolate the special name `$npm_package_name` for portability across platforms (e.g., Windows)._

```sh
npm run build

# Additional arguments ma be passed
# Additional arguments may be passed
npm run build -- --feature=serde
```

Expand Down
6 changes: 6 additions & 0 deletions bin/cargo-cp-artifact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env node
"use strict";

const run = require("..")

run(process.argv.slice(2), process.env);
177 changes: 0 additions & 177 deletions index.js

This file was deleted.

Loading