This is the cam
cli. It's here because we are dumb and forget stuff.
- build the monorepo project with:
rushx build
- run
npm link
from this projects directory - type
cam
into your shell
After any updates, you must re run rush build
and you must navigate to this projects directory and run npm link
.
IMPORTANT NOTE: This is a rush repo, so using npm link
can be screwy. If you get errors, run rush unlink
and try again. Note that you will not be able to run npm link
inside of the "scripts." That will cause issues with Rush.
import 'zx' // the $ syntax won't work without this
const printShitToConsole = async (shit: string) => {
await $`echo "${shit}"`
}
import { Command } from 'commander'
import { printShitToConsole } from './helpers/printShitToConsole'
const doShitCommand = () =>
new Command('printShit') // "cam printShit" is the text you would type to run this command
.alias('ps') // you could use "cam ps" instead of "cam printShit"
.addHelpText('after', "You can't be helped") // if you ran "cam ps --help" then this text would be displayed after
.description('prints stupid shit to console') // If you ran "cam" without arguments, this text would show up next to the command
.action(() => {
// This is the stuff that happens when the command is run
printShitToConsole('shit')
})
src / cli.js
const UNIMPAIRED_CLI = new Command('cam')
// ... all commands are in this chain
.addCommand(doShitCommand()) // This is the line you will add to this file
We use the inquirer
package to do this
import inquirer from 'inquirer'
const askForDisability = () => {
const prompt = inquirer.prompt(
// First Question
[
name: 'firstQuestion',
message: 'Do you want to quit life?',
type: 'confirm',
choices: ['yes', 'no'],
]
// Second Question
[
name: 'secondQuestion',
message: 'Which character traits match you?',
type: 'checkbox', // they will select check the options they want
choices: ['idiot', 'freak', 'sexual deviant', 'mindless murderer']
]
).then((prompt) => {
// prompt is an object whose 'keys' equal the 'name' property in the prompt
// the value is equal to the 'choices' that the user decided
const firstQuestionData = prompt.firstQuestion
const secondQuestionData = prompt.secondQuestion
console.log('Go fuck yourself, ', secondQuestionData.join(' '))
})
}
/src
cli.ts // This is the file we run/export to use the command line
commands.ts // This file contains all the commands that we use
/helpers
// ... any code that is imported into the above files
// ... there really shouldn't be that much shit here. Keep it simple.
-
commander
: creates the CLI -
inquirer
: allows the cli to prompt a user for multiple options -
zx
: allows us to run bash scripts in our TS code