DEV Community

Cover image for Split commands and options from CLI
Lucas.T
Lucas.T

Posted on

2 2

Split commands and options from CLI

Hi 👋

This is a very small 1.33 KB package that does just one simple task to get the user's input data passed from your terminal, split it and send it back to and object, That's it, no big config or API just a tiny function.

Install

npm i argv-user-input
Enter fullscreen mode Exit fullscreen mode

Usage 💡

#!/usr/bin/env node
import parseArgvData from 'argv-user-input';
const argvs = parseArgvData();
Enter fullscreen mode Exit fullscreen mode

foo.js

With no commands or options.

$ foo.js 
Enter fullscreen mode Exit fullscreen mode
console.log(argvs);
/*
{
  commands: [],
  options: {},
}
*/
Enter fullscreen mode Exit fullscreen mode

With commands and no option.

$ foo.js start test
Enter fullscreen mode Exit fullscreen mode
console.log(argvs);
/*
{
  commands: ['start', 'test'],
  options: {},
}
*/
Enter fullscreen mode Exit fullscreen mode

With commands and options.

$ foo.js start test --skip -p ./dev
Enter fullscreen mode Exit fullscreen mode
console.log(argvs);
/*
{
  commands: ['start', 'test'],
  options: {
    skip: true,
    p: './dev'
  },
}
*/
Enter fullscreen mode Exit fullscreen mode

With option and no command.

$ foo.js --name=foo
Enter fullscreen mode Exit fullscreen mode
console.log(argvs);
/*
{
  commands: [],
  options: {
    name: 'foo'
  },
}
*/
Enter fullscreen mode Exit fullscreen mode

Good code and have fun ✨

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay