-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #230 from oclif/mdonnalley/internals
feat: update internals/api focused docs
- Loading branch information
Showing
14 changed files
with
365 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
title: Flag Inheritance | ||
--- | ||
|
||
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 base flag to an abstract base `Command` class. For example, | ||
|
||
|
||
```typescript | ||
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', | ||
// Show this flag under a separate GLOBAL section in help. | ||
helpGroup: 'GLOBAL', | ||
}), | ||
}; | ||
} | ||
``` | ||
|
||
Any command that extends `BaseCommand` will now have an `--interactive` flag on it. | ||
|
||
If you are going to stack multiple layers of abstract `Command` classes, then you must spread the `baseFlags` to ensure that the flags are properly inherited. For example, | ||
|
||
```typescript | ||
import { Command, Flags } from '@oclif/core'; | ||
|
||
export abstract class FirstBaseCommand extends Command { | ||
static baseFlags = { | ||
interactive: Flags.boolean({ | ||
char: 'i', | ||
description: 'Run command in interactive mode', | ||
// Show this flag under a separate GLOBAL section in help. | ||
helpGroup: 'GLOBAL', | ||
}), | ||
}; | ||
} | ||
|
||
export abstract class SecondBaseCommand extends FirstBaseCommand { | ||
static baseFlags = { | ||
...FirstBaseCommand.baseFlags, | ||
'log-level': Flags.option({ | ||
default: 'info', | ||
description: 'Specify log level', | ||
helpGroup: 'GLOBAL', | ||
options: ['debug', 'warn', 'error', 'info', 'trace'] as const, | ||
summary: 'Specify level for logging.', | ||
char: 'l', | ||
})(), | ||
}; | ||
} | ||
|
||
export abstract class ThirdBaseCommand extends SecondBaseCommand { | ||
static baseFlags = { | ||
...SecondBaseCommand.baseFlags, | ||
verbose: Flags.boolean({ | ||
description: 'Show verbose output.', | ||
char: 'v' | ||
}) | ||
}; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.