Skip to content

Commit

Permalink
FIXED katon tail should find app regardless of directory
Browse files Browse the repository at this point in the history
We’ve got a case where the project’s name (and so working directory)
doesn’t match the hostname.

`katon tail` can’t find the log file since it tries to use the working
directory name instead of the host name.

This change iterates over the hosts in ~/.katon to find the one that’s
associated with the current working directory.
  • Loading branch information
assaf committed Apr 20, 2015
1 parent 4c06923 commit 952d4f9
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 952d4f9

Please sign in to comment.