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: display proxy urls #28

Merged
merged 5 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ OPTIONS
-y, --yml output yml
```

_See code: [src/commands/info.js](https://github.com/adobe/aio-cli-plugin-info/blob/2.0.0/src/commands/info.js)_
_See code: [src/commands/info.js](https://github.com/adobe/aio-cli-plugin-info/blob/2.0.1-next.0/src/commands/info.js)_

## `aio report`

Expand All @@ -75,7 +75,7 @@ OPTIONS
-f, --feature request a feature
```

_See code: [src/commands/report.js](https://github.com/adobe/aio-cli-plugin-info/blob/2.0.0/src/commands/report.js)_
_See code: [src/commands/report.js](https://github.com/adobe/aio-cli-plugin-info/blob/2.0.1-next.0/src/commands/report.js)_
<!-- commandsstop -->

## Contributing
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@adobe/aio-cli-plugin-info",
"description": "Adobe I/O CLI plugin to display dev environment version information",
"version": "2.0.0",
"version": "2.0.1-next.0",
"repository": "adobe/aio-cli-plugin-info",
"homepage": "https://github.com/adobe/aio-cli-plugin-info",
"bugs": "https://github.com/adobe/aio-cli-plugin-info/issues",
Expand All @@ -11,11 +11,12 @@
"@oclif/config": "^1",
"@oclif/errors": "^1.1.2",
"@oclif/plugin-help": "^2.2.3",
"cli-ux": "^5.4.6",
"chalk": "^4.0.0",
"cli-ux": "^5.4.6",
"debug": "^4.1.0",
"envinfo": "^7.5.0",
"js-yaml": "^3.14.0"
"js-yaml": "^3.14.0",
"proxy-from-env": "^1.1.0"
},
"devDependencies": {
"@adobe/eslint-config-aio-lib-config": "^1.2.0",
Expand Down Expand Up @@ -60,7 +61,8 @@
},
"main": "src/index.js",
"scripts": {
"test": "jest --ci && eslint src test e2e",
"lint": "eslint src test e2e",
"test": "jest --ci && npm run lint",
"prepack": "oclif-dev manifest && oclif-dev readme",
"postpack": "rm -f oclif.manifest.json",
"version": "oclif-dev readme && git add README.md",
Expand Down
15 changes: 15 additions & 0 deletions src/commands/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const { Command, flags } = require('@oclif/command')
const envinfo = require('envinfo')
const chalk = require('chalk')
const yaml = require('js-yaml')
const { getProxyForUrl } = require('proxy-from-env')

class InfoCommand extends Command {
indentString (string, count = 2, indent = ' ') {
Expand All @@ -25,6 +26,11 @@ class InfoCommand extends Command {
this.log(this.indentString(`${plugin.name} ${chalk.gray(plugin.version)}${asterisk}`, count, indent))
}

printProxy ([key, value], count = 4, indent = ' ') {
const url = value || '(not set)'
this.log(this.indentString(`${key}: ${chalk.gray(url)}`, count, indent))
}

async run () {
const { flags } = this.parse(InfoCommand)

Expand Down Expand Up @@ -57,6 +63,11 @@ class InfoCommand extends Command {
const userPlugins = plugins.filter(p => p.type === 'user').map(mapAsterisk)
const linkPlugins = plugins.filter(p => p.type === 'link').map(mapAsterisk)

const proxies = {
http: getProxyForUrl('http://anyhost'),
https: getProxyForUrl('https://anyhost')
}

if (flags.json || flags.yml) {
// format plugin info as json/yml
const resObj = JSON.parse(resInfo)
Expand All @@ -72,6 +83,8 @@ class InfoCommand extends Command {
return _p
}

resObj.Proxies = proxies

resObj['CLI Plugins'] = {
core: corePlugins.map(mapPlugin),
user: userPlugins.map(mapPlugin),
Expand All @@ -84,6 +97,8 @@ class InfoCommand extends Command {
}
} else {
this.log(resInfo)
this.log(this.indentString('Proxies:', 2))
Object.entries(proxies).forEach(p => this.printProxy(p))
this.log(this.indentString('CLI plugins:', 2))
this.log(this.indentString('core:', 4))
corePlugins.forEach(p => this.printPlugin(p))
Expand Down
24 changes: 21 additions & 3 deletions test/commands/info.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ describe('instance methods', () => {
expect(stdout.output).toMatch(command.indentString('name2 version2 (*)\n', 6))
})

test('printProxy', () => {
command.printProxy(['http'])
expect(stdout.output).toEqual(command.indentString('http: (not set)\n', 4))

command.printProxy(['https', 'https://foo.bar'])
expect(stdout.output).toMatch(command.indentString('https: https://foo.bar\n', 4))
})

describe('run', () => {
test('exists', async () => {
expect(command.run).toBeInstanceOf(Function)
Expand All @@ -85,7 +93,7 @@ describe('instance methods', () => {
})
})

test('cli plugins (core, user, link) stdout', () => {
test('proxies, cli plugins (core, user, link) stdout', () => {
command.argv = []
command.config = {
pjson: {
Expand All @@ -106,6 +114,9 @@ describe('instance methods', () => {
}

const result = `
Proxies:
http: (not set)
https: (not set)
CLI plugins:
core:
core-plugin-a version
Expand All @@ -123,7 +134,7 @@ describe('instance methods', () => {
})
})

test('cli plugins (core, user, link) --json', () => {
test('proxies, cli plugins (core, user, link) --json', () => {
command.argv = ['-j']
command.config = {
pjson: {
Expand All @@ -146,6 +157,10 @@ describe('instance methods', () => {
}

const result = {
Proxies: {
http: '',
https: ''
},
'CLI Plugins': {
core: [
{
Expand Down Expand Up @@ -191,7 +206,7 @@ describe('instance methods', () => {
})
})

test('cli plugins (core, user, link) --yml', async () => {
test('proxies, cli plugins (core, user, link) --yml', async () => {
command.argv = ['-y']
command.config = {
pjson: {
Expand All @@ -212,6 +227,9 @@ describe('instance methods', () => {
}

const result = dedent`
Proxies:
http: ''
https: ''
CLI Plugins:
core:
- name: core-plugin-a
Expand Down