OverviewFilesCommitsIssuesDocsReleasesPeers

wirecore / cli / wiredove-cli / index.js

109 lines · javascript ref:
#!/usr/bin/env node

/**
 * wiredove-cli: CLI client for wiredove.net network
 *
 * Posts to the existing wiredove network using the same protocol:
 * - ANProto for identity and signing
 * - Trystero for WebRTC P2P connections
 * - BitTorrent DHT for peer discovery
 */

import { Command } from 'commander'
import chalk from 'chalk'
import { WiredoveCLI } from './wiredove.js'

const program = new Command()

program
  .name('wiredove')
  .description('CLI client for wiredove.net network')
  .version('0.1.0')

program
  .command('init')
  .description('Initialize identity (generate keypair)')
  .option('-n, --name <name>', 'Your display name')
  .action(async (options) => {
    const cli = new WiredoveCLI()
    await cli.init(options.name)
  })

program
  .command('whoami')
  .description('Show your identity')
  .action(async () => {
    const cli = new WiredoveCLI()
    await cli.whoami()
  })

program
  .command('post <text>')
  .description('Post a message to wiredove network')
  .option('-i, --image <hash>', 'Image hash (if any)')
  .action(async (text, options) => {
    const cli = new WiredoveCLI()
    await cli.post(text, options.image)
  })

program
  .command('listen')
  .description('Listen for messages from the network')
  .option('-f, --follow <pubkeys...>', 'Public keys to follow')
  .option('-t, --timeout <seconds>', 'How long to listen (default: 60)', '60')
  .action(async (options) => {
    const cli = new WiredoveCLI()
    await cli.listen(options.follow, parseInt(options.timeout))
  })

program
  .command('follow <pubkey>')
  .description('Add a public key to your following list')
  .action(async (pubkey) => {
    const cli = new WiredoveCLI()
    await cli.follow(pubkey)
  })

program
  .command('following')
  .description('Show who you follow')
  .action(async () => {
    const cli = new WiredoveCLI()
    await cli.showFollowing()
  })

program
  .command('users')
  .description('Fetch and display users from wiredove network')
  .option('-s, --search <name>', 'Search for users by name')
  .action(async (options) => {
    const cli = new WiredoveCLI()
    await cli.fetchUsers(options.search)
  })

program
  .command('posts')
  .description('Fetch recent posts from wiredove network')
  .option('-u, --user <pubkey>', 'Filter by user public key')
  .option('-n, --name <name>', 'Filter by user name')
  .option('-l, --limit <number>', 'Number of posts to show (default: 10)', '10')
  .action(async (options) => {
    const cli = new WiredoveCLI()
    await cli.fetchPosts({
      user: options.user,
      name: options.name,
      limit: parseInt(options.limit)
    })
  })

program
  .command('reply <hash> <text>')
  .description('Reply to a specific post')
  .option('-i, --image <hash>', 'Image hash (if any)')
  .action(async (replyToHash, text, options) => {
    const cli = new WiredoveCLI()
    await cli.reply(replyToHash, text, options.image)
  })

program.parse()