Skip to content

Commit

Permalink
Add a simple command to generate a bunch of random posts (bluesky-soc…
Browse files Browse the repository at this point in the history
…ial#73)

* add a simple command to generate a bunch of random posts

* move spam command into its own subcommand grouping:

* learn how the typescript build system works
  • Loading branch information
whyrusleeping authored Apr 13, 2022
1 parent 53847a1 commit 96a96f4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
31 changes: 31 additions & 0 deletions cli/src/commands/dev/spam.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import cmd from '../../lib/command.js'
import { loadDelegate } from '../../lib/client.js'
import { REPO_PATH } from '../../lib/env.js'
import { TID } from '@bluesky/common'

function makeRandText(l: number) {
var set = ' abcdefghijklmnopqrstuvwxyz ';
var len = set.length;
var out = '';
for ( let i = 0; i < len; i++ ) {
out += set.charAt(Math.floor(Math.random() *
len));
}
return out;
}

export default cmd({
name: 'gen-random-posts',
category: 'dev',
help: 'Create a large number of random posts.',
args: [{ name: 'count' }],
async command(args) {
const count : number = +(args._[0])
const client = await loadDelegate(REPO_PATH)

for (let i = 0; i < count; i++) {
await client.addPost(makeRandText(100))
}

},
})
1 change: 1 addition & 0 deletions cli/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ import './social/list-followers.js'
import './social/unfollow.js'
import './social/whoami.js'
import './social/whois.js'
import './dev/spam.js'
1 change: 1 addition & 0 deletions cli/src/lib/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const CATEGORIES = {
posts: 'Posts',
interactions: 'Interactions',
advanced: 'Advanced',
dev: 'Development',
}

export interface Cmd {
Expand Down
1 change: 1 addition & 0 deletions cli/src/lib/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function usage(err: any) {
addcat('posts')
addcat('interactions')
addcat('advanced')
addcat('dev')
for (const cat of cats) {
console.log(`\n${chalk.bold(cat.label)}:\n`)
for (let i = 0; i < cat.lhs.length; i++) {
Expand Down

0 comments on commit 96a96f4

Please sign in to comment.