duckopt

package module
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2023 License: GPL-3.0 Imports: 7 Imported by: 2

README

duckopt

duckopt is a docopt wrapper library for Go.

Installation

go get crdx.org/duckopt

Usage

import (
    "fmt"
    "crdx.org/duckopt"
)

func getUsage() string {
    return `
        Usage:
            $0 [options] command <arg>

        Options:
            --dry-run         Do a dry run
            -v, --verbose     Be verbose
            -C, --no-color    Disable colours
            -h, --help        Show help
    `
}

type Opts struct {
    Command bool   `docopt:"command"`
    Arg     string `docopt:"<arg>"`
    DryRun  bool   `docopt:"--dry-run"`
    Verbose bool   `docopt:"--verbose"`
    NoColor bool   `docopt:"--no-color"`
}

func main() {
    var opts Opts
    if err := duckopt.Parse(getUsage(), "$0").Bind(&opts); err != nil {
        panic(err)
    }
    fmt.Println(opts)
}

Contributions

Open an issue or send a pull request.

Licence

GPLv3.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(usage string, programNamePlaceholder string) docopt.Opts

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL