# cmdy

> A simple cmd parser framework for node js/ts cli apps.

Latest version **1.4.5** (published 2022-09-16) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install cmdy
pnpm add cmdy
yarn add cmdy
bun add cmdy
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.4.5 |
| Published | 2022-09-16 |
| First published | 2021-12-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 32.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | majo418 |
| Maintainers | majo418 |
| Keywords | typescript, node, lib, cli, cmd, arg, command |

## Links

- npm: https://www.npmjs.com/package/cmdy
- Repository: https://github.com/majo418/cmdy
- Homepage: https://github.com/majo418/cmdy#readme
- Issues: https://github.com/majo418/cmdy/issues
- npm.io page: https://npm.io/package/cmdy

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 1.4.5 (latest) — 2022-09-16
- 1.4.4 — 2022-08-06
- 1.4.2 — 2022-06-19
- 1.4.1 — 2022-05-21
- 1.4.0 — 2022-05-08
- 1.3.6 — 2022-05-07
- 1.3.5 — 2022-05-07
- 1.3.2 — 2022-05-07
- 1.3.1 — 2022-05-07
- 1.2.6 — 2022-05-07
- 1.2.5 — 2022-03-29
- 1.2.4 — 2022-03-27
- 1.2.2 — 2022-03-22
- 1.2.1 — 2022-03-20
- 1.1.8 — 2022-01-24
- … 4 more at https://npm.io/package/cmdy/versions

## README

# cmdy

![CI/CD](https://github.com/majo418/cmdy/workflows/Publish/badge.svg)
![MIT](https://img.shields.io/badge/license-MIT-blue.svg)
![typescript](https://img.shields.io/badge/dynamic/json?style=plastic&color=blue&label=Typescript&prefix=v&query=devDependencies.typescript&url=https%3A%2F%2Fraw.githubusercontent.com%2Fmajo418%2Fcmdy%2Fmain%2Fpackage.json)
![npm](https://img.shields.io/npm/v/cmdy.svg?style=plastic&logo=npm&color=red)
![github](https://img.shields.io/badge/dynamic/json?style=plastic&color=darkviolet&label=GitHub&prefix=v&query=version&url=https%3A%2F%2Fraw.githubusercontent.com%2Fmajo418%2Fcmdy%2Fmain%2Fpackage.json)

![](https://img.shields.io/badge/dynamic/json?color=green&label=watchers&query=watchers&suffix=x&url=https%3A%2F%2Fapi.github.com%2Frepos%2Fmajo418%2Fcmdy)
![](https://img.shields.io/badge/dynamic/json?color=yellow&label=stars&query=stargazers_count&suffix=x&url=https%3A%2F%2Fapi.github.com%2Frepos%2Fmajo418%2Fcmdy)
![](https://img.shields.io/badge/dynamic/json?color=orange&label=subscribers&query=subscribers_count&suffix=x&url=https%3A%2F%2Fapi.github.com%2Frepos%2Fmajo418%2Fcmdy)
![](https://img.shields.io/badge/dynamic/json?color=navy&label=forks&query=forks&suffix=x&url=https%3A%2F%2Fapi.github.com%2Frepos%2Fmajo418%2Fcmdy)
![](https://img.shields.io/badge/dynamic/json?color=darkred&label=open%20issues&query=open_issues&suffix=x&url=https%3A%2F%2Fapi.github.com%2Frepos%2Fmajo418%2Fcmdy)

# table of contents 
- [cmdy](#cmdy)
- [table of contents](#table-of-contents)
- [about](#about)
- [Features](#features)
  - [General](#general)
  - [cmd (sub cmd)](#cmd-sub-cmd)
  - [flags](#flags)
- [Getting started](#getting-started)
  - [1. Install package](#1-install-package)
  - [2. Add example code](#2-add-example-code)
- [npm scripts](#npm-scripts)
  - [use](#use)
  - [base scripts](#base-scripts)
  - [watch mode](#watch-mode)
- [contribution](#contribution)

# about
"cmdy" is a node js cmd argument framework that looks like the docker cli tool.

# Features

## General
 - root and sub commands
 - differend cmd callbacks
 - state and value flags

## cmd (sub cmd)
 - own flags
 - global gflas
 - premade or custom help function/generator
 - cmd groups

## flags
 - value flags with types
 - default values
 - aliases
 - shorthand

# Getting started
## 1. Install package
```sh
npm i cmdy
```

## 2. Add example code
```ts
import { Flag, parseCmd, CmdDefinition } from "../src/index"

const force: Flag = {
    name: "force",
    description: "The force flag",
}

const port: Flag = {
    name: "port",
    description: "The port flag",
    shorthand: "p",
    types: ["number"]
}

const verbose: Flag = {
    name: "verbose",
    description: "The verbose flag",
    shorthand: "V",
}

const version: Flag = {
    name: "version",
    description: "The verbose flag",
    alias: ["v", "ve", "ver", "vers", "versi", "versio"],
    shorthand: "v",
}

const ps: CmdDefinition = {
    name: "ps",
    description: "The ps command",
    flags: [
        port
    ],
    allowUnknownArgs: true,
    exe: async (res) => console.log("ps: ", res.cmd.name + "\nres-data:\n", res.flags, res.valueFlags)
}

const start: CmdDefinition = {
    name: "start",
    description: "The start command",
    flags: [
        port
    ],
    exe: async (res) => console.log("start: ", res.cmd.name + "\nres-data:\n", res.flags, res.valueFlags)
}

const stop: CmdDefinition = {
    name: "stop",
    description: "The stop command",
    flags: [
        force
    ],
    exe: async (res) => console.log("stop: ", res.cmd.name + "\nres-data:\n", res.flags, res.valueFlags)
}

const root: CmdDefinition = {
    name: "testcmd",
    description: "The root testcmd command",
    cmds: [
        start,
        stop,
        ps,
    ],
     flags: [
        version
    ],
    //exe: async () => console.log("asdasdd")
}

parseCmd({
    cmd: root,
    globalFlags: [
        verbose
    ]
}).exe()
```

# npm scripts
The npm scripts are made for linux but can also work on mac and windows.
## use
You can run npm scripts in the project folder like this:
```sh
npm run <scriptname>
```
Here is an example:
```sh
npm run test
```

## base scripts
You can find all npm scripts in the `package.json` file.
This is a list of the most important npm scripts:
 - test // test the app
 - build // build the app
 - exec // run the app
 - start // build and run the app

## watch mode
Like this example you can run all npm scripts in watch mode:
```sh
npm run start:watch
```

# contribution
 - 1. fork the project
 - 2. implement your idea
 - 3. create a pull/merge request
```ts
// please create seperated forks for different kind of featues/ideas/structure changes/implementations
```

---
**cya ;3**  
*by majo418*

---
_Source: https://npm.io/package/cmdy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
