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: add --aliases flag for readme command #925

Merged
merged 3 commits into from Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/commands/readme.ts
Expand Up @@ -30,8 +30,11 @@ Customize the code URL prefix by setting oclif.repositoryPrefix in package.json.
static flags = {
dir: Flags.string({description: 'output directory for multi docs', default: 'docs', required: true}),
multi: Flags.boolean({description: 'create a different markdown page for each topic'}),
aliases: Flags.boolean({description: 'include aliases in the command list', allowNo: true, default: true }),
}

static aliases = ['rdm']
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer to not put an alias on this command unless there's overwhelming demand for it

Copy link
Contributor Author

@shazron shazron Jul 27, 2022

Choose a reason for hiding this comment

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

Me neither, but I will have to figure out another way to test this then...

Copy link
Contributor

Choose a reason for hiding this comment

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

@shazron You can emulate the tests that use the fixtures. For example,

describe('with custom help that does not implement formatCommand', () => {

Basically, you just need to add a CLI with an alias'd command to the fixtures directory and use that for your test case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gotcha, I'll amend the PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mdonnalley I've resolved it to use a custom fixture. However the tests are failing due to AWS_ACCESS_KEY_ID not being set. I assumed the CI would set this in its environment, but it's failing there as well. Those tests are not relevant to this PR and I never touched them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Filed #951


private HelpClass!: HelpBaseDerived

async run(): Promise<void> {
Expand All @@ -55,6 +58,7 @@ Customize the code URL prefix by setting oclif.repositoryPrefix in package.json.

let commands = config.commands
.filter(c => !c.hidden && c.pluginType === 'core')
.filter(c => flags.aliases? true : !c.aliases.includes(c.id))
.map(c => c.id === '.' ? {...c, id: ''} : c)

this.debug('commands:', commands.map(c => c.id).length)
Expand Down
9 changes: 9 additions & 0 deletions test/unit/readme.test.ts
Expand Up @@ -14,6 +14,7 @@ describe('readme', () => {
.it('runs readme', () => {
// expect(fs.readFileSync('README.md', 'utf8')).to.contain('manifest')
expect(fs.readFileSync('README.md', 'utf8')).to.contain('multi')
expect(fs.readFileSync('README.md', 'utf8')).to.contain('## `oclif rdm`')
})

test
Expand All @@ -26,6 +27,14 @@ describe('readme', () => {
expect(fs.readFileSync('README.md', 'utf8')).to.contain('multi')
})

test
.stdout()
.finally(() => fs.writeFile('README.md', readme))
.command(['readme', '--no-aliases'])
.it('runs readme --no-aliases', () => {
expect(fs.readFileSync('README.md', 'utf8')).not.to.contain('## `oclif rdm`')
})

describe('with custom help that implements formatCommand', () => {
const rootPath = path.join(__dirname, '../fixtures/cli-with-custom-help')
const readmePath = path.join(rootPath, 'README.md')
Expand Down