Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: work with 4.8.3 * test: fix test compilation * chore: refine solution
- Loading branch information
1 parent
2038ad4
commit 2f09a72
Showing
13 changed files
with
190 additions
and
157 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
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
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,82 @@ | ||
import stripAnsi = require('strip-ansi') | ||
|
||
import {Interfaces, toCached} from '../../src' | ||
import {Help, CommandHelp} from '../../src/help' | ||
|
||
export class TestCommandHelp extends CommandHelp { | ||
protected sections() { | ||
const sections = super.sections() | ||
const flagSection = sections.find(section => section.header === 'FLAGS') | ||
if (flagSection) flagSection.header = 'OPTIONS' | ||
return sections | ||
} | ||
} | ||
|
||
// extensions to expose method as public for testing | ||
export class TestHelpWithOptions extends Help { | ||
CommandHelpClass = TestCommandHelp | ||
|
||
constructor(config: Interfaces.Config, opts: Partial<Interfaces.HelpOptions> = {}) { | ||
super(config, opts) | ||
this.opts.showFlagNameInTitle = true | ||
this.opts.showFlagOptionsInTitle = true | ||
this.opts.hideCommandSummaryInDescription = true | ||
} | ||
|
||
public formatCommand(command: Interfaces.Command) { | ||
return super.formatCommand(command) | ||
} | ||
} | ||
|
||
// extensions to expose method as public for testing | ||
export class TestHelp extends Help { | ||
public formatCommand(command: Interfaces.Command) { | ||
return super.formatCommand(command) | ||
} | ||
|
||
public formatTopics(topics: Interfaces.Topic[]) { | ||
return super.formatTopics(topics) | ||
} | ||
|
||
public formatTopic(topic: Interfaces.Topic) { | ||
return super.formatTopic(topic) | ||
} | ||
} | ||
|
||
export const commandHelp = (command?: any) => ({ | ||
async run(ctx: {help: TestHelp; commandHelp: string; expectation: string}) { | ||
const cached = await toCached(command!, {} as any) | ||
const help = ctx.help.formatCommand(cached) | ||
if (process.env.TEST_OUTPUT === '1') { | ||
console.log(help) | ||
} | ||
|
||
ctx.commandHelp = stripAnsi(help).split('\n').map(s => s.trimEnd()).join('\n') | ||
ctx.expectation = 'has commandHelp' | ||
}, | ||
}) | ||
|
||
export const topicsHelp = (topics: Interfaces.Topic[]) => ({ | ||
run(ctx: {help: TestHelp; commandHelp: string; expectation: string}) { | ||
const topicsHelpOutput = ctx.help.formatTopics(topics) || '' | ||
|
||
if (process.env.TEST_OUTPUT === '1') { | ||
console.log(topicsHelpOutput) | ||
} | ||
|
||
ctx.commandHelp = stripAnsi(topicsHelpOutput).split('\n').map(s => s.trimEnd()).join('\n') | ||
ctx.expectation = 'has topicsHelp' | ||
}, | ||
}) | ||
|
||
export const topicHelp = (topic: Interfaces.Topic) => ({ | ||
run(ctx: {help: TestHelp; commandHelp: string; expectation: string}) { | ||
const topicHelpOutput = ctx.help.formatTopic(topic) | ||
if (process.env.TEST_OUTPUT === '1') { | ||
console.log(topicHelpOutput) | ||
} | ||
|
||
ctx.commandHelp = stripAnsi(topicHelpOutput).split('\n').map(s => s.trimEnd()).join('\n') | ||
ctx.expectation = 'has topicHelp' | ||
}, | ||
}) |
Oops, something went wrong.