import {Command, Flags} from '@oclif/core'
      
      export class MyCommand extends Command {
        static description = `description of my command can be multiline`
      
        // hide the command from help
        static hidden = false
      
        // custom usage string for help
        // this overrides the default usage
        static usage = 'mycommand --myflag'
      
        // examples to add to help
        // each can be multiline
        static examples = [
          '$ mycommand --force',
          '$ mycommand --help',
        ]
      
        // this makes the parser not fail when it receives invalid arguments
        // defaults to true
        // set it to false if you need to accept variable arguments
        static strict = false
      
        async run() {
          //Write your business logic 
        this.warn('uh oh!')
          
          // exit with an error message
          this.error('uh oh!!!')
          // exit with status code
          this.exit(1)
        }
      }

      Typescript language logo
      New Command

      oclif
      new-command
      cli
      ...
      Oclif Cookbook

      The MyCommand class extends the Command class. The MyCommand class has a static description which can be multiline. The MyCommand class has a static hidden which can be false or true. The MyCommand class has a static usage which is 'mycommand --myflag'. The MyCommand class has a static examples which can be multiline. The MyCommand class has a static strict which can be false or true. The MyCommand class has an async run() method which can be called. The MyCommand class has a warn() method which can be called. The MyCommand class has an error() method which can be called. The MyCommand class has an exit() method which can be called with a status code of 1.

      Shortcut: oclif.newcommand

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.