git ssb

15+

ansuz / dnssb



Tree: aa8bdc9d1c7570e788c3416709fa6ef788024cec

Files: aa8bdc9d1c7570e788c3416709fa6ef788024cec / index.js

2885 bytesRaw
1#!/bin/sh
2':' //; exec "$(command -v nodejs || command -v node)" "$0" "$@"
3// http://unix.stackexchange.com/questions/65235/universal-node-js-shebang
4
5var SsbRef = require("ssb-ref");
6var Lib = require("./lib/");
7
8(function () {
9if (require.main !== module) { return module.exports = Lib; }
10
11var publishHelp = "\tssb-dns publish (previous record key...) name type value (class)";
12var updateHelp = "\tssb-dns update name type value (class)";
13var serverHelp = "\tssb-dns server port host";
14var dumpHelp = "\tssb-dns dump";
15
16
17var CLI_Help = function () {
18 [
19 "try one of:",
20 serverHelp,
21 publishHelp,
22 updateHelp,
23 dumpHelp,
24 ].forEach(function (m) {
25 console.log(m);
26 });
27};
28
29var argv = process.argv.slice(2);
30
31switch (argv[0]) {
32 case undefined:
33 CLI_Help();
34 break;
35 case 'dump':
36 (function () {
37 var count = 0;
38 Lib.dump.records(function (record) { // each
39 console.log(JSON.stringify(record, null, 2));
40 count++;
41 }, function (sbot) { // done
42 console.log("Found a total of %s valid ssb-dns records", count);
43 sbot.close();
44 });
45 }());
46 break;
47 case 'server':
48 (function () {
49 var port = argv[1] || 53053;
50 var host = argv[2] || '127.0.0.1';
51
52 Lib.server.listen( port, host, function () {
53 console.log("server listening on %s:%s", host, port);
54 });
55 }());
56 break;
57 case 'publish':
58 (function () {
59 var branches = [];
60 while (argv[1] && SsbRef.isMsgId(argv[1])) {
61 branches.push(argv.splice(1));
62 }
63
64 if (argv.length < 4) {
65 console.log("Try:");
66 console.error(publishHelp);
67 return;
68 }
69
70 var name = argv[1];
71 var type = argv[2];
72 var value = argv[3];
73 var _class = argv[4];
74
75 Lib.publish.record(branches, name, type, value, _class, function (err, msg) {
76 if (err) {
77 console.error(err);
78 process.exit(1);
79 }
80 console.log(msg);
81 process.exit(0);
82 });
83 }());
84 break;
85 case 'update':
86 (function () {
87 if (argv.length < 4) {
88 console.log("Try:");
89 console.error(updateHelp);
90 return;
91 }
92
93 var name = argv[1];
94 var type = argv[2];
95 var value = argv[3];
96 var _class = argv[4];
97
98 Lib.query.branches(name, type, _class, function (err, branches) {
99 if (err) throw err;
100 Lib.publish.record(branches, name, type, value, _class, function (err, msg) {
101 if (err) throw err;
102 console.log(msg);
103 process.exit(0);
104 });
105 })
106 }());
107 break;
108 default:
109 CLI_Help();
110 break;
111}
112
113}());
114

Built with git-ssb-web