Skip to content

Commit

Permalink
feat: add app.commandLine.hasSwitch() / app.commandLine.getSwitchValue()
Browse files Browse the repository at this point in the history
  • Loading branch information
miniak committed Jan 5, 2019
1 parent 959c7a7 commit 6c74e6b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/api/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,20 @@ correctly.

**Note:** This will not affect `process.argv`.

### `app.commandLine.hasSwitch(switch)`

* `switch` String - A command-line switch

Returns `Boolean` - Whether the command-line switch is present.

### `app.commandLine.getSwitchValue(switch)`

* `switch` String - A command-line switch

Returns `String` - The command-line switch value.

**Note:** When the switch is not present, it returns empty string.

### `app.enableSandbox()` _Experimental_ _macOS_ _Windows_

Enables full sandbox mode on the app.
Expand Down
1 change: 1 addition & 0 deletions lib/browser/api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Object.assign(app, {
return Menu.getApplicationMenu()
},
commandLine: {
...process.atomBinding('command_line'),
appendSwitch (...args) {
const castedArgs = args.map((arg) => {
return typeof arg !== 'string' ? `${arg}` : arg
Expand Down
27 changes: 27 additions & 0 deletions spec/api-app-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1091,4 +1091,31 @@ describe('app module', () => {
return expect(app.whenReady()).to.be.eventually.fulfilled
})
})

describe('commandLine.hasSwitch', () => {
it('returns true when present', () => {
app.commandLine.appendSwitch('foobar1')
expect(app.commandLine.hasSwitch('foobar1')).to.be.true()
})

it('returns false when not present', () => {
expect(app.commandLine.hasSwitch('foobar2')).to.be.false()
})
})

describe('commandLine.getSwitchValue', () => {
it('returns the value when present', () => {
app.commandLine.appendSwitch('foobar', 'test')
expect(app.commandLine.getSwitchValue('foobar')).to.equal('test')
})

it('returns an empty string when present without value', () => {
app.commandLine.appendSwitch('foobar1')
expect(app.commandLine.getSwitchValue('foobar1')).to.equal('')
})

it('returns an empty string when not present', () => {
expect(app.commandLine.getSwitchValue('foobar2')).to.equal('')
})
})
})

0 comments on commit 6c74e6b

Please sign in to comment.