Skip to content

Commit

Permalink
chore: clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Sep 26, 2023
1 parent 57794c3 commit a893f34
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
11 changes: 2 additions & 9 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import {LoadOptions} from './interfaces/config'
import {PJSON} from './interfaces'
import {Plugin} from './interfaces/plugin'
import {PrettyPrintableError} from './errors'
import {boolean} from './flags'
import chalk from 'chalk'
import {fileURLToPath} from 'node:url'
import {json} from './flags'
import {ux} from './cli-ux'

const pjson = requireJson<PJSON>(__dirname, '..', 'package.json')
Expand All @@ -42,13 +42,6 @@ stdout.on('error', (err: any) => {
throw err
})

export const jsonFlag = {
json: boolean({
description: 'Format output as json.',
helpGroup: 'GLOBAL',
}),
}

/**
* An abstract class which acts as the base for each command
* in your project.
Expand Down Expand Up @@ -328,7 +321,7 @@ export abstract class Command {
const opts = {
context: this,
...options,
flags: (options.enableJsonFlag ? {...combinedFlags, ...jsonFlag} : combinedFlags) as FlagInput<F>,
flags: (options.enableJsonFlag ? {...combinedFlags, json} : combinedFlags) as FlagInput<F>,
}

const results = await Parser.parse<F, B, A>(argv, opts)
Expand Down
9 changes: 2 additions & 7 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {join, sep} from 'node:path'
import {Command} from '../command'
import {Performance} from '../performance'
import PluginLoader from './plugin-loader'
import {boolean} from '../flags'
import {format} from 'node:util'
import {getHelpFlagAdditions} from '../help'
import {json} from '../flags'
import {loadWithData} from '../module-loader'
import {settings} from '../settings'
import {stdout} from '../cli-ux/stream'
Expand Down Expand Up @@ -870,12 +870,7 @@ export async function toCached(cmd: Command.Class, plugin?: IPlugin, respectNoCa
const c = mergePrototype(cmd, cmd)

const cmdFlags = {
...(c.enableJsonFlag ? {
json: boolean({
description: 'Format output as json.',
helpGroup: 'GLOBAL',
}),
} : {}),
...(c.enableJsonFlag ? {json} : {}),
...c.flags,
...c.baseFlags,
} as typeof c['flags']
Expand Down
5 changes: 5 additions & 0 deletions src/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,8 @@ export function option<T extends readonly string[], P extends CustomOptions>(
type: 'option',
})
}

export const json = boolean({
description: 'Format output as json.',
helpGroup: 'GLOBAL',
})
27 changes: 26 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
import {
boolean,
custom,
directory,
file,
help,
integer,
option,
string,
url,
version,
} from './flags'
import {stderr} from './cli-ux/stream'

function checkCWD() {
Expand All @@ -14,7 +26,20 @@ checkCWD()

export * as Args from './args'
export * as Errors from './errors'
export * as Flags from './flags'

export const Flags = {
custom,
option,
boolean,
string,
url,
integer,
directory,
file,
help,
version,
}

export * as Interfaces from './interfaces'
export * as Parser from './parser'
export * as ux from './cli-ux'
Expand Down

0 comments on commit a893f34

Please sign in to comment.