Easily create CLIs using OCLIF
Case Study: Adobe I/O CLI
src
└── commands
└── giphy
├── index.js
├── random.js
├── search.js
├── translate.js
├── trending.js
└── upload.js
const { Command, flags } = require('@oclif/command')
class RandomCommand extends Command {
async run () {
const { flags, args } = this.parse(RandomCommand)
this.log(`args: ${JSON.stringify(args)}`)
this.log(`flags: ${JSON.stringify(flags)}`)
// TODO: call the Giphy API and get the first random gif
}
}
RandomCommand.description = 'Grabs a random gif from giphy'
RandomCommand.args = [
{
name: 'tag',
description: 'filters results by the specified tag',
required: false
}
]
RandomCommand.flags = {
rating: flags.string({
char: 'r',
description: 'filters results by specified rating',
default: 'g',
options: [ 'y', 'g', 'pg', 'pg-13', 'r' ]
})
}
module.exports = RandomCommand
# ##############################################
# NOTE: Every PLUGIN is also a stand-alone CLI!
# ##############################################
$ ./bin/run giphy:random --help
Grabs a random gif from giphy
USAGE
$ my-cli giphy:random [TAG]
ARGUMENTS
TAG filters results by the specified tag
OPTIONS
-r, --rating=y|g|pg|pg-13|r [default: g] filters results by specified rating
Thank you!