Skip to content

Commit

Permalink
Deprecate the cli client subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
bas080 committed Aug 23, 2023
1 parent abfd7c8 commit 34de92a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 31 deletions.
76 changes: 47 additions & 29 deletions cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,32 @@ const argv = yargs(hideBin(process.argv))
.command('server <modules..>', 'start server', noop, async ({ modules, port }) => {
serve(modules, port)
})
.command('repl <modules..>', 'start a repl without server', noop, async ({ modules }) => {
.command('repl [modules..]', 'start a local server or client repl', noop, async ({ url, modules }) => {
if (url) {
const { default: repl } = await import('./repl.mjs')
const { default: FurverClient } = await import('./client.mjs')

const api = await FurverClient({ endpoint: url })

Object.keys(api).forEach(key => {
if (!global[key]) global[key] = api[key]
})

repl(async function awaitEval (cmd, context, filename, callback) {
const value = eval(cmd) // eslint-disable-line

if (isPromise(value)) { return callback(null, await value) }

callback(null, await api.call(value))
})

return
}

if (!modules) {
throw new Error('No --url or modules.. defined.\nEither define modules or a --url connection string.')
}

const { default: repl } = await import('./repl.mjs')
const { exec } = await import('./lisp.mjs')

Expand All @@ -73,34 +98,34 @@ const argv = yargs(hideBin(process.argv))
callback(null, await exec(modules, value))
})
})
.command(['client [port|url]'], 'start client repl', noop, async ({ endpoint, port, url }) => {
const { default: repl } = await import('./repl.mjs')
const { default: FurverClient } = await import('./client.mjs')

const api = await FurverClient({ endpoint })

Object.keys(api).forEach(key => {
if (!global[key]) global[key] = api[key]
})

repl(async function awaitEval (cmd, context, filename, callback) {
const value = eval(cmd) // eslint-disable-line

if (isPromise(value)) { return callback(null, await value) }

callback(null, await api.call(value))
})
.command({
command: 'client',
describe: 'start client repl. Use repl --url instead',
deprecated: true,
hidden: true,
handler: () => {
// Handle the deprecated subcommand here
console.log('Use the "repl" subcommand')
process.exit(1)
}
})
.command('schema [modules..]|[--port]|[--url]', 'print schema of api', noop, async ({ endpoint, modules, port, url }) => {

.command('schema [modules..]', 'print schema of api', noop, async ({ modules, url }) => {
if (modules) {
const { default: schema } = await import('./schema.mjs')
console.log(JSON.stringify(schema(modules)))
} else {
const { default: FurverClient, schema } = await import('./client.mjs')
const api = await FurverClient({ endpoint })
return
}

return console.log(JSON.stringify(await schema(api)))
if (!url) {
throw new Error('No --url or modules.. defined.\nEither define modules or a --url connection string.')
}

const { default: FurverClient, schema } = await import('./client.mjs')
const api = await FurverClient({ endpoint: url })

return console.log(JSON.stringify(await schema(api)))
})
.option('url', {
type: 'string',
Expand Down Expand Up @@ -134,13 +159,6 @@ const argv = yargs(hideBin(process.argv))
return isNaN(Number(x))
}
})
.middleware((argv) => {
const { port, url } = argv

argv.endpoint = (isNaN(Number(port)))
? url
: `http://localhost:${port}`
})
.parse()

debug('Options', await argv)
Expand Down
10 changes: 8 additions & 2 deletions server.mz
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ import {

## Reference

### `server(object)(request, response, lispProgram)`
### server

A function that takes an object which could be the module export or any object.
It then returns a function which is called on request.

### `withConfig
```js
// A pseudo express implementation.
route.get(async (request, response) =>
await server(object)(request, response, req.params.body))
```

### withConfig

The `withConfig` function is completely optional and used to define behavior
that is performed on every request, response or error. Simply wrap the exported
Expand Down

0 comments on commit 34de92a

Please sign in to comment.