# simple-flags

> Simple and practical module to generate and organize command line flags

Latest version **1.2.4** (published 2018-01-22) · ISC license · 0 weekly downloads

## Install

```sh
npm install simple-flags
pnpm add simple-flags
yarn add simple-flags
bun add simple-flags
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.4 |
| Published | 2018-01-22 |
| First published | 2016-08-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Philippe Assis |
| Maintainers | philippeassis |
| Keywords | flags, flag, cli, args, arguments, opt, opts |

## Links

- npm: https://www.npmjs.com/package/simple-flags
- Repository: https://github.com/PhilippeAssis/node-simple-flags
- Homepage: https://github.com/PhilippeAssis/node-simple-flags#readme
- Issues: https://github.com/PhilippeAssis/node-simple-flags/issues
- npm.io page: https://npm.io/package/simple-flags

## Dependencies (1)

- [colors](https://npm.io/package/colors.md) ^1.1.2

## 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.2.4 (latest) — 2018-01-22
- 1.2.3 — 2018-01-22
- 1.2.2 — 2017-11-05
- 1.2.0 — 2017-11-05
- 1.1.0 — 2017-11-05
- 1.0.1 — 2016-09-19
- 1.0.0 — 2016-08-25

## README

# Simple Flags

The aim of this module is to facilitate the capture and manulação of badeiras on the command line. There are several modules that provide a similar result, but I chose to write this to create a simpler architecture for the configuration data.

## Installation
`npm install --save simple-args`

## Test
In node_modules/simple-args, run: `npm run test`

## Features

#### option.args
Get the names of the arguments that are not pre-defined, ie its definition is from your order.

#### Booleans
All Boolean object to be declared as an argument will have its inverted default value if true is false, is false is true.

You can create aliases for an object. When the value is not pre defined, use `{objectName: ['a']}`, passing the alias in an array. When the value is definiod use `{alias: [ 'a', 'b'], value: "123"}`

### Description
To describe the flags, just add **description**. When you run `--help` the full description of the schema will be displayed
```javascript
{
  print: {
    description: "Print all",
    default: true
  }
}
```

### Print description's, --help
By default the `--help` flag is available when no other arument is passed before it.

```bash
myapp --help
```
You can force the display of the description of the flags using [execute](#execute) and calling within it the function `this.help()`.

### Execute
You can execute functions directly when a flag is declared. If the function has a return other than `undefined` the value will be set for the parameter.

```javascript
const params = flags({
  print: {
    execute(){
      console.log(this.schema)
    }
  },
  support: {
    execute(){
      this.help() // print description's
    }
  },
  calc: {
    execute(){
      return 1 + 1 // params.calc === 2
    }
  }
})
```

## Example
### Code
```javascript
//test.js
var flags = require('simple-flags')

// Default options
var options = {
    "args": ["author", "website"],
    "coffee": false,
    "not": true,
    "developer": null,
    "country": {
        aliases: ['c', 'country'],
        default: "Do not be 'reaça'"
    }
}

console.log(flags(options))
```

### Command
```shell
node test.js 'Philippe Assis' ${HOME} --site www.philippeassis.com --github=https://github.com/PhilippeAssis -d --coffee -not -c 'Brazil=#foraTemer'
```

### Result
```javascript
{ coffee: true,
  not: false,
  developer: true,
  country: 'Brazil=Fora Temer',
  site: 'www.philippeassis.com',
  github: 'https://github.com/PhilippeAssis',
  author: 'Philippe Assis',
  website: '/home/assis' }
  ```

  ## Deprecation'
  ### alias to aliases
  The `alias` priority will be replaced for `aliases` in the future, necessarily passing an array

```javascript
"country": {
    aliases: ['c', 'country']
}
```
### value to default
The `value` priority will be replaced for `default` in the future

```javascript
"country": {
    default: "#foraTemer"
}
```

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