<commit_before>// @flow

import Command, {type Flag, type Arg} from 'cli-engine-command'
import App, {AppFlag, RemoteFlag} from 'cli-engine-command/lib/mixins/app'
import Heroku from 'cli-engine-command/lib/mixins/heroku'

export type LegacyContext = {
  supportsColor: boolean
}

export type LegacyCommand = {
  topic: string,
  command?: string,
  aliases?: string[],
  variableArgs?: boolean,
  args: Arg[],
  flags: Flag[],
  description?: ?string,
  help?: ?string,
  usage?: ?string,
  needsApp?: ?boolean,
  needsAuth?: ?boolean,
  hidden?: ?boolean,
  default?: ?boolean,
  run: (ctx: LegacyContext) => Promise<any>
}

export function convertFromV5 (c: LegacyCommand): Class<Command> {
  if (!c.topic) throw new Error('command has no topic')
  class V5 extends Command {
    static topic = c.topic
    static command = c.command
    static description = c.description
    static hidden = c.hidden
    static args = c.args || []
    static flags = c.flags || []
    static variableArgs = !!c.variableArgs
    static help = c.help

    heroku = new Heroku(this, {required: false})
    app = new App(this, {required: c.needsApp})

    run () {
      const ctx = {
        supportsColor: this.color.enabled,
        auth: {},
        debug: this.config.debug,
        flags: this.flags,
        args: c.variableArgs ? this.argv : this.args,
        app: this.app.name
      }
      ctx.auth.password = <PASSWORD>
      return c.run(ctx)
    }
  }
  if (c.needsApp || c.wantsApp) V5.flags.push(AppFlag, RemoteFlag)
  return V5<commit_msg>Add needsOrg, fixes #12<commit_after>// @flow

import Command, {type Flag, type Arg} from 'cli-engine-command'
import App, {AppFlag, RemoteFlag} from 'cli-engine-command/lib/mixins/app'
import Org, {OrgFlag} from 'cli-engine-command/lib/mixins/org'
import Heroku from 'cli-engine-command/lib/mixins/heroku'

export type LegacyContext = {
  supportsColor: boolean
}

export type LegacyCommand = {
  topic: string,
  command?: string,
  aliases?: string[],
  variableArgs?: boolean,
  args: Arg[],
  flags: Flag[],
  description?: ?string,
  help?: ?string,
  usage?: ?string,
  needsApp?: ?boolean,
  needsAuth?: ?boolean,
  needsOrg?: ?boolean,
  hidden?: ?boolean,
  default?: ?boolean,
  run: (ctx: LegacyContext) => Promise<any>
}

export function convertFromV5 (c: LegacyCommand): Class<Command> {
  if (!c.topic) throw new Error('command has no topic')
  class V5 extends Command {
    static topic = c.topic
    static command = c.command
    static description = c.description
    static hidden = c.hidden
    static args = c.args || []
    static flags = c.flags || []
    static variableArgs = !!c.variableArgs
    static help = c.help

    heroku = new Heroku(this, {required: false})
    app = new App(this, {required: c.needsApp})
    org = new Org(this, {required: c.needsOrg})

    run () {
      const ctx = {
        supportsColor: this.color.enabled,
        auth: {},
        debug: this.config.debug,
        flags: this.flags,
        args: c.variableArgs ? this.argv : this.args,
        app: this.app.name,
        org: this.org.name
      }
      ctx.auth.password = <PASSWORD>
      return c.run(ctx)
    }
  }

  if (c.needsApp || c.wantsApp) V5.flags.push(AppFlag, RemoteFlag)
  if (c.needsOrg || c.wantsOrg) V5.flags.push(OrgFlag)
  return V5
{'fraction_non_alphanumeric': 0.13534743202416918, 'fraction_numerical': 0.003323262839879154, 'mean_word_length': 3.0927070457354757, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1593007', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1079, 'n_words': 294}