-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: restore short flags for --help and --version (#205)
- Loading branch information
1 parent
f3ee1f8
commit 67dadd4
Showing
7 changed files
with
93 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "help-plugin", | ||
"description": "Module type ESM; Configure help and version flag overrides", | ||
"private": true, | ||
"type": "module", | ||
"files": [], | ||
"oclif": { | ||
"commands": "./src/commands", | ||
"additionalHelpFlags": ["-h", "--mycommandhelp"], | ||
"additionalVersionFlags": ["-v", "myversion", "version"] | ||
} | ||
} |
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,5 @@ | ||
export class Command { | ||
static run() { | ||
console.log('it works!') | ||
} | ||
} |
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,51 @@ | ||
import * as url from 'url' | ||
import * as path from 'path' | ||
|
||
import {Config} from '../../src/config' | ||
|
||
import {expect, fancy} from './test' | ||
import {getHelpFlagAdditions} from '../../src/help' | ||
import {helpAddition, versionAddition} from '../../src/main' | ||
|
||
const root = path.resolve(__dirname, 'fixtures/help') | ||
// const p = (p: string) => path.join(root, p) | ||
|
||
// This tests file URL / import.meta.url simulation. | ||
const rootAsFileURL = url.pathToFileURL(root).toString() | ||
|
||
const withConfig = fancy | ||
.add('config', () => Config.load(rootAsFileURL)) | ||
|
||
describe('help and version flag additions', () => { | ||
withConfig | ||
.it('has help and version additions', ({config}) => { | ||
expect(config.pjson.oclif.additionalHelpFlags).to.have.lengthOf(2) | ||
expect(config.pjson.oclif.additionalVersionFlags).to.have.lengthOf(3) | ||
const mergedHelpFlags = getHelpFlagAdditions(config) | ||
expect(mergedHelpFlags).to.deep.equal(['--help', ...config.pjson.oclif.additionalHelpFlags as string[]]) | ||
expect(helpAddition(['-h'], config)).to.be.true | ||
expect(helpAddition(['help'], config)).to.be.false | ||
expect(helpAddition(['--mycommandhelp'], config)).to.be.true | ||
expect(helpAddition(['foobar'], config)).to.be.false | ||
expect(versionAddition(['-v'], config)).to.be.true | ||
expect(versionAddition(['version'], config)).to.be.true | ||
expect(versionAddition(['myversion'], config)).to.be.true | ||
expect(versionAddition(['notmyversion'], config)).to.be.false | ||
}) | ||
|
||
withConfig | ||
.do(({config}) => delete config.pjson.oclif.additionalHelpFlags) | ||
.it('has version additions', ({config}) => { | ||
expect(config.pjson.oclif.additionalHelpFlags).to.not.be.ok | ||
expect(config.pjson.oclif.additionalVersionFlags).to.have.lengthOf(3) | ||
const mergedHelpFlags = getHelpFlagAdditions(config) | ||
expect(mergedHelpFlags).to.deep.equal(['--help']) | ||
expect(helpAddition(['-h'], config)).to.be.false | ||
expect(helpAddition(['help'], config)).to.be.false | ||
expect(helpAddition(['mycommandhelp'], config)).to.be.false | ||
expect(versionAddition(['-v'], config)).to.be.true | ||
expect(versionAddition(['version'], config)).to.be.true | ||
expect(versionAddition(['myversion'], config)).to.be.true | ||
expect(versionAddition(['notmyversion'], config)).to.be.false | ||
}) | ||
}) |