From 65bd3ea0672ccc33eb6d90de988def632b031b3c Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Tue, 28 Sep 2021 15:43:01 +0800 Subject: [PATCH 1/3] feat: display proxy urls HTTP_PROXY, HTTPS_PROXY environment variables. --- package.json | 5 +++-- src/commands/info.js | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 685e9a9..b8f7b1a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/commands/info.js b/src/commands/info.js index 4b9047b..2251f1f 100644 --- a/src/commands/info.js +++ b/src/commands/info.js @@ -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 = ' ') { @@ -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 = 6, indent = ' ') { + const url = value ? value : '(not set)' + this.log(this.indentString(`${key}: ${chalk.gray(url)}`, count, indent)) + } + async run () { const { flags } = this.parse(InfoCommand) @@ -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) @@ -72,6 +83,8 @@ class InfoCommand extends Command { return _p } + resObj['Proxies'] = proxies + resObj['CLI Plugins'] = { core: corePlugins.map(mapPlugin), user: userPlugins.map(mapPlugin), @@ -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)) From 946b4f3481b8ebb655f8db21c847023723cba6d8 Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Tue, 28 Sep 2021 16:06:50 +0800 Subject: [PATCH 2/3] update tests --- package.json | 3 ++- src/commands/info.js | 8 ++++---- test/commands/info.test.js | 24 +++++++++++++++++++++--- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index b8f7b1a..d0b9cea 100644 --- a/package.json +++ b/package.json @@ -61,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", diff --git a/src/commands/info.js b/src/commands/info.js index 2251f1f..5de7c9d 100644 --- a/src/commands/info.js +++ b/src/commands/info.js @@ -26,8 +26,8 @@ class InfoCommand extends Command { this.log(this.indentString(`${plugin.name} ${chalk.gray(plugin.version)}${asterisk}`, count, indent)) } - printProxy([key, value], count = 6, indent = ' ') { - const url = value ? value : '(not set)' + printProxy ([key, value], count = 4, indent = ' ') { + const url = value || '(not set)' this.log(this.indentString(`${key}: ${chalk.gray(url)}`, count, indent)) } @@ -65,7 +65,7 @@ class InfoCommand extends Command { const proxies = { http: getProxyForUrl('http://anyhost'), - https: getProxyForUrl('https://anyhost'), + https: getProxyForUrl('https://anyhost') } if (flags.json || flags.yml) { @@ -83,7 +83,7 @@ class InfoCommand extends Command { return _p } - resObj['Proxies'] = proxies + resObj.Proxies = proxies resObj['CLI Plugins'] = { core: corePlugins.map(mapPlugin), diff --git a/test/commands/info.test.js b/test/commands/info.test.js index d90a8df..45da1c4 100644 --- a/test/commands/info.test.js +++ b/test/commands/info.test.js @@ -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) @@ -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: { @@ -106,6 +114,9 @@ describe('instance methods', () => { } const result = ` + Proxies: + http: (not set) + https: (not set) CLI plugins: core: core-plugin-a version @@ -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: { @@ -146,6 +157,10 @@ describe('instance methods', () => { } const result = { + Proxies: { + http: '', + https: '' + }, 'CLI Plugins': { core: [ { @@ -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: { @@ -212,6 +227,9 @@ describe('instance methods', () => { } const result = dedent` + Proxies: + http: '' + https: '' CLI Plugins: core: - name: core-plugin-a From 289c9869930ce411cfdcf1fbd27bd481eba500f1 Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 29 Sep 2021 09:45:01 +0000 Subject: [PATCH 3/3] 2.0.1-next.0 --- README.md | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0725721..3959051 100644 --- a/README.md +++ b/README.md @@ -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` @@ -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)_ ## Contributing diff --git a/package.json b/package.json index d0b9cea..c9f1f9d 100644 --- a/package.json +++ b/package.json @@ -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",