PHPackages                             smeghead/phel-getopt - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. smeghead/phel-getopt

ActiveLibrary[CLI &amp; Console](/categories/cli)

smeghead/phel-getopt
====================

parse CLI arguments and options.

v0.0.6(5mo ago)310MITPHPCI passing

Since Jan 11Pushed 5mo agoCompare

[ Source](https://github.com/smeghead/phel-getopt)[ Packagist](https://packagist.org/packages/smeghead/phel-getopt)[ RSS](/packages/smeghead-phel-getopt/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (1)Versions (8)Used By (0)

phel-getopt
===========

[](#phel-getopt)

Natural and safe command-line argument parsing for phel CLI programs.

[![Testing](https://github.com/smeghead/phel-getopt/actions/workflows/ci.yml/badge.svg?event=push)](https://github.com/smeghead/phel-getopt/actions/workflows/ci.yml/badge.svg?event=push) [![Latest Stable Version](https://camo.githubusercontent.com/20f32cdf6e69480fc70dfecd5cccc96311d86a2a818e55efaa51db73a1358004/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736d6567686561642f7068656c2d6765746f70742e737667)](https://packagist.org/packages/smeghead/phel-getopt) [![Total Downloads](https://camo.githubusercontent.com/7dfa00c81d98d6a357e3aa5e9033a214ccb51a880109c764b59b41a059885ecb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736d6567686561642f7068656c2d6765746f70742e737667)](https://packagist.org/packages/smeghead/phel-getopt) [![License](https://camo.githubusercontent.com/74d8837f092be7df6fbebcb9ca029b10cf5eb99f6edae738741c17839d99314d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f736d6567686561642f7068656c2d6765746f70742e737667)](LICENSE)

A small and focused command-line option and argument parser for phel.

Overview
--------

[](#overview)

`phel-getopt` is a library for parsing command-line options and arguments in phel CLI programs. It provides clear, predictable, and phel-friendly command-line parsing with a simple and explicit API.

Installation
------------

[](#installation)

```
composer require smeghead/phel-getopt
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
(ns app\core
  (:require smeghead\getopt\getopt))

(def options ["-a"         # short option `a` without value
              "--output:"  # long option `output` with value(required)
             ])
(def result (getopt/getopt argv options))

(println "options:" (result :options))
(println "arguments:" (result :args))
```

```
$ vendor/bin/phel run examples/example.phel -a --output ./output.txt one two
options: {:a true, :output ./output.txt}
arguments: [one two]
```

### Option Definitions

[](#option-definitions)

Options are defined as strings with the following format:

FormatMeaningExample`"-x"`Short option without value`"-a"``"-x:"`Short option with required value`"-o:"``"--name"`Long option without value`"--verbose"``"--name:"`Long option with required value`"--output:"`The colon suffix (`:`) indicates that an option requires a value.

### Result Structure

[](#result-structure)

The `getopt` function returns a `Result` struct with three fields:

- `:args` - Vector of positional arguments
- `:options` - Map of option keywords to their values
- `:errors` - Vector of error messages (empty if successful)

### Practical Examples

[](#practical-examples)

#### Multiple Arguments

[](#multiple-arguments)

```
(def options [])
(def result (getopt/getopt ["one" "two"] options))
;; result: {:args ["one" "two"], :options {}, :errors []}
```

#### Short Options with Values

[](#short-options-with-values)

```
(def options ["-a:"])
(def result (getopt/getopt ["-a" "param" "one" "two"] options))
;; result: {:args ["one" "two"], :options {:a "param"}, :errors []}
```

#### Combined Short Options

[](#combined-short-options)

```
(def options ["-a:"])
(def result (getopt/getopt ["-aparam" "one" "two"] options))
;; result: {:args ["one" "two"], :options {:a "param"}, :errors []}
```

#### Long Options with Values

[](#long-options-with-values)

```
(def options ["--amazing:"])
(def result (getopt/getopt ["--amazing=man" "one" "two"] options))
;; result: {:args ["one" "two"], :options {:amazing "man"}, :errors []}
```

#### Error Handling

[](#error-handling)

```
(def options ["-a"])
(def result (getopt/getopt ["--unknown" "one" "two"] options))
;; result: {:args ["one" "two"], :options {}, :errors ["Unknown option: \"--unknown\""]}
```

#### Stop Parsing with --

[](#stop-parsing-with---)

```
(def options ["-a"])
(def result (getopt/getopt ["--" "-a" "one" "two"] options))
;; result: {:args ["-a" "one" "two"], :options {}, :errors []}
```

API Reference
-------------

[](#api-reference)

### getopt/getopt

[](#getoptgetopt)

```
(defn getopt [args options])
```

- `args` - Vector of command-line arguments (normalized `argv`)
- `options` - Vector of option definition strings
- Returns - `Result` struct with `:args`, `:options`, and `:errors` fields

Notes
-----

[](#notes)

This library assumes a normalized `argv` provided by Phel v0.28.0+ and focuses solely on option and argument parsing. For development setup instructions, see the original README history.

Development
-----------

[](#development)

### Initial

[](#initial)

```
composer init
composer require phel-lang/phel-lang:dev-main
vendor/bin/phel init
```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance72

Regular maintenance activity

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity30

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

7

Last Release

156d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/112476?v=4)[smeghead](/maintainers/smeghead)[@smeghead](https://github.com/smeghead)

---

Top Contributors

[![smeghead](https://avatars.githubusercontent.com/u/112476?v=4)](https://github.com/smeghead "smeghead (26 commits)")

### Embed Badge

![Health badge](/badges/smeghead-phel-getopt/health.svg)

```
[![Health](https://phpackages.com/badges/smeghead-phel-getopt/health.svg)](https://phpackages.com/packages/smeghead-phel-getopt)
```

###  Alternatives

[illuminate/console

The Illuminate Console package.

13046.0M6.5k](/packages/illuminate-console)[styleci/cli

The CLI tool for StyleCI

71470.5k9](/packages/styleci-cli)[winbox/args

Windows command-line formatter

20720.9k21](/packages/winbox-args)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
