Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/commands/duration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @flow

import Command from 'cli-engine-command'
import DurationFlag from '../flags/duration'

export default class extends Command {
static topic = 'cli'
static command = 'duration'
static description = 'this is an example command showing duration parsing'
static flags = {duration: DurationFlag()}

async run () {
this.log('duration:')
this.inspect(this.flags.duration)
}
}
19 changes: 19 additions & 0 deletions src/flags/duration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @flow

import type {Flag} from 'cli-engine-command'

type Options = $Shape<Flag<Date>>

export default function DurationFlag (options: Options = {}, env: typeof process.env = process.env): Flag<Date> {
const defaultOptions: Options = {
description: 'a duration',
parse: (input) => {
if (!input) {
if (options.required) throw new Error('No org specified')
return
}
return new Date(input)
}
}
return Object.assign(defaultOptions, options)
}
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ export const topics = [
{name: 'cli', description: 'example CLI engine topic'}
]

import CLI from './commands/cli'
export const commands = [CLI]
export const commands = [
require('./commands/cli'),
require('./commands/duration')
]
Loading