Skip to content

Commit

Permalink
Using yargs, added README
Browse files Browse the repository at this point in the history
  • Loading branch information
RangerMauve committed Mar 29, 2019
1 parent 0bef131 commit 59f6771
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -59,3 +59,5 @@ typings/

# next.js build output
.next

package-lock.json
43 changes: 43 additions & 0 deletions README.md
@@ -1,2 +1,45 @@
# dat-pin
An extension for the Dat CLI to support Pinning Services

```shell
npm install -g dat-pin

# Install local pinning service
dat-pin install-service

# Add a dat to the pinning service so it's always being shared
dat-pin add dat://0a9e202b8055721bd2bc93b3c9bbc03efdbda9cfee91f01a123fdeaadeba303e/
```

## Commands

```
dat-pin [command]
Commands:
dat-pin add Pin a `dat://` read key to your pinning service to
keep it online
dat-pin remove Remove a `dat://` read key from your pinning
service
dat-pin list List the `dat://` read keys that you've pinned
dat-pin set-service Set the URL of the pinning service you want to use
dat-pin unset-service Resets your preferences to use your local pinning
service
dat-pin get-service Get the URL for your pinning service
dat-pin login Logs you into the configured pinning service. Not
necessary for local services
dat-pin logout Logs you out of the pinning service
dat-pin install-service Installs a local pinning service on your computer.
This will run in the background while your computer
is active.
dat-pin uninstall-service Uninstalls your local pinning service.
```

## How it works:

- Uses [dat-pinning-service-client](https://github.com/beakerbrowser/dat-pinning-service-client) to talk to pinning services that adhere to [DEP 0003](https://www.datprotocol.com/deps/0003-http-pinning-service-api/)
- Can start a local pinning service called `dat-pin` using `dat-pin install-service` (uses [os-service](https://www.npmjs.com/package/os-service))
- Runs on `127.0.0.1:3472`
- Binds to port `3282` for interacting with the P2P network
- The service uses [dat-librarian](https://www.npmjs.com/package/dat-librarian) to manage archives
- The service acts as a discovery gateway for [discovery-swarm-stream](https://www.npmjs.com/package/discovery-swarm-stream)
22 changes: 19 additions & 3 deletions index.js
@@ -1,8 +1,8 @@
const subcommand = require('subcommand')
let yargs = require('yargs')

const SERVICE_NAME = 'dat-pin'

subcommand([{
const commands = [{
name: 'add',
command: add,
help: 'Pin a `dat://` read key to your pinning service to keep it online'
Expand Down Expand Up @@ -49,7 +49,23 @@ subcommand([{
name: 'uninstall-service',
command: uninstallService,
help: 'Uninstalls your local pinning service.'
}])(process.argv.slice(2))
}]

for(let {name, command, help, options} of commands) {
yargs = yargs.command(name, help, (yargs) => {
if(!options) return yargs
return options.reduce((yargs, {name, abbr, help}) => {
return yargs.option(name, {
alias: abbr,
describe: help,
demandOption: true
})
}, yargs)
}, command)
}

yargs.scriptName('dat-pin').help().argv


function getClient (args) {
const PeerClient = require('./client')
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -34,7 +34,7 @@
"fastify-websocket": "^0.3.0",
"fs-extra": "^7.0.1",
"os-service": "^2.1.3",
"subcommand": "^2.1.1",
"userhome": "^1.0.0"
"userhome": "^1.0.0",
"yargs": "^13.2.2"
}
}

0 comments on commit 59f6771

Please sign in to comment.