This repository has been archived by the owner on Nov 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
re #661
- Loading branch information
Ryan Garant
committed
Sep 18, 2019
1 parent
f4de999
commit 841e2a2
Showing
9 changed files
with
212 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`E2E: Alias Module Test User alias is expanded \`gh user --user=zeno\` 1`] = ` | ||
"You're logged in as zenorocha | ||
" | ||
`; |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* © 2013 Liferay, Inc. <https://liferay.com> and Node GH contributors | ||
* (see file: CONTRIBUTORS) | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
import { runCmd } from './testUtils' | ||
|
||
describe('E2E: Alias Module Test', () => { | ||
it('User alias is expanded `gh user --user=zeno`', done => { | ||
expect(runCmd('gh user --user=zeno')).toMatchSnapshot() | ||
done() | ||
}) | ||
}) |
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 |
---|---|---|
|
@@ -109,5 +109,9 @@ | |
|
||
"ssh": true, | ||
|
||
"signature": "" | ||
"signature": "", | ||
|
||
"alias": { | ||
"zeno": "zenorocha" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/** | ||
* © 2013 Liferay, Inc. <https://liferay.com> and Node GH contributors | ||
* (see file: CONTRIBUTORS) | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
// -- Requires ------------------------------------------------------------------------------------- | ||
|
||
import * as base from '../base' | ||
import * as configs from '../configs' | ||
import * as logger from '../logger' | ||
|
||
const config = base.getConfig() | ||
|
||
// -- Constructor ---------------------------------------------------------------------------------- | ||
|
||
export default function Alias(options) { | ||
this.options = options | ||
} | ||
|
||
// -- Constants ------------------------------------------------------------------------------------ | ||
|
||
Alias.DETAILS = { | ||
alias: 'al', | ||
description: 'Create alias for a username.', | ||
commands: ['add', 'list', 'remove'], | ||
options: { | ||
add: String, | ||
list: Boolean, | ||
remove: String, | ||
user: String, | ||
}, | ||
shorthands: { | ||
a: ['--add'], | ||
l: ['--list'], | ||
r: ['--remove'], | ||
u: ['--user'], | ||
}, | ||
payload(payload, options) { | ||
if (payload[0]) { | ||
options.add = payload[0] | ||
options.user = payload[1] | ||
} else { | ||
options.list = true | ||
} | ||
}, | ||
} | ||
|
||
// -- Commands ------------------------------------------------------------------------------------- | ||
|
||
Alias.prototype.run = function() { | ||
const instance = this | ||
const options = instance.options | ||
|
||
if (options.add) { | ||
if (!options.user) { | ||
logger.error('You must specify an user, try --user username.') | ||
} | ||
|
||
logger.debug(`Creating alias ${options.add}`) | ||
instance.add() | ||
} | ||
|
||
if (options.list) { | ||
instance.list((err, data) => { | ||
let item | ||
|
||
for (item in data) { | ||
if (data.hasOwnProperty(item)) { | ||
logger.log(`${logger.colors.cyan(item)}: ${logger.colors.magenta(data[item])}`) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
if (options.remove) { | ||
logger.debug(`Removing alias ${options.remove}`) | ||
instance.remove() | ||
} | ||
} | ||
|
||
Alias.prototype.add = function() { | ||
const instance = this | ||
const options = instance.options | ||
|
||
configs.writeGlobalConfig(`alias.${options.add}`, options.user) | ||
} | ||
|
||
Alias.prototype.list = function(opt_callback) { | ||
opt_callback && opt_callback(null, config.alias) | ||
} | ||
|
||
Alias.prototype.remove = function() { | ||
const instance = this | ||
const options = instance.options | ||
|
||
delete config.alias[options.remove] | ||
|
||
configs.writeGlobalConfig('alias', config.alias) | ||
} |