Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove support for baseFlags #1084

Merged
merged 8 commits into from
May 23, 2024

Conversation

mdonnalley
Copy link
Contributor

Remove support for baseFlags

Currently, in order for one Command class to inherit flags from another Command class is to use a property called baseFlags (see docs).

This solution assumes that you'll only ever have one layer of abstraction, which is not a safe assumption. So in order for commands to inherit flags from multiple parents you have to use the spread operator

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

abstract class BaseCommand1 extends Command {
  static baseFlags = {
    loglevel: Flags.boolean()
  }
}

abstract class BaseCommand2 extends BaseCommand1 {
  static baseFlags = {
    ...BaseCommand1.baseFlags,
    verbose: Flags.boolean()
  }
}

abstract class BaseCommand3 extends BaseCommand2 {
  static baseFlags = {
    ...BaseCommand2.baseFlags,
    silent: Flags.boolean()
  }
}

export default class MyCommand extends BaseCommand3 {
  static flags = {
    username: Flags.string()
  }
}

Because of this, we're removing baseFlags and requiring the spread operator anytime you want flags to be inherited. So the above example would change to this:

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

abstract class BaseCommand1 extends Command {
  static flags = {
    loglevel: Flags.boolean()
  }
}

abstract class BaseCommand2 extends BaseCommand1 {
  static flags = {
    ...BaseCommand1.flags,
    verbose: Flags.boolean()
  }
}

abstract class BaseCommand3 extends BaseCommand2 {
  static flags = {
    ...BaseCommand2.flags,
    silent: Flags.boolean()
  }
}

export default class MyCommand extends BaseCommand3 {
  static flags = {
    ...BaseCommand3.flags,
    username: Flags.string()
  }
}

The downside is that it will require an extra line of code for those who are only using a single base Command class but the upside is that there won't be any confusion about the difference between baseFlags and flags and when to use each.

Other Changes

@W-15470630@

import {expect} from 'chai'
import {resolve} from 'node:path'
import {pathToFileURL} from 'node:url'

import {runCommand} from '../test'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do this change? @cristiand391 and I struggled to reverse this in jsforce?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WillieRuemmele I'm not sure what you mean. This change is to use the new major of oclif/test (which I originally wrote as POC inside ../test). Not sure how it relates to jsforce


import {Command, Flags} from '../../src'
// import Cache from '../../src/cache'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably clean this at L11 up

Copy link
Contributor

@WillieRuemmele WillieRuemmele left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a major bump in pjson, or in commit messages - did I miss it?

@mdonnalley
Copy link
Contributor Author

I don't see a major bump in pjson, or in commit messages - did I miss it?

This is going into the prerelease/beta branch which has the major version bump in it

@WillieRuemmele WillieRuemmele merged commit 98bd316 into prerelease/beta May 23, 2024
40 of 84 checks passed
@WillieRuemmele WillieRuemmele deleted the mdonnalley/no-base-flags branch May 23, 2024 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants