mirror of
https://github.com/flynx/argv.js.git
synced 2025-12-17 17:11:39 +00:00
added support for electron packaged apps...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
cb56060d4c
commit
8c4846c46b
25
argv.js
25
argv.js
@ -415,6 +415,9 @@ object.Constructor('Parser', {
|
|||||||
|
|
||||||
packageJson: undefined,
|
packageJson: undefined,
|
||||||
|
|
||||||
|
hideExt: /\.exe$/,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// instance stuff...
|
// instance stuff...
|
||||||
// XXX do we need all three???
|
// XXX do we need all three???
|
||||||
@ -1150,13 +1153,11 @@ object.Constructor('Parser', {
|
|||||||
// all the parse data...
|
// all the parse data...
|
||||||
// NOTE: this (i.e. parser) can be used as a nested command/option
|
// NOTE: this (i.e. parser) can be used as a nested command/option
|
||||||
// handler...
|
// handler...
|
||||||
//
|
|
||||||
// XXX need to get the name of the command define in package.json's
|
|
||||||
// run key...
|
|
||||||
__call__: function(context, argv, main, root_value){
|
__call__: function(context, argv, main, root_value){
|
||||||
var that = this
|
var that = this
|
||||||
var parsed = Object.create(this)
|
var parsed = Object.create(this)
|
||||||
var opt_pattern = parsed.optionInputPattern
|
var opt_pattern = parsed.optionInputPattern
|
||||||
|
|
||||||
// prep argv...
|
// prep argv...
|
||||||
var rest = parsed.rest =
|
var rest = parsed.rest =
|
||||||
argv == null ?
|
argv == null ?
|
||||||
@ -1167,17 +1168,29 @@ object.Constructor('Parser', {
|
|||||||
parsed.argv = rest.slice()
|
parsed.argv = rest.slice()
|
||||||
main = main
|
main = main
|
||||||
|| (require.main || {}).filename
|
|| (require.main || {}).filename
|
||||||
// || parsed.argv[1]
|
|| this.script
|
||||||
// nested command handler...
|
// nested handler...
|
||||||
var nested = parsed.parent = false
|
var nested = parsed.parent = false
|
||||||
if(context instanceof Parser){
|
if(context instanceof Parser){
|
||||||
nested = parsed.parent = context
|
nested = parsed.parent = context
|
||||||
main = context.scriptName +' '+ main
|
main = context.scriptName +' '+ main
|
||||||
rest.unshift(main) }
|
rest.unshift(main)
|
||||||
|
// electron packaged app root -- no script included...
|
||||||
|
} else if(main
|
||||||
|
&& rest[1] != main
|
||||||
|
// both paths can be relative...
|
||||||
|
&& path.resolve(process.cwd(), rest[1])
|
||||||
|
!= path.resolve(process.cwd(), main)){
|
||||||
|
main = (this.hideExt && this.hideExt.test(rest[0])) ?
|
||||||
|
// remove ext...
|
||||||
|
rest[0].replace(this.hideExt, '')
|
||||||
|
: rest[0]
|
||||||
|
rest.splice(1, 0, rest[0]) }
|
||||||
// normalize the argv...
|
// normalize the argv...
|
||||||
if(main != null && rest[0] == process.execPath){
|
if(main != null && rest[0] == process.execPath){
|
||||||
rest.splice(0, 2)
|
rest.splice(0, 2)
|
||||||
rest.unshift(main) }
|
rest.unshift(main) }
|
||||||
|
|
||||||
// script stuff...
|
// script stuff...
|
||||||
var script = parsed.script = rest.shift()
|
var script = parsed.script = rest.shift()
|
||||||
var basename = script.split(/[\\\/]/).pop()
|
var basename = script.split(/[\\\/]/).pop()
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ig-argv",
|
"name": "ig-argv",
|
||||||
"version": "2.16.1",
|
"version": "2.16.2",
|
||||||
"description": "simple argv parser",
|
"description": "simple argv parser",
|
||||||
"main": "argv.js",
|
"main": "argv.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user