oclif: The Open CLI Framework
  • Getting Started
  • API Reference
  • Blog
  • GitHub

›How to

Getting Started

  • Introduction
  • Features
  • FAQs
  • Generator Commands

Architecture

  • Command Execution
  • Plugin Loading

API Reference

  • Commands
  • Command Arguments
  • Command Flags
  • Configuration
  • Topics
  • Topic Separators
  • Hooks
  • Plugins
  • Help Classes
  • Error Handling
  • JSON

How to

  • Release
  • Testing
  • Running Commands Programmatically
  • Aliases
  • Custom Base Class
  • Prompting
  • Spinner
  • Table
  • Notifications
  • Debugging
  • Flexible Taxonomy
  • Global Flags
  • Single Command CLI
  • ESM

Also See

  • Examples
  • External Links
  • Related Repositories
  • How We Work
  • Feedback
Edit

Global Flags

There are some instances where you might want to define a flag once for all of your commands. In this case you can add a global flag to an abstract base Command class. For example,

import { Command, Flags } from '@oclif/core';

export abstract class BaseCommand extends Command {
  static baseFlags = {
    interactive: Flags.boolean({
      char: 'i',
      description: 'Run command in interactive mode',
    }),
  };
}

Any command that extends BaseCommand will now have an --interactive flag on it.

Last updated on 2/22/2023
← Flexible TaxonomySingle Command CLI →
Made with 💜 by Salesforce — MIT License