-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"default": "postgres://localhost/test_data" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,22 @@ | ||
#!/bin/sh | ||
|
||
BASEDIR=$(dirname $0) | ||
WORKING_DIR=$(pwd) | ||
|
||
if [ "$1" == "--help" ]; then | ||
echo "Usage:" | ||
echo "postbird localhost/dbname -> open postgres://$USER@localhost/dbname" | ||
echo "postbird . -> try to find .postbird in PWD" | ||
echo "postbird ../pathto/project -> try to find .postbird in ../pathto/project" | ||
exit 0 | ||
fi | ||
|
||
# postbird localhost/dbname => open postgres://localhost/dbname#WORKING_DIR=$WORKING_DIR | ||
# postbird => postgres://.#WORKING_DIR=$WORKING_DIR | ||
# postbird ../pathto/project => postgres://../pathto/project#WORKING_DIR=$WORKING_DIR | ||
|
||
if [ $1 ]; then | ||
open -a Postgres.app $1 | ||
open postgres://$1\#WORKING_DIR=$WORKING_DIR | ||
else | ||
open -a Postgres.app . | ||
open postgres://.\#WORKING_DIR=$WORKING_DIR | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
|
||
var CliUtil = { | ||
resolveArg(url, callback) { | ||
var parts = url.split('#WORKING_DIR='); | ||
var workingDir = null; | ||
if (parts.length == 2) { | ||
url = parts[0]; | ||
workingDir = parts[1]; | ||
} | ||
|
||
console.log('CliUtil.resolveArg', url, workingDir); | ||
|
||
if (workingDir) { | ||
this.checkFiles(url, workingDir, callback); | ||
} else { | ||
callback(url); | ||
} | ||
|
||
}, | ||
|
||
checkFiles(url, workingDir, callback) { | ||
var joinedPath = path.join(workingDir, url.replace('postgres://', '')); | ||
console.log("ckecking if exist", joinedPath); | ||
fs.access(joinedPath, 'r', (err, fd) => { | ||
if (err) { | ||
console.log(joinedPath, 'not exists'); | ||
callback(url); | ||
} else { | ||
this.tryFindConfig(joinedPath, (result) => { | ||
callback(result || url); | ||
}); | ||
//this.tryFindConfig(workingDir, callback); | ||
} | ||
}); | ||
}, | ||
|
||
tryFindConfig(folder, callback) { | ||
var file = path.join(folder, '.postbird'); | ||
console.log("ckecking if exist", file); | ||
fs.access(file, 'r', (err, fd) => { | ||
if (err) { | ||
callback(false); | ||
} else { | ||
this.loadDotPostbird(file, callback); | ||
} | ||
}); | ||
}, | ||
|
||
loadDotPostbird(path, callback) { | ||
fs.readFile(path, 'utf8', (err, data) => { | ||
if (err) throw err; | ||
var fileData = data.toString().trim(); | ||
if (fileData[0] == "{") { | ||
var data = JSON.parse(fileData); | ||
callback(data.default); | ||
} else { | ||
var data = require(path); | ||
callback(data.default); | ||
} | ||
}); | ||
} | ||
// nativeObject = YAML.parse(yamlString); | ||
}; | ||
|
||
module.exports = CliUtil; |