Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
feat: updating version command
Browse files Browse the repository at this point in the history
  • Loading branch information
vamsimundra committed Jun 22, 2021
1 parent f9c2cb3 commit e9dc75a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
"@types/fs-extra": "^9.0.6",
"@types/jsforce": "1.9.29",
"@types/request": "^2.48.5",
"@types/shelljs": "^0.8.8",
"@types/sinon": "10.0.0",
"@typescript-eslint/eslint-plugin": "^4.2.0",
"@typescript-eslint/parser": "^4.2.0",
Expand Down
48 changes: 43 additions & 5 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Config, IConfig } from '@oclif/config';
import { set } from '@salesforce/kit';
import { AnyJson, get } from '@salesforce/ts-types';
import * as Debug from 'debug';
import { exec } from 'shelljs';
import * as lazyRequire from './lazyRequire';
import { default as nodeEnv, Env } from './util/env';

Expand Down Expand Up @@ -117,13 +118,50 @@ function debugCliInfo(version: string, channel: string, env: Env, config: IConfi
);
}

class VersionObject {
public cliVersion: string;
public pluginVersions: string[];
public osVersion: string;

public constructor(cliVersion: string, pluginVersions: string[], osVersion: string) {
this.cliVersion = cliVersion;
this.pluginVersions = pluginVersions;
this.osVersion = osVersion;
}
}

class SfdxMain extends Main {
// Function which returns Version object which includes cli version, plugin versions, OS and its version.
protected getIssueVersionObject(): VersionObject {
const cliVersion = this.config.userAgent;
const pluginVersion: string = exec('sfdx plugins --core', {
silent: true,
}).toString();
const pluginVersions: string[] = pluginVersion.split('\n');
pluginVersions.pop();
const osVersion = `${os.type()} ${os.release()}`;
return new VersionObject(cliVersion, pluginVersions, osVersion);
}

protected _version(): never {
const plugins = this.config.plugins.map((plugin) => `${plugin.name}@${plugin.version}-${plugin.type}`).join(', ');
// Make this pretty
this.log(`Your installed plugins: ${plugins}`);
this.log(this.config.userAgent);
// What ever else you want.
const options: Set<string> = new Set(this.argv);

// Checking if options has json or verbose
if (options.has('--verbose') || options.has('--json')) {
const versionObject: VersionObject = this.getIssueVersionObject();
if (options.has('--json')) {
this.log(`${JSON.stringify(versionObject, null, '\t')}`);
} else {
this.log(` CLI Version : \n\t${versionObject.cliVersion}`);
this.log('\n Plugin Version: ');
versionObject.pluginVersions.forEach((plugin) => {
this.log(`\t${plugin}`);
});
this.log(`\n OS and Version: \n\t${versionObject.osVersion}`);
}
} else {
this.log(this.config.userAgent);
}
return this.exit(0);
}
}
Expand Down
10 changes: 9 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,7 @@
dependencies:
"@types/node" "*"

"@types/glob@^7.1.1":
"@types/glob@*", "@types/glob@^7.1.1":
version "7.1.3"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.3.tgz#e6ba80f36b7daad2c685acd9266382e68985c183"
integrity sha512-SEYeGAIQIQX8NN6LDKprLjbrd5dARM5EXsd8GI/A5l0apYI1fGMWgPHSe4ZKL4eozlAyI+doUE9XbYS4xCkQ1w==
Expand Down Expand Up @@ -1538,6 +1538,14 @@
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.6.tgz#e9831776f4512a7ba6da53e71c26e5fb67882d63"
integrity sha512-0caWDWmpCp0uifxFh+FaqK3CuZ2SkRR/ZRxAV5+zNdC3QVUi6wyOJnefhPvtNt8NQWXB5OA93BUvZsXpWat2Xw==

"@types/shelljs@^0.8.8":
version "0.8.8"
resolved "https://registry.yarnpkg.com/@types/shelljs/-/shelljs-0.8.8.tgz#e439c69929b88a2c8123c1a55e09eb708315addf"
integrity sha512-lD3LWdg6j8r0VRBFahJVaxoW0SIcswxKaFUrmKl33RJVeeoNYQAz4uqCJ5Z6v4oIBOsC5GozX+I5SorIKiTcQA==
dependencies:
"@types/glob" "*"
"@types/node" "*"

"@types/sinon@*":
version "10.0.2"
resolved "https://registry.yarnpkg.com/@types/sinon/-/sinon-10.0.2.tgz#f360d2f189c0fd433d14aeb97b9d705d7e4cc0e4"
Expand Down

0 comments on commit e9dc75a

Please sign in to comment.