A Node CLI - in 2017

Hi I'm Gant

AKA

AKA

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

1

Look at me CLI

  #!/usr/bin/env node

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

meeseeks.js

package.json

Writing Node CLIs

How a few hours of research tells you

2

Look at me CLI

  const program = require('commander');

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

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

Writing Node CLIs

Using Gluegun

3

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}`)
  }
}
looksy.js

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?

https://github.com/infinitered/solidarity

Solidarity

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

@GantLaborde

Slides Available

https://slides.com/gantlaborde/useful-cli

Articles on Medium

Updates on Twitter

Code on GitHub

Thanks GNO Code

AND THANK YOU!

Useful CLI

By Gant Laborde

Useful CLI

Using JavaScript to create a useful CLI. A tour through Node/JS/TypeScript/Solidarity and More.

  • 2,475