Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add app.commandLine.hasSwitch() / app.commandLine.getSwitchValue() #16282

Merged
merged 5 commits into from Jan 7, 2019
Next

feat: add app.commandLine.hasSwitch() / app.commandLine.getSwitchValue()

  • Loading branch information...
miniak committed Jan 4, 2019
commit 6c74e6b82a0150a9397d9ae3d753307b83290c76
@@ -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.

This comment has been minimized.

Copy link
@alexeykuzmin

alexeykuzmin Jan 7, 2019

Contributor

This is sad.

This comment has been minimized.

Copy link
@miniak

miniak Jan 7, 2019

Author Contributor

that's how the chromium API behaves


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

Enables full sandbox mode on the app.
@@ -25,6 +25,7 @@ Object.assign(app, {
return Menu.getApplicationMenu()
},
commandLine: {
...process.atomBinding('command_line'),
appendSwitch (...args) {
This conversation was marked as resolved by miniak

This comment has been minimized.

Copy link
@deepak1556

deepak1556 Jan 7, 2019

Member

You could move these methods implemented via app module into command_line module in a followup PR.

This comment has been minimized.

Copy link
@miniak

miniak Jan 7, 2019

Author Contributor

done in this PR

const castedArgs = args.map((arg) => {
return typeof arg !== 'string' ? `${arg}` : arg
@@ -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('')
})
})
})
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.