-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: add check command instead of using it as an option (#96)
- Loading branch information
1 parent
b92b15a
commit cd53a8d
Showing
9 changed files
with
233 additions
and
207 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const yargs = require('yargs')(process.argv.slice(2)); | ||
|
||
// https://github.com/yargs/yargs/blob/main/docs/advanced.md#commanddirdirectory-opts | ||
module.exports = yargs | ||
.parserConfiguration({ 'camel-case-expansion': false }) | ||
.commandDir('commands') | ||
.demandCommand() | ||
.help() | ||
.alias('help', 'h') | ||
.argv; |
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,16 @@ | ||
const { check } = require('../src/runner'); | ||
|
||
exports.command = 'check <license>'; | ||
|
||
exports.describe = 'check if a license is SPDX compliant'; | ||
|
||
exports.handler = function (argv) { | ||
const { license } = argv; | ||
|
||
try { | ||
check(license); | ||
} catch (e) { | ||
console.error(e.message); | ||
process.exit(1); | ||
} | ||
}; |
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,42 @@ | ||
const { check } = require('../src/runner'); | ||
|
||
describe('check command', () => { | ||
it('should throw an error if the license is not SPDX compliant', async () => { | ||
const license = 'GPL'; | ||
|
||
let error; | ||
try { | ||
await check(license); | ||
} catch (e) { | ||
error = e; | ||
} finally { | ||
expect(error.message).toMatch(`Error: License "${license}" is not SPDX compliant`); | ||
} | ||
}); | ||
|
||
it('should not throw an error if the license is SPDX compliant', async () => { | ||
const license = 'MIT'; | ||
|
||
let error; | ||
try { | ||
await check(license); | ||
} catch (e) { | ||
error = e; | ||
} finally { | ||
expect(error).toBeUndefined(); | ||
} | ||
}); | ||
|
||
it('should throw an error if the alicense is one of the licenses not supported by the spdx-satisfies module', async () => { | ||
const license = 'GFDL-1.1-invariants-or-later'; | ||
|
||
let error; | ||
try { | ||
await check(license); | ||
} catch (e) { | ||
error = e; | ||
} finally { | ||
expect(error.message).toMatch('GFDL-1.x licenses are temporary unallowed. There\'s an issue pending to be solved. 🙏'); | ||
} | ||
}); | ||
}); |
Oops, something went wrong.