npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@xyd-js/opencli2go

v0.0.0-build-f0c10f6-20260703195526

Published

Generate a buildable Go CLI (urfave/cli v3) from an OpenCLI document with the x-openapi request binding

Readme

@xyd-js/opencli2go

Generates a buildable, functional Go CLI (urfave/cli v3) from an OpenCLI document (@xyd-js/opencli). It reads the x-openapi request binding (emitted by @xyd-js/openapi2opencli) so the generated commands make real API requests — not stubs.

import { opencli2go, writeProject } from '@xyd-js/opencli2go';

const files = opencli2go(opencliDoc, { binName: 'openai' }); // pure: { path -> contents }
await writeProject(files, './out');                          // the only fs-touching step

Output (mirrors openai-cli's layout)

go.mod
cmd/<bin>/main.go            # root cli.Command{ Commands: [...] } + app.Run
pkg/cmd/<resource>.go        # one per top-level command; New<Resource>Command() + handlers
internal/runtime/runtime.go  # generic HTTP client (vendored verbatim)
internal/runtime/config.go   # generated: base URL + auth from x-openapi

How it works

A templated emitter (fern's CLI-generator pattern), not a Go AST:

  • The recursive cli.Command tree + typed flags are rendered with small Go-literal string helpers; imports are a fixed/known set per file.
  • Each leaf handler is generated from x-openapi: positional path params → url.PathEscape, query params → url.Values, body flags → a map[string]any marshalled to JSON (encodings: int/float/bool/[]string/nested-json), then runtime.Do(ctx, req).
  • Flag types follow the encoding: cli.StringFlag / IntFlag / FloatFlag / BoolFlag / StringSliceFlag.
  • internal/runtime is a small generic HTTP client; config.go bakes the base URL (overridable via <BIN>_BASE_URL) and applyAuth (bearer / apiKey-header / apiKey-query / apiKey-cookie / basic), reading credentials from the env var named in x-openapi.security.

opencli2go is pure (returns a file map); writeProject does the disk IO.

Options

binName (default slug(info.title)), modulePath (default example.com/<binName>), goVersion (default 1.22), baseURL (default first x-openapi.servers).

Tests

Golden multi-file fixtures under __fixtures__/<n>/ (input.json OpenCLI → output/ Go tree):

pnpm --filter @xyd-js/opencli2go test                      # assert against committed goldens (no Go needed)
REGEN=1 pnpm --filter @xyd-js/opencli2go test               # regenerate the output/ trees
O2G_GO_SMOKE=1 pnpm --filter @xyd-js/opencli2go test        # opt-in: go mod tidy && go build ./... && go vet ./...

Known limits (v1)

  • Positional args are read via cmd.Args().Get(i) (functional) rather than declared cli.Arguments; declaring typed args (for --help surface parity with openai-cli) is a Milestone-3 refinement validated against the oracle.
  • multipart/form-data file uploads pass the file path through (not yet streamed).
  • The runtime is generic (untyped JSON in/out); typed response models are future work.