duckopt

package module
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: GPL-3.0 Imports: 6 Imported by: 3

README

duckopt

duckopt is a docopt wrapper library for Go.

Installation

go get crdx.org/duckopt/v2

Usage

import (
    "fmt"

    "crdx.org/duckopt/v2"
)

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
    `
}

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() {
    opts := duckopt.MustBind[Opts](getUsage(), "$0")
    fmt.Printf("%+v\n", 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 Bind

func Bind[T any](usage string, placeholder ...string) (*T, error)

Bind parses a usage string and returns an instance of *T, or an error if it can't be parsed.

placeholder is an optional placeholder in the usage string that should be replaced with the name of the program.

func MustBind

func MustBind[T any](usage string, placeholder ...string) *T

MustBind parses a usage string and returns an instance of *T, or panics if it can't be parsed.

placeholder is an optional placeholder in the usage string that should be replaced with the name of the program.

func MustParse

func MustParse(usage string, placeholder ...string) docopt.Opts

MustParse parses a usage string and returns an instance of docopt.Opts, or panics if it can't be parsed.

placeholder is an optional placeholder in the usage string that should be replaced with the name of the program.

func Parse

func Parse(usage string, placeholder ...string) (docopt.Opts, error)

Parse parses a usage string and returns an instance of docopt.Opts, or an error if it can't be parsed.

placeholder is an optional placeholder in the usage string that should be replaced with the name of the program.

Types

This section is empty.

Jump to

Keyboard shortcuts

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