!if { man-summary go } then {
    summary go "Go is a tool for managing Go source code"
}

private go-package {
    # returns all the packages in $GOPATH
    find <!null> $GOPATH/src/ -type d -not -path */.* -> sed -r s:$GOPATH/src/::
}

autocomplete set go { [{
    "Flags": [ "help" ],
    "DynamicDesc": ({
        go help -> @[^The commands are..^Use]r -> tabulate: --map
    }),
    "FlagValues": {
        "get": [{
            "Flags": [ "github.com/" ]
        }],
        "run": [{
            "Dynamic": ({ go-package }),
            "AutoBranch": true
        }],
        "test": [{
            "Dynamic": ({ go-package }),
            "AutoBranch": true,
            "Flags": [ "./..." ]
        }],
        "mod": [{
            "DynamicDesc": ({
                go help mod -> @[^The commands are..^Use]r -> tabulate: --map
            })
        }],
        "help": [{
            "DynamicDesc": ({
                go help -> tabulate: --map
            })
        }],
        "build": [{ "Dynamic": ({ go-package }), "AutoBranch": true }],
        "install": [{ "Dynamic": ({ go-package }), "AutoBranch": true }],
        "fmt": [{ "IncFiles": true }],
        "vet": [{ "IncFiles": true }],
        "generate": [{ "IncFiles": true }]
    }
}] }
