Skip to content

Instantly share code, notes, and snippets.

View kenanchristian's full-sized avatar
👋

Christian Dimas kenanchristian

👋
View GitHub Profile
@kenanchristian
kenanchristian / keybase.md
Created April 13, 2020 01:09
Keybase Proof

Keybase proof

I hereby claim:

  • I am kenanchristian on github.

  • I am kenanchristian (https://keybase.io/kenanchristian) on keybase.

  • I have a public key ASC_HpN80L9Eb82i_Ih4XDrKnxlKCg4wF1v5nm4KJ6_zNQo

@kenanchristian
kenanchristian / hello.ts
Last active September 21, 2020 06:39
[[Typescript CLI] Starting Code] Code generated by OCLIF framework #oclif #cli #writing
import {Command, flags} from '@oclif/command'
export default class Hello extends Command {
static description = 'describe the command here'
static examples = [
`$ pizza hello
hello world from ./src/hello.ts!
`,
]
import {Command, flags} from '@oclif/command'
export default class Create extends Command {
static description = 'Create a new Pizza'
static examples = [
`$ pizza create
Your pizza is ready!
`,
]
@kenanchristian
kenanchristian / interactive-create.ts
Last active September 21, 2020 06:46
[[TypeScript CLI] Making the CLI Interactive] #cli #oclif
import {Command, flags} from '@oclif/command'
import {prompt} from 'inquirer'
export default class Create extends Command {
static description = 'Create a new Pizza'
static examples = [
`$ pizza create
Your pizza is ready!
`,
/* eslint-disable no-await-in-loop */
import {Command, flags} from '@oclif/command'
import {prompt} from 'inquirer'
import {SingleBar, Presets} from 'cli-progress'
import {yellow, green, cyan} from 'chalk'
import {sleep} from '../lib/util'
interface PizzaData {
crust: string;
toppings: string[];
static description = 'Create a new Pizza'
static examples = [
`$ pizza create
Your pizza is ready!
`,
]
static flags = {
help: flags.help({char: 'h'}),
crust: flags.string({char: 'c', description: 'Type of Crust (Thin/Thick)'}),
toppings: flags.string({char: 't', description: 'Toppings to add', options: ['pepperoni', 'mushroom', 'bacon', 'pineapple'], multiple: true}),
extraSauce: flags.boolean({char: 'x', description: 'Do you want extra sauce?'}),
}
static args = [
{
name: 'count',
async run() {
const {args, flags} = this.parse(Create)
this.log(JSON.stringify(args))
this.log(JSON.stringify(flags))
this.log('Your pizza is ready!')
}
import { prompt } from 'inquirer'
...
async run() {
const userInput = prompt([
{
type: 'number',
name: 'count',
@kenanchristian
kenanchristian / optional-interactive.ts
Last active September 21, 2020 06:47
[[TypeScript CLI] Make Interactive Mode Optional] #cli #oclif
...
async getInteractiveArgs() {
const answer = await prompt([
{
type: 'number',
name: 'count',
message: 'How many pizza you want to create',
default: 1,
validate(value) {