187 lines
6.3 KiB
HTML
187 lines
6.3 KiB
HTML
<!doctype html>
|
||
<html>
|
||
<head>
|
||
<title>Wroten - team-cli</title>
|
||
<meta charset="UTF-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet">
|
||
</head>
|
||
|
||
<body class="bg-gray-100">
|
||
<header>
|
||
<nav>
|
||
<ul><li>
|
||
<a href="/work-history/antharia/">
|
||
Web Design & Dev Intern at Antharia
|
||
</a>
|
||
</li><li>
|
||
<a href="/work-history/cyto-communications/">
|
||
Interactive Technologies Lead & Web Admin at Cyto Communications
|
||
</a>
|
||
</li><li>
|
||
<a href="/work-history/eyemaginations/">
|
||
Senior Web Engineer at Eyemaginations
|
||
</a>
|
||
</li><li>
|
||
<a href="/volunteering/theseed/">
|
||
Austin Give Camp - The SEED
|
||
</a>
|
||
</li><li>
|
||
<a href="/repos/json-query-chain/">
|
||
json-query-chain
|
||
</a>
|
||
</li><li>
|
||
<a href="/repos/blabber-comic/">
|
||
blabber-comic
|
||
</a>
|
||
</li><li>
|
||
<a href="/volunteering/code2college/">
|
||
Code 2 College
|
||
</a>
|
||
</li><li>
|
||
<a href="/repos/svgdir2sprite/">
|
||
svgdir2sprite
|
||
</a>
|
||
</li><li>
|
||
<a href="/repos/my_spells/">
|
||
my_spells
|
||
</a>
|
||
</li><li>
|
||
<a href="/volunteering/gabriellas-smile-foundation/">
|
||
Gabriella’s Smile Foundation
|
||
</a>
|
||
</li><li>
|
||
<a href="/work-history/q2/">
|
||
Developer III at Q2ebanking
|
||
</a>
|
||
</li><li>
|
||
<a href="/repos/team-cli/" aria-current="page">
|
||
team-cli
|
||
</a>
|
||
</li><li>
|
||
<a href="/work-history/allovue/">
|
||
Software Engineer at Allovue
|
||
</a>
|
||
</li><li>
|
||
<a href="/repos/sortable-recipes/">
|
||
sortable-recipes
|
||
</a>
|
||
</li><li>
|
||
<a href="/work-history/skillsengine/">
|
||
Lead Full-Stack Software Engineer at SkillsEngine
|
||
</a>
|
||
</li><li>
|
||
<a href="/repos/ember-select-light/">
|
||
ember-select-light
|
||
</a>
|
||
</li></ul>
|
||
</nav>
|
||
</header>
|
||
|
||
|
||
<main class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||
<div class="max-w-3x1 mx-auto mb-5">
|
||
<div class="-ml-2 mt-8 flex flex-wrap items-baseline">
|
||
<h1 class="ml-8 mt-2 text-lg font-medium text-gray-900">
|
||
team-cli
|
||
</h1>
|
||
<p class="ml-2 mt-1 text-sm text-gray-500 truncate">in </p>
|
||
</div>
|
||
</div>
|
||
<div class="bg-white overflow-hidden shadow sm:rounded-lg">
|
||
<div class="px-4 py-5 sm:p-6">
|
||
<blockquote>
|
||
<p>Automate all the things with a team-centric CLI. Abstract away annoying day-to-day tasks and eliminate tribal team knowledge by building your team their very own CLI.</p>
|
||
</blockquote>
|
||
<!--more-->
|
||
<p><a href="https://github.com/q2ebanking/team-cli">Fork on Github</a></p>
|
||
<h1>team-cli</h1>
|
||
<p><a href="https://badge.fury.io/js/team-cli"><img src="https://badge.fury.io/js/team-cli.svg" alt="npm version"></a></p>
|
||
<p>Automate all the things with a team-centric CLI. Abstract away annoying day-to-day tasks and eliminate tribal team knowledge by building your team their very own CLI.</p>
|
||
<h2>Getting Started</h2>
|
||
<h3>Initialize Project</h3>
|
||
<pre><code class="language-bash">mkdir teamname-cli
|
||
cd teamname-cli
|
||
git init
|
||
npm init
|
||
npm install --save team-cli
|
||
</code></pre>
|
||
<h3>Create Bin index.js</h3>
|
||
<p>Then in an <code>index.js</code> you could write the following:</p>
|
||
<pre><code class="language-javascript">#!/usr/bin/env node
|
||
|
||
const { resolve } = require('path');
|
||
const cli = require('team-cli');
|
||
|
||
const commandsDir = resolve(__dirname, 'commands');
|
||
cli(commandsDir);
|
||
</code></pre>
|
||
<h3>Point to Bin index.js in Package</h3>
|
||
<p>Then customize your <code>package.json</code> to include a path to the bin:</p>
|
||
<pre><code class="language-json">"bin": {
|
||
"NAME_OF_TOOL": "./index.js"
|
||
}
|
||
</code></pre>
|
||
<h3>Create Commands</h3>
|
||
<p>Then you may make a <code>commands</code> directory with files like <code>command-foo.js</code>:</p>
|
||
<pre><code class="language-javascript">const run = require('team-cli/terminal');
|
||
const { resolve } = require('path');
|
||
|
||
const script = resolve(__dirname, 'foo.sh'); // also supports bash .ps1 scripts
|
||
|
||
const action = async param => {
|
||
await run(script, param)
|
||
// Or, run any Node code you wish
|
||
};
|
||
|
||
module.exports = {
|
||
title: 'foo <param>',
|
||
description: 'Calls foo',
|
||
action,
|
||
}
|
||
</code></pre>
|
||
<h3>Try it out!</h3>
|
||
<pre><code class="language-bash">node ./index.js --help
|
||
</code></pre>
|
||
<h2>Options</h2>
|
||
<p>Any command can export the following options:</p>
|
||
<pre><code class="language-javascript">{
|
||
title: 'foo', // or 'foo <required_param>' or 'foo [optional_param]'
|
||
action: (param) => {} // function with param as a string or undefined
|
||
description: 'Calls foo', // optional
|
||
alias: 'f', // optional
|
||
option: ['-f, --force', 'Forces something to happen'], // optional, this will become available globally not just per-command
|
||
}
|
||
</code></pre>
|
||
<h2>For Your Users</h2>
|
||
<p>At any time a <code>--help</code> or <code>-h</code> may be passed to log commands to the console.</p>
|
||
<h3>Prompts</h3>
|
||
<p>Optionally, you may find it useful to walk users through a guided CLI experience with prompts to your users. I suggest <a href="https://www.npmjs.com/package/prompts">prompts</a> for this task, but any tool of your choice will work within an action.</p>
|
||
<h4>Example usage with prompts:</h4>
|
||
<pre><code class="language-javascript">const action = async (cmd) => {
|
||
if (!cmd) {
|
||
let { value: cmdResponse } = await prompts({
|
||
type: 'text',
|
||
name: 'value',
|
||
message: 'Which git command would you like to run?',
|
||
});
|
||
cmd = cmdResponse
|
||
}
|
||
await run(`git ${cmd}`, '~/aCoolRepo');
|
||
};
|
||
</code></pre>
|
||
<h3>Logging</h3>
|
||
<p>The environment's log level can be changed with <code>process.env.LOG_LEVEL</code> to any of <a href="https://github.com/winstonjs/winston">winston's</a> supported log levels including <code>verbose</code>.</p>
|
||
<p>To customize where logs are saved, pass a second param in your <code>index.js</code>'s <code>cli</code> call like so:</p>
|
||
<pre><code class="language-javascript">cli(commandsDir, logsDir)
|
||
</code></pre>
|
||
|
||
</div>
|
||
</div>
|
||
</main>
|
||
|
||
</body>
|
||
</html>
|
||
|
||
|
||
|