Skip to content

Commit

Permalink
Merge pull request #70 from assaf/master
Browse files Browse the repository at this point in the history
FIXED katon tail should find app regardless of directory
  • Loading branch information
typicode committed May 4, 2015
2 parents 3541a81 + 952d4f9 commit 73676c1
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/cli/commands/tail.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
var chalk = require('chalk')
var config = require('../../config.js')
var fs = require('fs')
var listHosts = require('../utils/list-hosts')
var Tail = require('../../daemon/utils/tail')
var pathToHost = require('../utils/path-to-host')


// Number of lines to show from end of log.
var INITIAL_LINES = 10

// Return host name for current working directory
// Directory usually, not necessarily, same as host name
function getHostName(cwd) {
var hostNames = listHosts()
.map(function(name) {
var filename = config.hostsDir + '/' + name
var host = JSON.parse(fs.readFileSync(filename))
return [name.replace('.json', ''), host.cwd]
})
.filter(function(nameAndPath) {
var path = nameAndPath[1]
return path === cwd
})
.map(function(nameAndPath) {
var name = nameAndPath[0]
return name
})
return hostNames[0]
}


module.exports = function(args) {
var host = args[0] || pathToHost(process.cwd())
var host = args[0] || getHostName(process.cwd())
var tail = new Tail(host, INITIAL_LINES);
tail
.on('line', function(prefix, line) {
Expand Down

0 comments on commit 73676c1

Please sign in to comment.