first pass at reorganizing default usage

This commit is contained in:
Shelley Vohr 2017-09-27 14:23:42 -04:00
parent 494000114c
commit 2289d085fa
No known key found for this signature in database
GPG key ID: F13993A75599653C

View file

@ -7,19 +7,16 @@ const url = require('url')
// Parse command line options. // Parse command line options.
const argv = process.argv.slice(1) const argv = process.argv.slice(1)
const option = { file: null, help: null, version: null, abi: null, webdriver: null, modules: [] } const option = { file: null, help: null, default: null, version: null, webdriver: null, modules: [] }
for (let i = 0; i < argv.length; i++) { for (let i = 0; i < argv.length; i++) {
if (argv[i] === '--version' || argv[i] === '-v') { if (argv[i] === '--version' || argv[i] === '-v') {
option.version = true option.version = true
break break
} else if (argv[i] === '--abi') {
option.abi = true
break
} else if (argv[i].match(/^--app=/)) { } else if (argv[i].match(/^--app=/)) {
option.file = argv[i].split('=')[1] option.file = argv[i].split('=')[1]
break break
} else if (argv[i] === '--help' || argv[i] === '-h') { } else if (argv[i] === '--default' || argv[i] === '-d') {
option.help = true option.default = true
break break
} else if (argv[i] === '--interactive' || argv[i] === '-i') { } else if (argv[i] === '--interactive' || argv[i] === '-i') {
option.interactive = true option.interactive = true
@ -327,16 +324,17 @@ if (option.file && !option.webdriver) {
} else if (option.version) { } else if (option.version) {
console.log('v' + process.versions.electron) console.log('v' + process.versions.electron)
process.exit(0) process.exit(0)
} else if (option.abi) { } else if (option.default) {
console.log(process.versions.modules) const indexPath = path.join(__dirname, '/index.html')
process.exit(0) loadApplicationByUrl(`file://${indexPath}`);
} else if (option.help) { } else if (option.interactive) {
const helpMessage = `Electron ${process.versions.electron} - Build cross platform desktop apps with JavaScript, HTML, and CSS startRepl()
} else {
const welcomeMessage = `Electron ${process.versions.electron} - Build cross platform desktop apps with JavaScript, HTML, and CSS
Usage: electron [options] [path] Usage: electron [options] [path]
A path to an Electron app may be specified. The path must be one of the following: A path to an Electron app may be specified. It must be one of the following:
- index.js file. - index.js file.
- Folder containing a package.json file. - Folder containing a package.json file.
- Folder containing an index.js file. - Folder containing an index.js file.
@ -344,16 +342,10 @@ if (option.file && !option.webdriver) {
- http://, https://, or file:// URL. - http://, https://, or file:// URL.
Options: Options:
-h, --help Print this usage message. -d, --default Run the default bundled Electron app.
-i, --interactive Open a REPL to the main process. -i, --interactive Open a REPL to the main process.
-r, --require Module to preload (option can be repeated) -r, --require Module to preload (option can be repeated)
-v, --version Print the version. -v, --version Print the version.`
--abi Print the application binary interface.` console.log(welcomeMessage)
console.log(helpMessage)
process.exit(0) process.exit(0)
} else if (option.interactive) {
startRepl()
} else {
const indexPath = path.join(__dirname, '/index.html')
loadApplicationByUrl(`file://${indexPath}`)
} }