From f9850123406d42fc6f466d33daf03258128aa356 Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Wed, 6 Oct 2021 23:08:15 +0800 Subject: [PATCH] feat: display proxy urls (#28) --- README.md | 4 ++-- package.json | 10 ++++++---- src/commands/info.js | 15 +++++++++++++++ test/commands/info.test.js | 24 +++++++++++++++++++++--- 4 files changed, 44 insertions(+), 9 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 685e9a9..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", @@ -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", @@ -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", diff --git a/src/commands/info.js b/src/commands/info.js index 4b9047b..5de7c9d 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 = 4, indent = ' ') { + const url = 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)) 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