This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3393 from trufflesuite/add-subcommands
Enhancement: Subcommands and Truffle DB Serve functionality
- Loading branch information
Showing
4 changed files
with
94 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const command = { | ||
command: "serve", | ||
description: "Start Truffle's GraphQL UI playground", | ||
builder: {}, | ||
help: { | ||
usage: "truffle db serve", | ||
options: [] | ||
}, | ||
|
||
/* This command does starts an express derived server that invokes | ||
* `process.exit()` on SIGINT. As a result there is no need to invoke | ||
* truffle's own `process.exit()` which is triggered by invoking the `done` | ||
* callback. | ||
* | ||
* Todo: blacklist this command for REPLs | ||
*/ | ||
run: async function (argv) { | ||
const Config = require("@truffle/config"); | ||
const { playgroundServer } = require("@truffle/db"); | ||
|
||
const config = Config.detect(argv); | ||
const port = (config.db && config.db.port) || 4444; | ||
|
||
const { url } = await playgroundServer(config).listen({ port }); | ||
|
||
console.log(`🚀 Playground listening at ${url}`); | ||
console.log(`ℹ Press Ctrl-C to exit`); | ||
} | ||
}; | ||
|
||
module.exports = command; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const OS = require("os"); | ||
const serveCommand = require("./commands/serve"); | ||
|
||
const usage = | ||
"truffle db <sub-command> [options]" + | ||
OS.EOL + | ||
OS.EOL + | ||
" Available sub-commands: " + | ||
OS.EOL + | ||
OS.EOL + | ||
" serve \tStart the GraphQL server" + | ||
OS.EOL; | ||
|
||
const command = { | ||
command: "db", | ||
description: "Database interface commands", | ||
builder: function (yargs) { | ||
return yargs.commandDir("commands").demandCommand(); | ||
}, | ||
|
||
subCommands: { | ||
serve: { | ||
help: serveCommand.help, | ||
description: serveCommand.description | ||
} | ||
}, | ||
|
||
help: { | ||
usage, | ||
options: [] | ||
}, | ||
|
||
run: function (args, done) { | ||
const [subCommand] = args._; | ||
switch (subCommand) { | ||
case "serve": | ||
serveCommand.run(args, done); | ||
break; | ||
|
||
default: | ||
console.log(`Unknown command: ${subCommand}`); | ||
done(); | ||
} | ||
} | ||
}; | ||
|
||
module.exports = command; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters