Skip to content
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

CLI improvements #26

Open
lights0123 opened this issue May 7, 2020 · 0 comments
Open

CLI improvements #26

lights0123 opened this issue May 7, 2020 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@lights0123
Copy link

lights0123 commented May 7, 2020

Now that I've started writing my own cargo subcommand as you recommended on the forums, I thought I'd share some of my findings.

// TODO: Add highlighting

You can pass --message-format=json-render-diagnostics instead of just --message-format=json. Then, all warnings will be printed to cargo's stderr with proper formatting, and you can just inherit that to do syntax highlighting.

// Return build artifact

Instead of just grabbing the last artifact, you should grab everything where target.executable exists for when there's multiple binaries, such as in workspaces:

{
  "reason": "compiler-artifact",
  "package_id": "hello-world 1.0.2 (path+file:///path/to/hello-world)",
  "target": {
    "kind": [
      "bin" // Right here
    ],
    "crate_types": [
      "bin"
    ],
    "name": "hello-world",
    "src_path": "/path/to/hello-world/src/main.rs",
    "edition": "2018",
    "doctest": false
  },
  "profile": {
    "opt_level": "0",
    "debuginfo": 2,
    "debug_assertions": true,
    "overflow_checks": true,
    "test": false
  },
  "features": [],
  "filenames": [
    "/path/to/hello-world"
  ],
  "executable": "/path/to/hello-world", // Right here
  "fresh": false
}

You can use cargo_metadata to do that parsing, or whatever JSON parser.

Another thing is that you're requiring the user to pass in a few parameters. What I like to do instead is use the [metadata] section of the Cargo.toml to store that data, so you don't have to keep passing it in. Just thought I'd mention it.

@parasyte parasyte added enhancement New feature or request good first issue Good for newcomers labels May 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants