Skip to content

Commit 455714a

Browse files
committed
make list print version and api
1 parent 8c6470a commit 455714a

1 file changed

Lines changed: 29 additions & 4 deletions

File tree

cli/cmds/list.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030
*/
3131
"use strict";
3232

33+
var home = require('../../lib/home');
3334
var path = require('path');
3435
var Promise = require('promise');
3536
var sprintf = require('sprintf-js').sprintf;
37+
var strings = require('../../lib/strings');
3638

3739
var list = function(args) {
3840
return new Promise(function(resolve, reject) {
@@ -43,14 +45,37 @@ var list = function(args) {
4345
console.log(JSON.stringify(gameList, undefined, " "));
4446
} else {
4547
if (gameList.length > 0) {
46-
var longestIdLength = gameList.reduce(function(previous, current) {
47-
return Math.max(previous, current.originalGameId.length);
48+
var longest = {
49+
id: 0,
50+
version: 7,
51+
apiVersion: 3,
52+
};
53+
gameList.forEach(function(runtimeInfo) {
54+
longest.id = Math.max(longest.id , runtimeInfo.originalGameId.length);
55+
longest.version = Math.max(longest.version , runtimeInfo.info.version.length);
56+
longest.apiVersion = Math.max(longest.apiVersion, runtimeInfo.info.happyFunTimes.apiVersion.length);
4857
}, 0);
58+
var format = strings.replaceParams("%-%(id)ss %3s %%(version)ss %%(apiVersion)ss %s", longest);
59+
console.log(sprintf(format,
60+
"id",
61+
"dev",
62+
"version",
63+
"api",
64+
"path"));
65+
console.log("------------------------------------------------------------------------------");
4966
console.log(gameList.map(function(game) {
50-
return sprintf("id: %-" + (longestIdLength) + "s dev: %s path: %s",
67+
var basePath = game.basePath;
68+
if (process.platform.substring(0, 3).toLowerCase() != "win") {
69+
if (strings.startsWith(basePath, home.homeDir)) {
70+
basePath = basePath.replace(home.homeDir, "~");
71+
}
72+
}
73+
return sprintf(format,
5174
game.originalGameId,
5275
game.originalGameId != game.info.happyFunTimes.gameId ? "*" : " ",
53-
game.basePath);
76+
game.info.version,
77+
game.info.happyFunTimes.apiVersion,
78+
basePath);
5479
}).join("\n"));
5580
} else {
5681
console.log("no games installed");

0 commit comments

Comments
 (0)