MCPcopy Index your code
hub / github.com/docopt/docopt.go

github.com/docopt/docopt.go @0.6.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.6.2 ↗ · + Follow
139 symbols 545 edges 19 files 8 documented · 6%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

docopt-go

Build Status Coverage Status GoDoc

An implementation of docopt in the Go programming language.

docopt helps you create beautiful command-line interfaces easily:

package main

import (
    "fmt"
    "github.com/docopt/docopt-go"
)

func main() {
      usage := `Naval Fate.

Usage:
  naval_fate ship new <name>...
  naval_fate ship <name> move <x> <y> [--speed=<kn>]
  naval_fate ship shoot <x> <y>
  naval_fate mine (set|remove) <x> <y> [--moored|--drifting]
  naval_fate -h | --help
  naval_fate --version

Options:
  -h --help     Show this screen.
  --version     Show version.
  --speed=<kn>  Speed in knots [default: 10].
  --moored      Moored (anchored) mine.
  --drifting    Drifting mine.`

      arguments, _ := docopt.Parse(usage, nil, true, "Naval Fate 2.0", false)
      fmt.Println(arguments)
}

docopt parses command-line arguments based on a help message. Don't write parser code: a good help message already has all the necessary information in it.

Installation

⚠ Use the alias “docopt-go”. To use docopt in your Go code:

import "github.com/docopt/docopt-go"

To install docopt according to your $GOPATH:

$ go get github.com/docopt/docopt-go

API

func Parse(doc string, argv []string, help bool, version string,
    optionsFirst bool, exit ...bool) (map[string]interface{}, error)

Parse argv based on the command-line interface described in doc.

Given a conventional command-line help message, docopt creates a parser and processes the arguments. See https://github.com/docopt/docopt#help-message-format for a description of the help message format. If argv is nil, os.Args[1:] is used.

docopt returns a map of option names to the values parsed from argv, and an error or nil.

More documentation for docopt is available at GoDoc.org.

Testing

All tests from the Python version are implemented and passing at Travis CI. New language-agnostic tests have been added to test_golang.docopt.

To run tests for docopt-go, use go test.

Core symbols most depended-on inside this repo

newOption
called by 203
docopt.go
newArgument
called by 144
docopt.go
Error
called by 80
docopt.go
Parse
called by 59
docopt.go
eq
called by 58
docopt.go
newRequired
called by 54
docopt.go
match
called by 53
docopt.go
newEither
called by 26
docopt.go

Shape

Function 100
Method 29
Struct 6
TypeAlias 4

Languages

Go100%

Modules by API surface

docopt.go70 symbols
docopt_test.go46 symbols
examples/git/git.go4 symbols
examples/config_file/config_file_example.go4 symbols
examples/type_assert/type_assert_example.go1 symbols
examples/quick/quick_example.go1 symbols
examples/options_shortcut/options_shortcut_example.go1 symbols
examples/options/options_example.go1 symbols
examples/odd_even/odd_even_example.go1 symbols
examples/naval_fate/naval_fate.go1 symbols
examples/git/remote/git_remote.go1 symbols
examples/git/push/git_push.go1 symbols

For agents

$ claude mcp add docopt.go \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page