Comments (2)
@richburdon thanks for creating the issue. I have a couple of comments
- For the
--json
flag to show up for thestatus
command's help. You need to setstatic flags = {}
. However, I don't like that pattern so I have an incoming PR to make it so you don't need to do that anymore this.parse
is failing because it's parsing the flags forBaseCommand
, which doesn't haveenableJsonFlag
, while executingStatus
, which does haveenableJsonFlag
. So yourinit
method inBaseCommand
needs a way to know which command class to parse
Off the top of my head you could accomplish this by maintaining a map of your command classes, e.g.
const classes: Record<string, typeof Command> = {
Status,
}
export abstract class BaseCommand extends Command {
static _globalFlags = {
config: Flags.string({
description: 'Specify config file',
}),
};
async init(): Promise<void> {
await super.init()
const {flags} = await this.parse(classes[this.constructor.name])
}
}
from core.
Hello Mike -- thanks for the quick response.
Re the --json flag, something very strange happens depending on the order in which flags and enableJsonFlag are declared.
// This works
export default class Status extends BaseCommand {
static enableJsonFlag = true;
static flags = {};
async run (): Promise<{ status: number }> {
return { status: 200 };
}
}
▶ ./bin/dev kube status --help
USAGE
$ dx kube status [--json] [--config <value>]
// This doesn't
export default class Status extends BaseCommand {
static flags = {};
static enableJsonFlag = true;
async run (): Promise<{ status: number }> {
return { status: 200 };
}
}
▶ ./bin/dev kube status --help
USAGE
$ dx kube status [--config <value>]
Re the init/parse. Strangely, calling parse with undefined
works:
async init (): Promise<void> {
await super.init();
const { flags } = await this.parse(undefined); // This works!
const { config: configFile } = flags;
if (fs.existsSync(configFile)) {
this.userConfig = yaml.load(String(fs.readFileSync(configFile))) as any;
}
}
Otherwise I was going to add a new param to the constructor requiring derived classes to pass down their type -- but it seems to me that it was a reasonable thing to want to do in the init method -- and have the framework support this.
I think my suggestion would be to either pass a config object into the constructor, or require a virtual method where this config state is provided. Then the base class and caller can access this information. I feel this is more stable than relying on overloading properties. (Just one view point.)
class MyCommand extends Command {
constructor () {
super({
flags: ...
jsonRequired: ...
})
}
}
Thanks again. RB
from core.
Related Issues (20)
- topicSeparator space generates wrong message when used alongside usage HOT 1
- Upgrading to a version after 3.20.0 causes issues with hooks HOT 3
- (help): show arg/flag options if user didn't provide any HOT 1
- Command summary displays as topic summary when nested below topic without summary. HOT 1
- Unable to run dev.js outside of the project folder
- BaseCommand Documentation HOT 3
- Native support for .env files HOT 1
- bun with oclif not catching unhandled exceptions
- [BUG]The issue of ux.prompt handling special characters. HOT 3
- Can't run development mode with bun HOT 2
- RangeError on ux.table when column starts with emoji HOT 1
- ux.Table: Incorrect parsing of double quotes when exporting to CSV HOT 3
- ux.table `maxWidth` column option HOT 2
- CliUx.ux.prompt text truncation HOT 3
- Build failure with `exactOptionalPropertyTypes` enabled HOT 5
- [Feature request] Alias a single flag to a set of multiple flags HOT 1
- Getting MaxListenersExceededWarning: Possible EventEmitter memory leak detected. after updating to latest version of oclif HOT 2
- Error bundling @oclif/core into my project HOT 15
- UX tables get displayed along with json output on usage of --json flag HOT 2
- Specify different oclif options for dev and run HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from core.