Getopts Parser Generator

VerifiedSafe

Generate argument parsing code for shell scripts with short/long options and validation. Full usage documentation support.

Sby Skills Guide Bot
DevelopmentIntermediate
3/2/2026
Claude CodeCursorWindsurfCodex
#bash#shell-scripting#argument-parsing#getopts#cli

Recommended for

Automated summary

Generates getopts-based argument parsing code for shell scripts with short and long options, validation, and help text.

Strengths

  • Provides a complete working pattern, including translation of long options into getopts short flags
  • Includes usage/die helpers, value validation (format whitelisting), and checks for required positional arguments
  • Covers practical guards such as input file existence and overwrite protection unless --force is passed

Limitations

  • Stays within getopts: no GNU getopt, subcommands, or advanced features like option grouping
  • The long-option rewriting loop does not handle --option=value syntax
  • Shell completion script generation is listed as a target process but is not described among the capabilities
When to use it

Use it when a bash script needs to move from ad-hoc $1/$2 handling to a clean CLI with short/long options and validation.

When not to use it

Avoid it if the script needs complex subcommands, --option=value syntax, or native long options via GNU getopt.

Security analysis

Safe
Quality score82/100

The skill provides legitimate shell argument-parsing templates and does not instruct destructive, exfiltrating, or obfuscated actions. Bash is listed as an allowed tool, but its use is limited to normal script generation and validation.

No concerns found

How this analysis is made

Examples

Backup script options
Add argument parsing to backup.sh: -v verbose, -o output directory, -f format (text|json), -F force, plus a required source path. Include a --help screen and error messages for unknown options.
Deploy CLI with validation
Generate a getopts-based parser for a deploy script with --env, --region and --dry-run, plus a required service name. Validate that env is one of dev, staging or prod.
Refactor ad-hoc args
Refactor my bash script's manual $1/$2 handling into getopts with long options, required-argument checks, and proper exit codes on invalid input.

name: getopts-parser-generator description: Generate getopts-based argument parsing for shell scripts with short/long options and validation. allowed-tools: Read, Write, Edit, Bash, Glob, Grep

Getopts Parser Generator

Generate getopts-based argument parsing for shell scripts.

Capabilities

  • Generate getopts parsing code
  • Support short and long options
  • Implement option validation
  • Create help text generation
  • Handle required arguments
  • Generate usage documentation

Usage

Invoke this skill when you need to:

  • Add argument parsing to shell scripts
  • Support short and long options
  • Validate argument values
  • Generate help text

Generated Patterns

Getopts with Long Options

#!/usr/bin/env bash

# Default values
VERBOSE=false
OUTPUT=""
FORMAT="text"
FORCE=false

# Usage function
usage() {
    cat <<EOF
Usage: $(basename "$0") [OPTIONS] <input>

Options:
    -h, --help              Show this help
    -v, --verbose           Enable verbose output
    -o, --output FILE       Output file (default: stdout)
    -f, --format FORMAT     Output format: text, json, csv (default: text)
    -F, --force             Force overwrite existing files

Arguments:
    input                   Input file to process
EOF
}

# Parse options
parse_options() {
    # Transform long options to short ones
    for arg in "$@"; do
        shift
        case "$arg" in
            '--help')    set -- "$@" '-h' ;;
            '--verbose') set -- "$@" '-v' ;;
            '--output')  set -- "$@" '-o' ;;
            '--format')  set -- "$@" '-f' ;;
            '--force')   set -- "$@" '-F' ;;
            *)           set -- "$@" "$arg" ;;
        esac
    done

    # Parse short options
    local OPTIND opt
    while getopts ":hvo:f:F" opt; do
        case "$opt" in
            h) usage; exit 0 ;;
            v) VERBOSE=true ;;
            o) OUTPUT="$OPTARG" ;;
            f)
                case "$OPTARG" in
                    text|json|csv) FORMAT="$OPTARG" ;;
                    *) die "Invalid format: $OPTARG" ;;
                esac
                ;;
            F) FORCE=true ;;
            :) die "Option -$OPTARG requires an argument" ;;
            \?) die "Unknown option: -$OPTARG" ;;
        esac
    done

    shift $((OPTIND - 1))

    # Remaining arguments
    if [[ $# -lt 1 ]]; then
        usage
        die "Missing required argument: input"
    fi

    INPUT="$1"
    shift

    # Extra arguments
    EXTRA_ARGS=("$@")
}

die() {
    echo "Error: $*" >&2
    exit 1
}

# Parse and validate
parse_options "$@"

# Validation
[[ -f "$INPUT" ]] || die "Input file not found: $INPUT"
[[ -n "$OUTPUT" && -f "$OUTPUT" && "$FORCE" != true ]] && \
    die "Output file exists: $OUTPUT (use --force to overwrite)"

Target Processes

  • shell-script-development
  • shell-completion-scripts
  • argument-parser-setup

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/getopts-parser-generator-mm8o51xd/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/getopts-parser-generator-mm8o51xd' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/getopts-parser-generator-mm8o51xd/download' --output '.skill-downloads/getopts-parser-generator-mm8o51xd/SKILL.md.part' && mv '.skill-downloads/getopts-parser-generator-mm8o51xd/SKILL.md.part' '.skill-downloads/getopts-parser-generator-mm8o51xd/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

Tools declared by the author (check availability in your agent): Read, Write, Edit, Bash, Glob, Grep

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/getopts-parser-generator-mm8o51xd/SKILL.md' && test -s '.skill-downloads/getopts-parser-generator-mm8o51xd/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/getopts-parser-generator' && cp -R '.skill-downloads/getopts-parser-generator-mm8o51xd' '.claude/skills/getopts-parser-generator'

Cursor
test -f '.skill-downloads/getopts-parser-generator-mm8o51xd/SKILL.md' && test -s '.skill-downloads/getopts-parser-generator-mm8o51xd/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/getopts-parser-generator' && cp -R '.skill-downloads/getopts-parser-generator-mm8o51xd' '.cursor/skills/getopts-parser-generator'

Codex
test -f '.skill-downloads/getopts-parser-generator-mm8o51xd/SKILL.md' && test -s '.skill-downloads/getopts-parser-generator-mm8o51xd/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/getopts-parser-generator' && cp -R '.skill-downloads/getopts-parser-generator-mm8o51xd' '.agents/skills/getopts-parser-generator'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/getopts-parser-generator-mm8o51xd'

openskills read 'getopts-parser-generator-mm8o51xd'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/getopts-parser-generator-mm8o51xd/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills