CLI's by friends
Another CLI
1
#!/usr/bin/env node
console.log("I'm Mr. Meeseeks")
...
"author": "Gant Laborde",
"license": "MIT",
+ "bin": {
+ "looksy": "./meeseeks.js"
+ }
}
meeseeks.js
package.json
2
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!
3
$ 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
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 🌟
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
https://slides.com/gantlaborde/useful-cli
Articles on Medium
Updates on Twitter
Code on GitHub