-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Replace commander with yargs (#872)
- Loading branch information
1 parent
682c544
commit fb86cad
Showing
7 changed files
with
105 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,55 @@ | ||
/* eslint-disable no-console */ | ||
import * as program from 'commander'; | ||
import * as yargs from 'yargs'; | ||
import { generateLicence } from './generateLicense'; | ||
|
||
const oneDayInMs = 1000 * 60 * 60 * 24; | ||
|
||
export function licenseGenCli(args: any) { | ||
program | ||
.option('-o, --order <order>', 'Order number id') | ||
.option('-e, --expiry <expiry>', 'Number of days from now until expiry date', '366') | ||
.action(() => { | ||
if (!program.order) { | ||
throw new Error( | ||
'Material-UI: You forgot to pass an order number. $ > licensegen -o order_123.', | ||
); | ||
} | ||
interface HandlerArgv { | ||
order: string; | ||
expiry: string; | ||
} | ||
|
||
const licenseDetails = { | ||
expiryDate: new Date(new Date().getTime() + parseInt(program.expiry, 10) * oneDayInMs), | ||
orderNumber: program.order, | ||
}; | ||
export function licenseGenCli() { | ||
yargs | ||
.command({ | ||
command: '$0', | ||
describe: 'Generates Component.propTypes from TypeScript declarations', | ||
builder: (command) => { | ||
return command | ||
.option('order', { | ||
default: '', | ||
describe: 'Order number id.', | ||
type: 'string', | ||
}) | ||
.option('expiry', { | ||
default: '366', | ||
describe: 'Number of days from now until expiry date.', | ||
type: 'string', | ||
}); | ||
}, | ||
handler: (argv: HandlerArgv) => { | ||
if (!argv.order) { | ||
throw new Error( | ||
'Material-UI: You forgot to pass an order number. $ > licensegen -o order_123.', | ||
); | ||
} | ||
|
||
console.log( | ||
`Generating new license number for order ${ | ||
licenseDetails.orderNumber | ||
} with expiry date ${licenseDetails.expiryDate.toLocaleDateString()}`, | ||
); | ||
const license = generateLicence(licenseDetails); | ||
console.log(`New license: \n${license}`); | ||
const licenseDetails = { | ||
expiryDate: new Date(new Date().getTime() + parseInt(argv.expiry, 10) * oneDayInMs), | ||
orderNumber: argv.order, | ||
}; | ||
|
||
console.log( | ||
`Generating new license number for order ${ | ||
licenseDetails.orderNumber | ||
} with expiry date ${licenseDetails.expiryDate.toLocaleDateString()}`, | ||
); | ||
const license = generateLicence(licenseDetails); | ||
console.log(`New license: \n${license}`); | ||
}, | ||
}) | ||
.parse(args); | ||
.help() | ||
.strict(true) | ||
.version(false) | ||
.parse(); | ||
} |
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