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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@gunshi/plugin-global

v0.27.5

Published

global options plugin for gunshi

Readme

@gunshi/plugin-global

Version InstallSize JSR

global options plugin for gunshi.

This plugin provides standard global options (--help and --version) for all commands in your CLI application. It's installed by default in gunshi, ensuring consistent behavior across all CLI applications.

💿 Installation

# npm
npm install --save @gunshi/plugin-global

# pnpm
pnpm add @gunshi/plugin-global

# yarn
yarn add @gunshi/plugin-global

# deno
deno add jsr:@gunshi/plugin-global

# bun
bun add @gunshi/plugin-global

🚀 Usage

import global from '@gunshi/plugin-global'
import { cli } from 'gunshi'

const command = {
  name: 'my-command',
  args: {
    target: {
      type: 'string',
      description: 'Target to process'
    }
  },
  run: ctx => {
    console.log(`Processing ${ctx.values.target}`)
  }
}

await cli(process.argv.slice(2), command, {
  name: 'my-cli',
  version: '1.0.0',
  plugins: [
    global() // Adds --help and --version options
  ]
})

[!TIP] This plugin is installed in gunshi by default. You don't need to explicitly add it unless you've disabled default plugins.

✨ Features

Global Options

This plugin automatically adds the following options to all commands:

  • --help, -h: Display the command usage and available options
  • --version, -v: Display the application version

Automatic Behavior

When these options are used:

  • With --help: The command execution is bypassed, and the usage information is displayed instead
  • With --version: The command execution is bypassed, and only the version number is printed

🧩 Context Extensions

When using the global options plugin, your command context is extended via ctx.extensions['g:global'].

[!IMPORTANT] This plugin extension is namespaced in CommandContext.extensions using this plugin ID g:global by the gunshi plugin system.

Available extensions:

[!NOTE] The Awaitable<T> type used in the method signatures below is equivalent to T | Promise<T>, meaning the methods can return either a value directly or a Promise that resolves to that value.

  • showVersion(): string: Display the application version. Returns 'unknown' if no version is specified in the CLI configuration.

  • showHeader(): Awaitable<string | undefined>: Display the application header. Returns undefined if no renderHeader function is provided in the CLI configuration.

  • showUsage(): Awaitable<string | undefined>: Display the command usage information. This is automatically called when --help is used. Returns undefined if no renderUsage function is provided.

  • showValidationErrors(error: AggregateError): Awaitable<string | undefined>: Display validation errors when argument validation fails. Returns undefined if renderValidationErrors is null.

Usage Example

import global, { pluginId as globalId } from '@gunshi/plugin-global'
import { cli } from 'gunshi'

const command = {
  name: 'deploy',
  run: async ctx => {
    // Access global extensions
    const { showVersion, showHeader } = ctx.extensions[globalId]

    // Manually show version if needed
    console.log(`Deploying with CLI version: ${showVersion()}`)

    // Show custom header
    const header = await showHeader()
    if (header) {
      console.log(header)
    }

    // Your command logic here...
  }
}

await cli(process.argv.slice(2), command, {
  name: 'deploy-cli',
  version: '2.1.0',
  plugins: [global()],

  // Optional: Custom header renderer
  renderHeader: async () => {
    return `
╔══════════════════════╗
║   Deploy CLI v2.1.0  ║
╚══════════════════════╝
`
  }
})

📚 API References

See the API References

©️ License

MIT