Skip to main content

Inside the Gluegun Toolbox

Let's explore the inside of the famous Gluegun "Toolbox" (or "Context" as it's sometimes called).

module.exports = {
name: 'dostuff',
alias: 'd',
run: async function (toolbox) {
// great! now what?
},
}

Here's what's available inside the toolbox object you see all over Gluegun.

nameprovides the...3rd party
metainformation about the currently running CLI
configconfiguration options from the app or plugin
filesystemability to copy, move & delete files & directoriesfs-jetpack
httpability to talk to the webapisauce
parameterscommand line arguments and optionsyargs-parser
patchingmanipulating file contents easilyfs-jetpack
printtools to print output to the command linecolors, ora
prompttools to acquire extra command line user inputenquirer
semverutilities for working with semantic versioningsemver
stringssome string helpers like case conversion, etc.lodash
systemability to executenode-which, execa, cross-spawn
templatecode generation from templatesejs
packageManagerability to add or remove packages with Yarn/NPM

The toolbox has "drawers" full of useful tools for building CLIs. For example, the toolbox.meta.version function can be invoked like this:

module.exports = {
name: 'dostuff',
alias: 'd',
run: async function (toolbox) {
// use them like this...
toolbox.print.info(toolbox.meta.version())

// or destructure!
const {
print: { info },
meta: { version },
} = toolbox
info(version())
},
}

To learn more about each tool, explore the rest of docs in this category.

Accessing Tools Directly

You can access almost all of Gluegun's toolbox tools without running a command. This is useful when you'd like to use these tools outside a CLI context or when doing some really specialized CLI.

const { print, filesystem, strings } = require('gluegun')
// or
const { print } = require('gluegun/print')
const { filesystem } = require('gluegun/filesystem')
const { strings } = require('gluegun/strings')
const { packageManager } = require('gluegun/package-manager')

print.info(`Hey, I'm Gluegun!`)
filesystem.dir('/tmp/jamon')
print.error(strings.isBlank(''))