Skip to content

Commit 6dfbfa0

Browse files
committed
Merge pull request #73 from igorshubovych/fix-random-options
Fix --random and --random-example options
2 parents 2d8f768 + 4df9e67 commit 6dfbfa0

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

lib/cache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function tryLoad(pages, index, done) {
6161
if (index >= pages.length) {
6262
done(new Error('Failed to load from cache'));
6363
}
64-
var filepath = path.join(CACHE_FOLDER, pages[index]);
64+
var filepath = path.join(CACHE_FOLDER, 'pages', pages[index]);
6565
fs.readFile(filepath, function(err, contents) {
6666
if (err) {
6767
tryLoad(pages, index + 1, done);

lib/platform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function getPreferredPlatform() {
2222
}
2323

2424
function specific(command, os) {
25-
return 'pages/' + os + '/' + command + '.md';
25+
return os + '/' + command + '.md';
2626
}
2727

2828
function resolve(command) {

lib/tldr.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@ var render = require('./render');
99
var exit = process.exit;
1010

1111

12-
function printPages(pages, singleColumn) {
13-
var endOfLine = require('os').EOL;
14-
var delimiter = ', ';
15-
if (singleColumn) {
16-
delimiter = endOfLine;
17-
}
18-
console.log('\n' + pages.map(pageName).join(delimiter));
19-
}
20-
2112
exports.list = function(singleColumn) {
2213
cache.list(platform.getPreferredPlatformFolder(), function(err, pages) {
2314
if (err) {
@@ -48,23 +39,25 @@ exports.get = function(command) {
4839
};
4940

5041
exports.random = function() {
51-
cache.list(function(err, pages) {
42+
cache.list(platform.getPreferredPlatformFolder(), function(err, pages) {
5243
if (err) {
5344
console.error(messages.emptyCache());
5445
exit(1);
5546
}
5647
var page = _.sample(pages);
48+
console.log('PAGE', page);
5749
printBestPage([page]);
5850
});
5951
};
6052

6153
exports.randomExample = function() {
62-
cache.list(function(err, pages) {
54+
cache.list(platform.getPreferredPlatformFolder(), function(err, pages) {
6355
if (err) {
6456
console.error(messages.emptyCache());
6557
exit(1);
6658
}
6759
var page = _.sample(pages);
60+
console.log('PAGE', page);
6861
printBestPage([page], {randomExample: true});
6962
});
7063
};
@@ -97,6 +90,15 @@ exports.updateCache = function() {
9790
});
9891
};
9992

93+
function printPages(pages, singleColumn) {
94+
var endOfLine = require('os').EOL;
95+
var delimiter = ', ';
96+
if (singleColumn) {
97+
delimiter = endOfLine;
98+
}
99+
console.log('\n' + pages.map(pageName).join(delimiter));
100+
}
101+
100102
function printBestPage(pages, options) {
101103
cache.get(pages, function(err, content) {
102104
if (err) {

test/platform.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ describe('Platform', function() {
6161
it('should resolve tar command with specific OS and common folder', function() {
6262
os.platform.onCall(0).returns('linux');
6363
platform.resolve('tar').should.eql([
64-
'pages/linux/tar.md',
65-
'pages/common/tar.md'
64+
'linux/tar.md',
65+
'common/tar.md'
6666
]);
6767
});
6868
});

0 commit comments

Comments
 (0)