Skip to content

Commit

Permalink
[FEATURE] Log CLI version when using --verbose option
Browse files Browse the repository at this point in the history
  • Loading branch information
matz3 committed Jul 22, 2019
1 parent a1d5281 commit c143a85
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bin/ui5.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ setTimeout(() => {
// Explicitly set CLI version as the yargs default might
// be wrong in case a local CLI installation is used
// Also add CLI location
cli.version(`${pkg.version} (from ${__filename})`);
const version = `${pkg.version} (from ${__filename})`;
require("../lib/cli/version").set(version);
cli.version(version);

// Explicitly set script name to prevent windows from displaying "ui5.js"
cli.scriptName("ui5");
Expand Down
2 changes: 2 additions & 0 deletions lib/cli/middlewares/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ function init(argv) {
}
if (argv.verbose) {
logger.setLevel("verbose");
const version = require("../version").get();
logger.getLogger("cli:middlewares:base").verbose(`using @ui5/cli version ${version}`);
logger.getLogger("cli:middlewares:base").verbose(`using node version ${process.version}`);
}
return logger;
Expand Down
11 changes: 11 additions & 0 deletions lib/cli/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let version;

// This module holds the CLI's version information (set via ui5.js) for later retrieval (e.g. from middlewares/logger)
module.exports = {
set: function(v) {
version = v;
},
get: function() {
return version;
}
};
14 changes: 14 additions & 0 deletions test/lib/cli/middlewares/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,17 @@ test.serial("retrieves logger middleware if verbose or loglevel are set", (t) =>
const loggerInstance = loggerMiddleware.init({verbose: true});
t.deepEqual(Object.keys(loggerInstance), Object.keys(logger), "Logger is used as middleware");
});

const path = require("path");
const execa = require("execa");
const pkg = require("../../../../package.json");
const ui5Cli = path.join(__dirname, "..", "..", "..", "..", "bin", "ui5.js");
const ui5 = (args, options = {}) => execa(ui5Cli, args, options);

test("ui5 --verbose", async (t) => {
// Using "versions" as a command, as the --verbose flag can't be used standalone
const {stderr} = await ui5(["versions", "--verbose"]);
t.is(stderr,
`verb cli:middlewares:base using @ui5/cli version ${pkg.version} (from ${ui5Cli})\n`+
`verb cli:middlewares:base using node version ${process.version}`);
});

0 comments on commit c143a85

Please sign in to comment.