Skip to content

Commit cf8cdc1

Browse files
committed
test.callmemaybe
1 parent 0e10308 commit cf8cdc1

File tree

4 files changed

+45
-16
lines changed

4 files changed

+45
-16
lines changed

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
[![callmemaybe](https://media3.giphy.com/media/kGdRnb1kF4OmQ/giphy.gif?cid=ecf05e472pq6o5ggg6vq0w1b88g3221a7cevv2orxgm6rva7&rid=giphy.gif&ct=g)](https://www.youtube.com/watch?v=fWNaR-rxAic&t=86s)
44

5-
*URL as an interface*
6-
Single binary local DNS server that launch commands if you ask for specific URL
5+
*hostname as an interface*
6+
Single binary local DNS server that launch commands if you ask for specific hostname
77

88
## Why?
99

10-
I have a lot of projects. Switching between them is a pain: some of them use docker, some are started from systemd, some just from cli with arbitrary params. A lot to deal with
11-
So I wanted to open `http://project1.local` in browser and project1 will be up automagically: no need to run something.
10+
I have a lot of projects. Switching between them is a pain: some of them use docker, some are started from systemd, some just from cli with arbitrary params. Also you need to memoize that 192.168.1.1:9200 is elasticsearch in one project, and 67.122.34.55:5423 is a postgres on another. And you need to find that dreaded command that creates proxy between your production pod to your local machine.
11+
A lot to deal with.
12+
13+
So I wanted to open http://project1 in browser and project1 will be up automagically: no need to run something. And then when I need to connect to database I could just use http://db.project1 as connection string and all ssh/kubernetes port forwarding would be hidden from me.
1214

1315
## Installation
1416
```bash
@@ -19,6 +21,11 @@ curl https://i.jpillora.com/slavaGanzin/callmemaybe! | bash
1921
```bash
2022
sudo callmemaybe
2123
```
24+
Test that everything working:
25+
```bash
26+
curl test.callmemaybe
27+
# you should see a notification
28+
```
2229

2330
## What can you do with it?
2431

callmemaybe.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,24 @@ const dns2 = require('dns2');
1010
const {homedir} = require('os')
1111
const {promisify} = require('util')
1212
const exec = promisify(require('child_process').exec)
13+
const http = require('http')
14+
15+
const notify = (message, title='') => notifier.notify({
16+
title: `callmemaybe${title?': '+title:''}` ,
17+
message: yaml.stringify(message),
18+
})
19+
20+
const { program } = require('commander');
21+
22+
program
23+
.option('--test')
24+
.parse()
25+
const options = program.opts();
26+
27+
if (options.test) {
28+
notify(`It's alive!`, 'test')
29+
return
30+
}
1331

1432
const pp = x =>
1533
process.stdout.write(yaml.stringify(x || {}))
@@ -24,10 +42,6 @@ const execPP = (c,o) => {
2442
return exec(c,o)
2543
}
2644

27-
const notify = (message, title='') => notifier.notify({
28-
title: `callmemaybe${title?': '+title:''}` ,
29-
message: yaml.stringify(message),
30-
})
3145

3246
const CONFIG_FILES = [`${homedir()}/.config/callmemaybe.yaml`]
3347

@@ -46,12 +60,18 @@ Promise.all(CONFIG_FILES.map(x => readFile(x).catch(() =>
4660
localhost:
4761
ip: 127.0.0.1
4862
63+
4964
# Params and default values
5065
# hostname: #hostname of your action
5166
# ip: 127.0.0.1 #what ip hostname resolve to.
5267
# healthcheck: ~ #any command that checks that project is up, so there is no need to run start command
5368
# start: ~ #command that starts your project
5469
# folder: ~ #folder where command will be running
70+
71+
#test endpoints. feel free to remove them
72+
73+
test.callmemaybe:
74+
start: callmemaybe --test
5575
`)
5676
)))
5777
.then(reloadConfig)
@@ -73,13 +93,13 @@ const server = dns2.createServer({
7393
ttl: 10,
7494
address: c.ip || '127.0.0.1'
7595
});
76-
await execPP(c.healthcheck, {cwd: c.folder, stdio: 'inherit'})
77-
.then(pp)
78-
.catch(({stdout, stderr}) => {
96+
// await (c.healthcheck ? execPP(c.healthcheck, {cwd: c.folder || '~', stdio: 'inherit'}) : Promise.reject({}))
97+
// .then(pp)
98+
// .catch(({stdout, stderr}) => {
7999
if (c.start) {
80100
execPP(c.start, {cwd: c.folder, stdio: 'inherit'}).then(pp).catch(({stderr}) => notify(stderr, question.name + ' ' + c.start + ' error'))
81101
}
82-
})
102+
// })
83103

84104
return send(response)
85105
}

maskfile.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ mask pkg
1111
version=`fx package.json .version`
1212
find bin -type f | parallel tar czf {}.tgz {}
1313
gh release delete v${version} --yes
14-
gh release create v${version} ./bin/*.tgz --title "calmmemaybe $version" --generate-notes --latest
14+
gh release create v${version} ./bin/*.tgz --title "calmmemaybe $version" --generate-notes --latest
1515
```
1616

17-
18-
19-
17+
## install
18+
```bash
19+
curl https://i.jpillora.com/slavaGanzin/callmemaybe! | bash
20+
```

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
},
1818
"homepage": "https://github.com/slavaGanzin/dns-runner#readme",
1919
"dependencies": {
20+
"commander": "^10.0.0",
2021
"dns2": "^2.0.5",
2122
"node-notifier": "^10.0.1",
2223
"ramda": "^0.28.0",

0 commit comments

Comments
 (0)