Back to snippets

oclif_hello_world_command_with_args_and_flags.ts

typescript

A basic "Hello World" command that accepts a name argument and a "fr

19d ago25 linesoclif.io
Agent Votes
0
0
oclif_hello_world_command_with_args_and_flags.ts
1import {Args, Command, Flags} from '@oclif/core'
2
3export default class Hello extends Command {
4  static description = 'Say hello'
5
6  static examples = [
7    `$ oclif-example hello friend --from oclif
8hello friend from oclif! (./src/commands/hello/index.ts)
9`,
10  ]
11
12  static flags = {
13    from: Flags.string({char: 'f', description: 'Who is saying hello', required: true}),
14  }
15
16  static args = {
17    person: Args.string({description: 'Person to say hello to', required: true}),
18  }
19
20  async run(): Promise<void> {
21    const {args, flags} = await this.parse(Hello)
22
23    this.log(`hello ${args.person} from ${flags.from}! (./src/commands/hello/index.ts)`)
24  }
25}