• This repository has been archived on 22/Aug/2023
  • Stars
    star
    136
  • Rank 258,140 (Top 6 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

oclif base command

@oclif/command

This library been replaced by @oclif/core and is now in maintenance mode. We will only consider PRs that address security concerns.

oclif base command

Version CircleCI Appveyor CI Known Vulnerabilities Downloads/week License

This is about half of the main codebase for oclif. The other half lives in @oclif/config. This can be used directly, but it probably makes more sense to build your CLI with the generator.

Usage

Without the generator, you can create a simple CLI like this:

TypeScript

#!/usr/bin/env ts-node

import * as fs from 'fs'
import {Command, flags} from '@oclif/command'

class LS extends Command {
  static flags = {
    version: flags.version(),
    help: flags.help(),
    // run with --dir= or -d=
    dir: flags.string({
      char: 'd',
      default: process.cwd(),
    }),
  }

  async run() {
    const {flags} = this.parse(LS)
    let files = fs.readdirSync(flags.dir)
    for (let f of files) {
      this.log(f)
    }
  }
}

LS.run()
.catch(require('@oclif/errors/handle'))

JavaScript

#!/usr/bin/env node

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

class LS extends Command {
  async run() {
    const {flags} = this.parse(LS)
    let files = fs.readdirSync(flags.dir)
    for (let f of files) {
      this.log(f)
    }
  }
}

LS.flags = {
  version: flags.version(),
  help: flags.help(),
  // run with --dir= or -d=
  dir: flags.string({
    char: 'd',
    default: process.cwd(),
  }),
}

LS.run()
.catch(require('@oclif/errors/handle'))

Then run either of these with:

$ ./myscript
...files in current dir...
$ ./myscript --dir foobar
...files in ./foobar...
$ ./myscript --version
myscript/0.0.0 darwin-x64 node-v9.5.0
$ ./myscript --help
USAGE
  $ @oclif/command

OPTIONS
  -d, --dir=dir  [default: /Users/jdickey/src/github.com/oclif/command]
  --help         show CLI help
  --version      show CLI version

See the generator for all the options you can pass to the command.

More Repositories

1

oclif

CLI for generating, building, and releasing oclif CLIs. Built by Salesforce.
TypeScript
8,760
star
2

cli-ux

CLI IO utilities
TypeScript
548
star
3

core

Node.js Open CLI Framework. Built by Salesforce.
TypeScript
150
star
4

plugin-autocomplete

autocomplete plugin for oclif
TypeScript
79
star
5

fancy-test

extends mocha with helpful, chainable extensions
TypeScript
60
star
6

dev-cli

TypeScript
60
star
7

example-multi-ts

example multi-command CLI built with typescript
TypeScript
54
star
8

kaomoji

A simple example CLI that generates kaomoji (https://en.wikipedia.org/wiki/Kaomoji)
TypeScript
53
star
9

plugin-plugins

plugins plugin for oclif
TypeScript
44
star
10

plugin-update

add autoupdate to your oclif CLI
TypeScript
44
star
11

plugin-warn-if-update-available

warn user if a new CLI version is available
TypeScript
34
star
12

hello-world

Template repository for generating CJS oclif plugins
TypeScript
27
star
13

parser

arg and flag parser for oclif
TypeScript
24
star
14

config

base config object and standard interfaces for oclif components
TypeScript
24
star
15

plugin-help

standard help for oclif
TypeScript
22
star
16

errors

TypeScript
14
star
17

test

test helpers for oclif components
TypeScript
14
star
18

example-multi-js

example multi-command CLI built with javascript
JavaScript
14
star
19

plugin-not-found

"did you mean" plugin for oclif
TypeScript
12
star
20

example-single-ts

example single command CLI built with oclif
TypeScript
11
star
21

oclif.github.io

docs for oclif
JavaScript
7
star
22

plugin-commands

TypeScript
7
star
23

githubcli

An simple example oclif cli
TypeScript
7
star
24

example-single-js

example single-command CLI built with oclif
JavaScript
7
star
25

screen

get stdout/stderr columns
JavaScript
5
star
26

plugin-which

TypeScript
5
star
27

color

TypeScript
5
star
28

eslint-config-oclif

eslint configuration for oclif
JavaScript
5
star
29

hello-world-esm

Template repository for generating ESM oclif plugins
TypeScript
5
star
30

semantic-release

shared semantic-release config for oclif projects
JavaScript
4
star
31

example-plugin-ts

example oclif plugin in typescript
TypeScript
4
star
32

example-plugin-js

example oclif plugin in javascript
JavaScript
4
star
33

eslint-config-oclif-typescript

eslint config for Typscript'd oclif
JavaScript
3
star
34

repo-status

repo status badges for oclif projects
JavaScript
3
star
35

plugin-search

TypeScript
2
star
36

nyc-config

nyc config for oclif components
2
star
37

plugin-legacy

TypeScript
2
star
38

plugin-version

a cli command that just shows the CLI version
TypeScript
2
star
39

goclif

Go
1
star
40

_dev

metapackage for dxcli dev dependencies
Shell
1
star
41

plugin-example

JavaScript
1
star
42

plugin-svo

Spike using SVO syntax
TypeScript
1
star
43

docker

Dockerfile
1
star
44

tslint

DEPRECATED: use oclif's eslint plugins
Shell
1
star
45

eslint

TypeScript
1
star
46

plugin-command-snapshot

generates and compares OCLIF plugins snapshot files
TypeScript
1
star
47

plugin-test-esbuild

TypeScript
1
star
48

github-workflows

duplicate of https://github.com/salesforcecli/github-workflows
1
star
49

fancy-test-nock

TypeScript
1
star