A Node CLI - in 2017

Hi I'm Gant



Why CLI?

CLI's Are Great For

  • Tooling
  • Lists
  • Repetitive Tasks
  • Composable Workflow

CLIs Collect Ideas

Open Source and Teams Unite!

CLI's by friends

Another CLI

The Worst Example Ever

Writing Node CLIs

How Google Tells You


Look at me CLI

  #!/usr/bin/env node

  console.log("I'm Mr. Meeseeks")
  "author": "Gant Laborde",
  "license": "MIT",
+ "bin": {
+   "looksy": "./meeseeks.js"
+ }



Writing Node CLIs

How a few hours of research tells you


Look at me CLI

  const program = require('commander');

   .option('-m, --me <me>', 'The person to look at')
   .action((file) => {
     console.log(`I'm Mr. ${person} look at ${program.me}!`

  $ looksy Meeseeks -m me
  # I'm Mr. Meeseeks look at me!

Writing Node CLIs

Using Gluegun


Look at me CLI

  $ npm install -g gluegun@next
  $ gluegun new looksy
  $ cd looksy
  $ npm link
  $ looksy

  Welcome to your CLI
modify src/commands/looksy.js
module.exports = {
  name: 'looksy',
  run: async (context) => {
    const { print, parameters } = context
    print.info(`I'm ${parameters.first} Look at ${parameters.options.me}`)

So why Gluegun?

Let's go back to hello world (looksy)

    module.exports = {
      name: 'looksy',
      run: async (context) => {
        // gluegun provides all these features and more!
        const { system, print, filesystem, strings, parameters } = context
        // ...and be the CLI you wish to see in the world
        const awesome = strings.trim(system.run('whoami'))
        const moreAwesome = strings.kebabCase(`${awesome} and a keyboard`)
        const contents = `🚨 Warning! ${moreAwesome} coming thru! 🚨`
        const home = process.env['HOME']
        filesystem.write(`${home}/realtalk.json`, { contents })
        print.info(`${print.checkmark} I'm ${parameters.first}`)
        print.warning(`${print.checkmark} Look at`)
        print.success(`${print.checkmark} ${parameters.options.me}`)
looksy.js 🌟

We fancy now

What else can Gluegun do?

CLIs Today

What are you building?

What makes Gluegun Better?

The Real World Story

The Problem

Have you ever come back to an old project, and it simply doesn't work now?

Can you the version when spreading objects was added to Node?  Or even Async/Await?

Ever depend on an environment variable or CLI for your stack?



Why Gluegun?

Thinking Features

Thinking Plugins

Why Typescript?

Let's check the code!

🌟 Summary 🌟

  • CLIs are useful

  • CLIs are easy

  • Gluegun is scalable

  • Solidarity is Awesome


Slides Available


Articles on Medium

Updates on Twitter

Code on GitHub

Thanks GNO Code