Skip to content

Commit

Permalink
feat: add space command with create and register (#3)
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Oli Evans <oli@protocol.ai>
  • Loading branch information
olizilla authored Dec 9, 2022
1 parent 3104b9f commit 9c25a2d
Show file tree
Hide file tree
Showing 4 changed files with 2,301 additions and 84 deletions.
17 changes: 17 additions & 0 deletions bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sade from 'sade'
import open from 'open'
import { getPkg } from './lib.js'
import { createSpace, registerSpace } from './index.js'

const cli = sade('w3')

Expand All @@ -14,4 +15,20 @@ cli.command('open <cid>')
.describe('open CID on https://w3s.link')
.action(cid => open(`https://w3s.link/ipfs/${cid}`))

cli.command('space')
.describe('Create and mangage w3 spaces')

cli.command('space create <name>')
.describe('Create a new w3 space')
.action(name => {
createSpace(name)
console.log(`Created ${name}`)
})

cli.command('space register <email>')
.describe('Claim the space by associating it with your email address')
.action(email => {
registerSpace(email)
})

cli.parse(process.argv)
19 changes: 19 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { create } from '@web3-storage/w3up-client'

export async function createSpace (name) {
const client = await create()
const space = await client.createSpace(name)
await client.setCurrentSpace(space.did)
}

export async function registerSpace (address) {
const client = await create()
if (await client.currentSpace() === undefined) {
await client.setCurrentSpace((await client.createSpace()).did)
}
try {
await client.registerSpace(address)
} catch (err) {
console.error('registration failed: ', err)
}
}
Loading

0 comments on commit 9c25a2d

Please sign in to comment.