Convert Figma logo to code with AI

oclif logooclif

CLI for generating, building, and releasing oclif CLIs. Built by Salesforce.

8,977
314
8,977
11

Top Related Projects

37,027

GitHub’s official command line tool

37,918

A Commander for modern Go CLI interactions

5,905

:vertical_traffic_light: An extensible linter for the TypeScript language

11,076

yargs the modern, pirate-themed successor to optimist.

Quick Overview

oclif (Open CLI Framework) is a powerful Node.js framework for building command-line interfaces (CLIs). It provides a robust set of tools and utilities to create complex, multi-command CLIs with ease, supporting both single and multi-command architectures.

Pros

  • Easy to use and quick to set up, with a comprehensive CLI generator
  • Extensive plugin system for adding functionality and sharing code between CLIs
  • Automatic documentation generation and command help
  • Built-in testing framework and CI support

Cons

  • Steeper learning curve for developers new to CLI development
  • Limited customization options for some built-in features
  • Dependency on Node.js, which may not be suitable for all projects
  • Some users report occasional issues with TypeScript support

Code Examples

  1. Creating a simple command:
import {Command} from '@oclif/core'

export default class Hello extends Command {
  static description = 'Say hello'

  async run() {
    this.log('Hello, world!')
  }
}
  1. Handling command arguments:
import {Command, Args} from '@oclif/core'

export default class Greet extends Command {
  static args = {
    name: Args.string({description: 'Name to greet', required: true})
  }

  async run() {
    const {args} = await this.parse(Greet)
    this.log(`Hello, ${args.name}!`)
  }
}
  1. Using flags in a command:
import {Command, Flags} from '@oclif/core'

export default class Echo extends Command {
  static flags = {
    uppercase: Flags.boolean({char: 'u', description: 'Uppercase the input'})
  }

  static args = {
    input: Args.string({description: 'Text to echo', required: true})
  }

  async run() {
    const {args, flags} = await this.parse(Echo)
    let output = args.input
    if (flags.uppercase) output = output.toUpperCase()
    this.log(output)
  }
}

Getting Started

To create a new oclif project:

npx oclif generate cli-name
cd cli-name
yarn install
./bin/run

To add a new command:

npx oclif generate command command-name

To build and run your CLI:

yarn build
./bin/run

Competitor Comparisons

37,027

GitHub’s official command line tool

Pros of cli

  • Official GitHub CLI tool with deep integration into GitHub's ecosystem
  • Supports a wide range of GitHub-specific operations out of the box
  • Actively maintained by GitHub with frequent updates and improvements

Cons of cli

  • Limited to GitHub-specific functionality, not suitable for general-purpose CLI development
  • Less flexible for creating custom commands compared to oclif's extensible architecture
  • Steeper learning curve for developers not familiar with GitHub's API and concepts

Code Comparison

oclif command structure:

import {Command} from '@oclif/core'

export default class Hello extends Command {
  static description = 'Say hello'

  async run() {
    console.log('Hello, world!')
  }
}

cli command structure:

func helloCmd(cmd *cobra.Command, args []string) error {
    fmt.Println("Hello, world!")
    return nil
}

While both frameworks allow for creating custom commands, oclif provides a more structured approach with TypeScript support, making it easier to develop complex CLIs. cli, being focused on GitHub operations, has a different command structure tailored to its specific use case.

37,918

A Commander for modern Go CLI interactions

Pros of Cobra

  • Written in Go, offering better performance and easier deployment
  • Extensive built-in functionality, including command suggestions and bash completions
  • Large and active community with frequent updates and contributions

Cons of Cobra

  • Steeper learning curve for developers new to Go
  • Less opinionated structure, requiring more manual setup for complex CLIs
  • Limited built-in testing utilities compared to oclif

Code Comparison

Cobra:

var rootCmd = &cobra.Command{
  Use:   "app",
  Short: "A brief description of your application",
  Run: func(cmd *cobra.Command, args []string) {
    // Your code here
  },
}

oclif:

export default class Command extends Command {
  static description = 'A brief description of your command'
  async run() {
    // Your code here
  }
}

Both Cobra and oclif are powerful CLI frameworks, but they cater to different ecosystems and development styles. Cobra excels in performance and built-in features, while oclif offers a more structured approach with TypeScript support and extensive testing utilities. The choice between them often depends on the developer's preferred language (Go vs. JavaScript/TypeScript) and specific project requirements.

5,905

:vertical_traffic_light: An extensible linter for the TypeScript language

Pros of TSLint

  • Specifically designed for TypeScript linting, offering deep integration with TypeScript's type system
  • Extensive rule set tailored for TypeScript best practices and common pitfalls
  • Well-established in the TypeScript ecosystem with a large community and plugin ecosystem

Cons of TSLint

  • Deprecated in favor of ESLint with TypeScript support
  • Less frequent updates and maintenance compared to actively developed projects
  • Limited to TypeScript, not suitable for projects using other languages or mixed codebases

Code Comparison

TSLint configuration example:

{
  "rules": {
    "no-unused-variable": true,
    "no-console": true,
    "semicolon": [true, "always"]
  }
}

Oclif command example:

import { Command } from '@oclif/command'

export default class HelloWorld extends Command {
  async run() {
    console.log('Hello, world!')
  }
}

While not directly comparable in functionality, these snippets showcase the different focus areas of the two projects. TSLint is centered around code quality rules, while Oclif provides a framework for building command-line interfaces.

11,076

yargs the modern, pirate-themed successor to optimist.

Pros of yargs

  • Simpler setup and configuration for basic CLI applications
  • More flexible argument parsing with support for various styles (e.g., POSIX, GNU)
  • Extensive documentation and a large community for support

Cons of yargs

  • Less structured approach for complex, multi-command CLIs
  • Lacks built-in features like automatic help generation and command discovery
  • May require more manual work for advanced CLI functionality

Code Comparison

yargs:

#!/usr/bin/env node
require('yargs')
  .command('serve [port]', 'Start the server', (yargs) => {
    yargs.positional('port', {
      describe: 'Port to bind on',
      default: 5000
    })
  }, (argv) => {
    console.log(`Server started on port ${argv.port}`)
  })
  .argv

oclif:

const {Command, flags} = require('@oclif/command')

class ServeCommand extends Command {
  async run() {
    const {flags} = this.parse(ServeCommand)
    const port = flags.port || 5000
    console.log(`Server started on port ${port}`)
  }
}

ServeCommand.flags = {
  port: flags.integer({char: 'p', description: 'Port to bind on'})
}

module.exports = ServeCommand

Both yargs and oclif are popular libraries for building command-line interfaces in Node.js. yargs offers a more flexible and lightweight approach, suitable for simpler CLI applications. oclif provides a more structured and feature-rich framework, better suited for complex, multi-command CLIs with advanced functionality.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

oclif CLI

Version Downloads/week License

🗒 Description

This is the oclif CLI for the Open CLI Framework, that supports the development of oclif plugins and CLIs.

See the docs for more information.

🚀 Getting Started Tutorial

The Getting Started tutorial is a step-by-step guide to introduce you to oclif. If you have not developed anything in a command line before, this tutorial is a great place to get started.

See Usage below for an overview of the oclif CLI.

📌 Requirements

Currently, Node 18+ is supported. We support the LTS versions of Node. You can add the node package to your CLI to ensure users are running a specific version of Node.

📌 Migrating from V1

If you have been using version 1 of the oclif CLI there are some important differences to note when using the latest version.

Breaking Changes

  • oclif multi, oclif plugin, and oclif single have all been removed in favor of oclif generate, which generates an oclif based CLI using the hello-world example repo.
    • The reason is that there's not enough of a meaningful difference between a "multi command cli", a "single command cli", and a "plugin" to justify the maintenance cost. The generated CLI can be easily used for any of those use cases.
  • oclif hook is now oclif generate:hook
  • oclif command is now oclif generate:command

New Commands

Version 2 now includes all the commands from the oclif-dev CLI. This means that you can now use a single CLI for all your oclif needs. These commands include:

  • oclif manifest
  • oclif pack
  • oclif pack:deb
  • oclif pack:macos
  • oclif pack:win
  • oclif upload (formerly known as oclif-dev publish)
  • oclif upload:deb (formerly known as oclif-dev publish:deb)
  • oclif upload:macos (formerly known as oclif-dev publish:macos)
  • oclif upload:win (formerly known as oclif-dev publish:win)
  • oclif readme

🏗 Usage

Creating a CLI:

$ npx oclif generate mynewcli
? npm package name (mynewcli): mynewcli
$ cd mynewcli
$ ./bin/run.js --version
mynewcli/0.0.0 darwin-x64 node-v9.5.0
$ ./bin/run.js --help
USAGE
  $ mynewcli [COMMAND]

COMMANDS
  hello
  help   display help for mynewcli

$ ./bin/run.js hello world
hello world! (./src/commands/hello/world.ts)

📚 Examples

🔨 Commands

Command Topics

🚀 Contributing

See the contributing guide.

🏭 Related Repositories

  • @oclif/core - Base library for oclif. This can be used directly without the generator.
  • @oclif/test - Test helper for oclif.

🦔 Learn More

NPM DownloadsLast 30 Days