# no

A tiny command-line filter that toggles a leading `no ` on each line — handy
for flipping Cisco-style configuration commands, where `no <command>` negates
`<command>`.

`no` reads from **stdin** (or named **files**) and writes to **stdout**. By
default it *toggles* the prefix: lines that begin with `no ` have it removed,
and lines that don't have it added. It can also be told to unconditionally add
or strip the prefix.

```
$ printf 'apple\nno banana\n' | no
no apple
banana
```

Leading indentation is preserved, so it works on indented config blocks:

```
$ printf 'interface Gig0/1\n shutdown\n no ip address\n' | no
no interface Gig0/1
 no shutdown
 ip address
```

## Usage

```
no [OPTION]... [FILE]...
```

With no `FILE`, or when `FILE` is `-`, `no` reads standard input.

| Option | Long form | Description |
|--------|-----------|-------------|
| `-t` | `--toggle`      | Default. Add `no ` where it is missing, remove it where present. |
| `-a` | `--add`         | Always add a leading `no ` if it isn't present; never strip. |
| `-d` | `--delete`      | Always strip a leading `no ` if it is present; never add. |
| `-i` | `--ignore-case` | Match a leading `no` case-insensitively (e.g. `NO `). |
| `-v` | `--version`     | Print version information and exit. |
| `-h` | `--help`        | Print a usage summary and exit (also `--usage`, `-?`). |

`-t`, `-a`, and `-d` are mutually exclusive; the last one on the command line
wins. `--` ends option parsing (everything after it is a file name), and an
unknown option is an error.

### Behavior notes

- Leading whitespace is preserved; the prefix is added/removed after it.
- Blank and whitespace-only lines pass through unchanged.
- A trailing newline is emitted only if the input line had one.
- `--add` and `--delete` are idempotent (running them twice changes nothing
  the second time); a double `--toggle` round-trips back to the original.

### Examples

Toggle the prefix on every line of a file:

```
cat config.txt | no
no config.txt          # equivalent, reading the file directly
```

Strip a leading `no ` wherever it appears:

```
no --delete config.txt
```

## Building

Requires a C++ compiler (`g++` by default) and `make`.

```
make
```

This produces the `no` executable in the current directory.

Run the test suite with:

```
make check
```

## Installing

Install the binary and manpage (defaults to `/usr/local`):

```
sudo make install
```

Choose a different prefix with `PREFIX`:

```
sudo make install PREFIX=/usr
```

Remove it again:

```
sudo make uninstall
```

### Building a Debian package

On Debian/Ubuntu/Kali you can build a `.deb` that installs the program and its
manpage under `/usr`:

```
make deb
sudo dpkg -i no_*.deb
```

Remove the installed package with `sudo apt remove no` (or `dpkg -r no`).

## License

GNU General Public License v3 or later (GPLv3+). See the header of `no.cpp` for
details.

By Eli Fulkerson — <http://www.elifulkerson.com>
