swpm icon indicating copy to clipboard operation
swpm copied to clipboard

Adding additional info utilities

Open joshmeads opened this issue 1 year ago • 1 comments

Hey, this PR just adds some extra info methods that I needed personally for some CI pipelines. I've separated the data fetching logic from the rendering logic to avoid repeat work.

Hope it helps!

swpm --info --json will return the info spec in JSON format

> swpm --info --json`
{
  "_": "npm",
  "using": "npm",
  "error": null,
  "ready": true,
  "origin": "pinned",
  "volta": true,
  "versions": {
    "swpm": "2.6.0",
    "node": "20.9.0",
    "npm": "10.2.1"
  }
}

If you pass a value to info it'll pick that value back.

> swpm --info=using
npm

> swpm --info origin
pinned

> swpm --info versions.node
20.9.0

> swpm --info brokenSelection
Invalid value - brokenSelection doesn't match any available value
using:  npm 
origin: 📌 pinned 
volta:  ⚡ detected 

Versions:
swpm:   2.6.0
Node:   20.9.0
npm:    10.2.1

The final brokenSelection example will run exit(1)

No value renders the same CLI output as previous.

> swpm --info
using:  npm 
origin: 📌 pinned 
volta:  ⚡ detected 

Versions:
swpm:   2.6.0
Node:   20.9.0
npm:    10.2.1

joshmeads avatar Apr 04 '24 03:04 joshmeads

Hi @joshmeads I'm actually running out of time, but I will try to take a look at it this weekend.

equiman avatar Apr 04 '24 19:04 equiman