Merge pull request #21 from tsandall/fix-packages

Fix package dependencies
This commit is contained in:
Torin Sandall
2016-04-04 10:58:26 -07:00
41 changed files with 212 additions and 165 deletions
Generated
+5 -24
View File
@@ -1,77 +1,58 @@
hash: 60660dbeea966624ef47c09512b10812b4fd5e9e82876d915ca69d72dbc3157c
updated: 2016-03-29T17:05:39.985980976-07:00
hash: a0c5cde7a83a30f6cffbeaf27a08a4c566b0d740e24ab8bb3161f9315cd1d58e
updated: 2016-04-04T10:43:40.051156348-07:00
imports:
- name: github.com/armon/consul-api
version: dcfedd50ed5334f96adee43fc88518a4f095e15c
repo: https://github.com/armon/consul-api
- name: github.com/BurntSushi/toml
version: bbd5bb678321a0d6e58f1099321dfa73391c1b6f
repo: https://github.com/BurntSushi/toml
- name: github.com/coreos/go-etcd
version: 003851be7bb0694fe3cc457a49529a19388ee7cf
repo: https://github.com/coreos/go-etcd
- name: github.com/cpuguy83/go-md2man
version: 2724a9c9051aa62e9cca11304e7dd518e9e41599
repo: https://github.com/cpuguy83/go-md2man
- name: github.com/hashicorp/hcl
version: 2604f3bda7e8960c1be1063709e7d7f0765048d0
repo: https://github.com/hashicorp/hcl
- name: github.com/kr/pretty
version: add1dbc86daf0f983cd4a48ceb39deb95c729b67
repo: https://github.com/kr/pretty
- name: github.com/kr/pty
version: f7ee69f31298ecbe5d2b349c711e2547a617d398
repo: https://github.com/kr/pty
- name: github.com/kr/text
version: bb797dc4fb8320488f47bf11de07a733d7233e1f
repo: https://github.com/kr/text
- name: github.com/magiconair/properties
version: c265cfa48dda6474e208715ca93e987829f572f8
repo: https://github.com/magiconair/properties
- name: github.com/mitchellh/mapstructure
version: d2dd0262208475919e1a362f675cfc0e7c10e905
repo: https://github.com/mitchellh/mapstructure
- name: github.com/PuerkitoBio/pigeon
version: a5221784523de14130c00a8c389148a1b2ad260c
- name: github.com/russross/blackfriday
version: b43df972fb5fdf3af8d2e90f38a69d374fe26dd0
repo: https://github.com/russross/blackfriday
- name: github.com/shurcooL/sanitized_anchor_name
version: 10ef21a441db47d8b13ebcc5fd2310f636973c77
repo: https://github.com/shurcooL/sanitized_anchor_name
- name: github.com/spf13/cast
version: 27b586b42e29bec072fe7379259cc719e1289da6
repo: https://github.com/spf13/cast
- name: github.com/spf13/cobra
version: c678ff029ee250b65714e518f4f5c5cb934955de
version: 4c05eb1145f16d0e6bb4a3e1b6d769f4713cb41f
- name: github.com/spf13/jwalterweatherman
version: 33c24e77fb80341fe7130ee7c594256ff08ccc46
repo: https://github.com/spf13/jwalterweatherman
- name: github.com/spf13/pflag
version: 7f60f83a2c81bc3c3c0d5297f61ddfa68da9d3b7
- name: github.com/spf13/viper
version: c975dc1b4eacf4ec7fdbf0873638de5d090ba323
repo: https://github.com/spf13/viper
- name: github.com/ugorji/go
version: a396ed22fc049df733440d90efe17475e3929ccb
repo: https://github.com/ugorji/go
- name: github.com/xordataexchange/crypt
version: 749e360c8f236773f28fc6d3ddfce4a470795227
repo: https://github.com/xordataexchange/crypt
- name: golang.org/x/crypto
version: 9e7f5dc375abeb9619ea3c5c58502c428f457aa2
- name: golang.org/x/net
version: 31df19d69da8728e9220def59b80ee577c3e48bf
version: 024ed629fd292398cfd43c9678a5bf004f7defdc
- name: golang.org/x/text
version: 1b466db55e0ba5d56ef5315c728216b42f796491
- name: golang.org/x/tools
version: 84e7bc0dd39bab24b696dde4d714641fa738f945
version: f2e4f834ecb7acd0edd3ba4d2d777b55f1a42470
subpackages:
- cmd/goimports
- name: gopkg.in/fsnotify.v1
version: 875cf421b32f8f1b31bd43776297876d01542279
repo: https://gopkg.in/fsnotify.v1
- name: gopkg.in/yaml.v2
version: a83829b6f1293c91addabc89d0571c246397bbf4
repo: https://gopkg.in/yaml.v2
devImports: []
+5 -1
View File
@@ -4,6 +4,10 @@ go:
- 1.4.2
- 1.5.1
- tip
before_install:
- mkdir -p bin
- curl -Lso bin/shellcheck https://github.com/caarlos0/shellcheck-docker/releases/download/v0.4.3/shellcheck
- chmod +x bin/shellcheck
script:
- go test -v ./...
- PATH=$PATH:$PWD/bin go test -v ./...
- go build
+39 -17
View File
@@ -61,7 +61,7 @@ __contains_word()
__handle_reply()
{
__debug "${FUNCNAME}"
__debug "${FUNCNAME[0]}"
case $cur in
-*)
if [[ $(type -t compopt) = "builtin" ]]; then
@@ -75,7 +75,7 @@ __handle_reply()
fi
COMPREPLY=( $(compgen -W "${allflags[*]}" -- "$cur") )
if [[ $(type -t compopt) = "builtin" ]]; then
[[ $COMPREPLY == *= ]] || compopt +o nospace
[[ "${COMPREPLY[0]}" == *= ]] || compopt +o nospace
fi
# complete after --flag=abc
@@ -88,11 +88,13 @@ __handle_reply()
flag="${cur%%=*}"
__index_of_word "${flag}" "${flags_with_completion[@]}"
if [[ ${index} -ge 0 ]]; then
COMPREPLY=() PREFIX="" cur="${cur#*=}"
COMPREPLY=()
PREFIX=""
cur="${cur#*=}"
${flags_completion[${index}]}
if [ -n "${ZSH_VERSION}" ]; then
# zfs completion needs --flag= prefix
eval COMPREPLY=( "\${COMPREPLY[@]/#/${flag}=}" )
eval "COMPREPLY=( \"\${COMPREPLY[@]/#/${flag}=}\" )"
fi
fi
fi
@@ -123,6 +125,10 @@ __handle_reply()
fi
COMPREPLY=( $(compgen -W "${completions[*]}" -- "$cur") )
if [[ ${#COMPREPLY[@]} -eq 0 && ${#noun_aliases[@]} -gt 0 && ${#must_have_one_noun[@]} -ne 0 ]]; then
COMPREPLY=( $(compgen -W "${noun_aliases[*]}" -- "$cur") )
fi
if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
declare -F __custom_func >/dev/null && __custom_func
fi
@@ -145,7 +151,7 @@ __handle_subdirs_in_dir_flag()
__handle_flag()
{
__debug "${FUNCNAME}: c is $c words[c] is ${words[c]}"
__debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
# if a command required a flag, and we found it, unset must_have_one_flag()
local flagname=${words[c]}
@@ -156,15 +162,15 @@ __handle_flag()
flagname=${flagname%%=*} # strip everything after the =
flagname="${flagname}=" # but put the = back
fi
__debug "${FUNCNAME}: looking for ${flagname}"
__debug "${FUNCNAME[0]}: looking for ${flagname}"
if __contains_word "${flagname}" "${must_have_one_flag[@]}"; then
must_have_one_flag=()
fi
# keep flag value with flagname as flaghash
if [ ${flagvalue} ] ; then
if [ -n "${flagvalue}" ] ; then
flaghash[${flagname}]=${flagvalue}
elif [ ${words[ $((c+1)) ]} ] ; then
elif [ -n "${words[ $((c+1)) ]}" ] ; then
flaghash[${flagname}]=${words[ $((c+1)) ]}
else
flaghash[${flagname}]="true" # pad "true" for bool flag
@@ -185,11 +191,11 @@ __handle_flag()
__handle_noun()
{
__debug "${FUNCNAME}: c is $c words[c] is ${words[c]}"
__debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
if __contains_word "${words[c]}" "${must_have_one_noun[@]}"; then
must_have_one_noun=()
elif __contains_word "${words[c]%s}" "${must_have_one_noun[@]}"; then
elif __contains_word "${words[c]}" "${noun_aliases[@]}"; then
must_have_one_noun=()
fi
@@ -199,20 +205,20 @@ __handle_noun()
__handle_command()
{
__debug "${FUNCNAME}: c is $c words[c] is ${words[c]}"
__debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
local next_command
if [[ -n ${last_command} ]]; then
next_command="_${last_command}_${words[c]//:/__}"
else
if [[ $c -eq 0 ]]; then
next_command="_$(basename ${words[c]//:/__})"
next_command="_$(basename "${words[c]//:/__}")"
else
next_command="_${words[c]//:/__}"
fi
fi
c=$((c+1))
__debug "${FUNCNAME}: looking for ${next_command}"
__debug "${FUNCNAME[0]}: looking for ${next_command}"
declare -F $next_command >/dev/null && $next_command
}
@@ -222,12 +228,12 @@ __handle_word()
__handle_reply
return
fi
__debug "${FUNCNAME}: c is $c words[c] is ${words[c]}"
__debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
if [[ "${words[c]}" == -* ]]; then
__handle_flag
elif __contains_word "${words[c]}" "${commands[@]}"; then
__handle_command
elif [[ $c -eq 0 ]] && __contains_word "$(basename ${words[c]})" "${commands[@]}"; then
elif [[ $c -eq 0 ]] && __contains_word "$(basename "${words[c]}")" "${commands[@]}"; then
__handle_command
else
__handle_noun
@@ -460,7 +466,7 @@ func writeRequiredFlag(cmd *Command, w io.Writer) error {
return visitErr
}
func writeRequiredNoun(cmd *Command, w io.Writer) error {
func writeRequiredNouns(cmd *Command, w io.Writer) error {
if _, err := fmt.Fprintf(w, " must_have_one_noun=()\n"); err != nil {
return err
}
@@ -473,6 +479,19 @@ func writeRequiredNoun(cmd *Command, w io.Writer) error {
return nil
}
func writeArgAliases(cmd *Command, w io.Writer) error {
if _, err := fmt.Fprintf(w, " noun_aliases=()\n"); err != nil {
return err
}
sort.Sort(sort.StringSlice(cmd.ArgAliases))
for _, value := range cmd.ArgAliases {
if _, err := fmt.Fprintf(w, " noun_aliases+=(%q)\n", value); err != nil {
return err
}
}
return nil
}
func gen(cmd *Command, w io.Writer) error {
for _, c := range cmd.Commands() {
if !c.IsAvailableCommand() || c == cmd.helpCommand {
@@ -500,7 +519,10 @@ func gen(cmd *Command, w io.Writer) error {
if err := writeRequiredFlag(cmd, w); err != nil {
return err
}
if err := writeRequiredNoun(cmd, w); err != nil {
if err := writeRequiredNouns(cmd, w); err != nil {
return err
}
if err := writeArgAliases(cmd, w); err != nil {
return err
}
if _, err := fmt.Fprintf(w, "}\n\n"); err != nil {
+27 -2
View File
@@ -80,7 +80,7 @@ The `BashCompletionFunction` option is really only valid/useful on the root comm
In the above example "pod" was assumed to already be typed. But if you want `kubectl get [tab][tab]` to show a list of valid "nouns" you have to set them. Simplified code from `kubectl get` looks like:
```go
validArgs []string = { "pods", "nodes", "services", "replicationControllers" }
validArgs []string = { "pod", "node", "service", "replicationcontroller" }
cmd := &cobra.Command{
Use: "get [(-o|--output=)json|yaml|template|...] (RESOURCE [NAME] | RESOURCE/NAME ...)",
@@ -99,9 +99,34 @@ Notice we put the "ValidArgs" on the "get" subcommand. Doing so will give result
```bash
# kubectl get [tab][tab]
nodes pods replicationControllers services
node pod replicationcontroller service
```
## Plural form and shortcuts for nouns
If your nouns have a number of aliases, you can define them alongside `ValidArgs` using `ArgAliases`:
```go`
argAliases []string = { "pods", "nodes", "services", "svc", "replicationcontrollers", "rc" }
cmd := &cobra.Command{
...
ValidArgs: validArgs,
ArgAliases: argAliases
}
```
The aliases are not shown to the user on tab completion, but they are accepted as valid nouns by
the completion aglorithm if entered manually, e.g. in:
```bash
# kubectl get rc [tab][tab]
backend frontend database
```
Note that without declaring `rc` as an alias, the completion algorithm would show the list of nouns
in this example again instead of the replication controllers.
## Mark flags as required
Most of the time completions will only show subcommands. But if a flag is required to make a subcommand work, you probably want it to show up when the user types [tab][tab]. Marking a flag as 'Required' is incredibly easy.
+42 -4
View File
@@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"os"
"os/exec"
"strings"
"testing"
)
@@ -23,9 +24,29 @@ func check(t *testing.T, found, expected string) {
}
}
func runShellCheck(s string) error {
excluded := []string{
"SC2034", // PREFIX appears unused. Verify it or export it.
}
cmd := exec.Command("shellcheck", "-s", "bash", "-", "-e", strings.Join(excluded, ","))
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
stdin, err := cmd.StdinPipe()
if err != nil {
return err
}
go func() {
defer stdin.Close()
stdin.Write([]byte(s))
}()
return cmd.Run()
}
// World worst custom function, just keep telling you to enter hello!
const (
bash_completion_func = `__custom_func() {
bashCompletionFunc = `__custom_func() {
COMPREPLY=( "hello" )
}
`
@@ -37,15 +58,19 @@ func TestBashCompletions(t *testing.T) {
c.AddCommand(cmdEcho, cmdPrint, cmdDeprecated, cmdColon)
// custom completion function
c.BashCompletionFunction = bash_completion_func
c.BashCompletionFunction = bashCompletionFunc
// required flag
c.MarkFlagRequired("introot")
// valid nouns
validArgs := []string{"pods", "nodes", "services", "replicationControllers"}
validArgs := []string{"pod", "node", "service", "replicationcontroller"}
c.ValidArgs = validArgs
// noun aliases
argAliases := []string{"pods", "nodes", "services", "replicationcontrollers", "po", "no", "svc", "rc"}
c.ArgAliases = argAliases
// filename
var flagval string
c.Flags().StringVar(&flagval, "filename", "", "Enter a filename")
@@ -88,7 +113,11 @@ func TestBashCompletions(t *testing.T) {
// check for custom completion function
check(t, str, `COMPREPLY=( "hello" )`)
// check for required nouns
check(t, str, `must_have_one_noun+=("pods")`)
check(t, str, `must_have_one_noun+=("pod")`)
// check for noun aliases
check(t, str, `noun_aliases+=("pods")`)
check(t, str, `noun_aliases+=("rc")`)
checkOmit(t, str, `must_have_one_noun+=("pods")`)
// check for filename extension flags
check(t, str, `flags_completion+=("_filedir")`)
// check for filename extension flags
@@ -99,4 +128,13 @@ func TestBashCompletions(t *testing.T) {
check(t, str, `flags_completion+=("__handle_subdirs_in_dir_flag themes")`)
checkOmit(t, str, cmdDeprecated.Name())
// if available, run shellcheck against the script
if err := exec.Command("which", "shellcheck").Run(); err != nil {
return
}
err := runShellCheck(str)
if err != nil {
t.Fatalf("shellcheck failed: %v", err)
}
}
+2 -2
View File
@@ -26,7 +26,7 @@ import (
"unicode"
)
var templateFuncs template.FuncMap = template.FuncMap{
var templateFuncs = template.FuncMap{
"trim": strings.TrimSpace,
"trimRightSpace": trimRightSpace,
"appendIfNotPresent": appendIfNotPresent,
@@ -39,7 +39,7 @@ var initializers []func()
// automatic prefix matching can be a dangerous thing to automatically enable in CLI tools.
// Set this to true to enable it
var EnablePrefixMatching bool = false
var EnablePrefixMatching = false
//AddTemplateFunc adds a template function that's available to Usage and Help
//template generation.
+1 -1
View File
@@ -196,7 +196,7 @@ func isEmpty(path string) (bool, error) {
if err != nil {
return false, err
}
list, err := f.Readdir(-1)
list, _ := f.Readdir(-1)
// f.Close() - see bug fix above
return len(list) == 0, nil
}
+1 -1
View File
@@ -150,7 +150,7 @@ import (
{{if .viper}}
var cfgFile string
{{ end }}
// This represents the base command when called without any subcommands
// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "{{ .appName }}",
Short: "A brief description of your application",
+1 -1
View File
@@ -24,7 +24,7 @@ import (
var cfgFile string
var userLicense string
// This represents the base command when called without any subcommands
// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "cobra",
Short: "A generator for Cobra based Applications",
+5 -5
View File
@@ -454,10 +454,10 @@ func TestGrandChildSameName(t *testing.T) {
func TestUsage(t *testing.T) {
x := fullSetupTest("help")
checkResultContains(t, x, cmdRootWithRun.Use + " [flags]")
checkResultContains(t, x, cmdRootWithRun.Use+" [flags]")
x = fullSetupTest("help customflags")
checkResultContains(t, x, cmdCustomFlags.Use)
checkResultOmits(t, x, cmdCustomFlags.Use + " [flags]")
checkResultOmits(t, x, cmdCustomFlags.Use+" [flags]")
}
func TestFlagLong(t *testing.T) {
@@ -752,7 +752,7 @@ func TestVisitParents(t *testing.T) {
}
func TestRunnableRootCommandNilInput(t *testing.T) {
empty_arg := make([]string, 0)
var emptyArg []string
c := initializeWithRootCmd()
buf := new(bytes.Buffer)
@@ -760,7 +760,7 @@ func TestRunnableRootCommandNilInput(t *testing.T) {
c.SetOutput(buf)
cmdEcho.AddCommand(cmdTimes)
c.AddCommand(cmdPrint, cmdEcho)
c.SetArgs(empty_arg)
c.SetArgs(emptyArg)
err := c.Execute()
if err != nil {
@@ -863,7 +863,7 @@ func TestFlagAccess(t *testing.T) {
}
func TestNoNRunnableRootCommandNilInput(t *testing.T) {
args := make([]string, 0)
var args []string
c := initialize()
buf := new(bytes.Buffer)
+31 -35
View File
@@ -45,8 +45,11 @@ type Command struct {
Long string
// Examples of how to use the command
Example string
// List of all valid non-flag arguments, used for bash completions *TODO* actually validate these
// List of all valid non-flag arguments that are accepted in bash completions
ValidArgs []string
// List of aliases for ValidArgs. These are not suggested to the user in the bash
// completion, but accepted if entered manually.
ArgAliases []string
// Custom functions used by the bash autocompletion generator
BashCompletionFunction string
// Is this command deprecated and should print this string when used?
@@ -132,9 +135,8 @@ func (c *Command) getOut(def io.Writer) io.Writer {
if c.HasParent() {
return c.parent.Out()
} else {
return def
}
return def
}
func (c *Command) Out() io.Writer {
@@ -194,14 +196,13 @@ func (c *Command) UsageFunc() (f func(*Command) error) {
if c.HasParent() {
return c.parent.UsageFunc()
} else {
return func(c *Command) error {
err := tmpl(c.Out(), c.UsageTemplate(), c)
if err != nil {
fmt.Print(err)
}
return err
}
return func(c *Command) error {
err := tmpl(c.Out(), c.UsageTemplate(), c)
if err != nil {
fmt.Print(err)
}
return err
}
}
@@ -223,35 +224,32 @@ func (c *Command) HelpFunc() func(*Command, []string) {
}
}
var minUsagePadding int = 25
var minUsagePadding = 25
func (c *Command) UsagePadding() int {
if c.parent == nil || minUsagePadding > c.parent.commandsMaxUseLen {
return minUsagePadding
} else {
return c.parent.commandsMaxUseLen
}
return c.parent.commandsMaxUseLen
}
var minCommandPathPadding int = 11
var minCommandPathPadding = 11
//
func (c *Command) CommandPathPadding() int {
if c.parent == nil || minCommandPathPadding > c.parent.commandsMaxCommandPathLen {
return minCommandPathPadding
} else {
return c.parent.commandsMaxCommandPathLen
}
return c.parent.commandsMaxCommandPathLen
}
var minNamePadding int = 11
var minNamePadding = 11
func (c *Command) NamePadding() int {
if c.parent == nil || minNamePadding > c.parent.commandsMaxNameLen {
return minNamePadding
} else {
return c.parent.commandsMaxNameLen
}
return c.parent.commandsMaxNameLen
}
func (c *Command) UsageTemplate() string {
@@ -261,8 +259,8 @@ func (c *Command) UsageTemplate() string {
if c.HasParent() {
return c.parent.UsageTemplate()
} else {
return `Usage:{{if .Runnable}}
}
return `Usage:{{if .Runnable}}
{{if .HasFlags}}{{appendIfNotPresent .UseLine "[flags]"}}{{else}}{{.UseLine}}{{end}}{{end}}{{if .HasSubCommands}}
{{ .CommandPath}} [command]{{end}}{{if gt .Aliases 0}}
@@ -287,7 +285,6 @@ Additional help topics:{{range .Commands}}{{if .IsHelpCommand}}
Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}}
`
}
}
func (c *Command) HelpTemplate() string {
@@ -297,11 +294,10 @@ func (c *Command) HelpTemplate() string {
if c.HasParent() {
return c.parent.HelpTemplate()
} else {
return `{{with or .Long .Short }}{{. | trim}}
}
return `{{with or .Long .Short }}{{. | trim}}
{{end}}{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}`
}
}
// Really only used when casting a command to a commander
@@ -603,9 +599,8 @@ func (c *Command) errorMsgFromParse() string {
if len(x) > 0 {
return x[0]
} else {
return ""
}
return ""
}
// Call execute to use the args (os.Args[1:] by default)
@@ -786,18 +781,18 @@ main:
}
}
// Convenience method to Print to the defined output
// Print is a convenience method to Print to the defined output
func (c *Command) Print(i ...interface{}) {
fmt.Fprint(c.Out(), i...)
}
// Convenience method to Println to the defined output
// Println is a convenience method to Println to the defined output
func (c *Command) Println(i ...interface{}) {
str := fmt.Sprintln(i...)
c.Print(str)
}
// Convenience method to Printf to the defined output
// Printf is a convenience method to Printf to the defined output
func (c *Command) Printf(format string, i ...interface{}) {
str := fmt.Sprintf(format, i...)
c.Print(str)
@@ -908,7 +903,7 @@ func (c *Command) Name() string {
return name
}
// Determine if a given string is an alias of the command.
// HasAlias determines if a given string is an alias of the command.
func (c *Command) HasAlias(s string) bool {
for _, a := range c.Aliases {
if a == s {
@@ -926,12 +921,12 @@ func (c *Command) HasExample() bool {
return len(c.Example) > 0
}
// Determine if the command is itself runnable
// Runnable determines if the command is itself runnable
func (c *Command) Runnable() bool {
return c.Run != nil || c.RunE != nil
}
// Determine if the command has children commands
// HasSubCommands determines if the command has children commands
func (c *Command) HasSubCommands() bool {
return len(c.commands) > 0
}
@@ -1123,7 +1118,7 @@ func (c *Command) HasInheritedFlags() bool {
return c.InheritedFlags().HasFlags()
}
// Climbs up the command tree looking for matching flag
// Flag climbs up the command tree looking for matching flag
func (c *Command) Flag(name string) (flag *flag.Flag) {
flag = c.Flags().Lookup(name)
@@ -1146,13 +1141,14 @@ func (c *Command) persistentFlag(name string) (flag *flag.Flag) {
return
}
// Parses persistent flag tree & local flags
// ParseFlags parses persistent flag tree & local flags
func (c *Command) ParseFlags(args []string) (err error) {
c.mergePersistentFlags()
err = c.Flags().Parse(args)
return
}
// Parent returns a commands parent command
func (c *Command) Parent() *Command {
return c.parent
}
+1 -1
View File
@@ -2,4 +2,4 @@
package cobra
var preExecHookFn func(*Command) = nil
var preExecHookFn func(*Command)
+1 -2
View File
@@ -149,9 +149,8 @@ func AssertNextLineEquals(scanner *bufio.Scanner, expectedLine string) error {
line := scanner.Text()
if line == expectedLine {
return nil
} else {
return fmt.Errorf("AssertNextLineEquals: got %#v, not %#v", line, expectedLine)
}
return fmt.Errorf("AssertNextLineEquals: got %#v, not %#v", line, expectedLine)
}
if err := scanner.Err(); err != nil {
+2 -3
View File
@@ -179,9 +179,8 @@ const (
opAddrModeAbsolute
opAddrModeIndirect
opAddrModeScratch
// These are actually extensions, not addressing modes.
opAddrModePacketLen
opAddrModeIPv4HeaderLen
opAddrModePacketLen // actually an extension, not an addressing mode.
opAddrModeMemShift
)
const (
+11 -7
View File
@@ -65,8 +65,8 @@ func (ri RawInstruction) Disassemble() Instruction {
return ri
}
return LoadExtension{Num: ExtLen}
case opAddrModeIPv4HeaderLen:
return LoadIPv4HeaderLen{Off: ri.K}
case opAddrModeMemShift:
return LoadMemShift{Off: ri.K}
default:
return ri
}
@@ -209,15 +209,19 @@ func (a LoadIndirect) Assemble() (RawInstruction, error) {
return assembleLoad(RegA, a.Size, opAddrModeIndirect, a.Off)
}
// LoadIPv4HeaderLen loads into register X the length of the IPv4
// header whose first byte is packet[Off].
type LoadIPv4HeaderLen struct {
// LoadMemShift multiplies the first 4 bits of the byte at packet[Off]
// by 4 and stores the result in register X.
//
// This instruction is mainly useful to load into X the length of an
// IPv4 packet header in a single instruction, rather than have to do
// the arithmetic on the header's first byte by hand.
type LoadMemShift struct {
Off uint32
}
// Assemble implements the Instruction Assemble method.
func (a LoadIPv4HeaderLen) Assemble() (RawInstruction, error) {
return assembleLoad(RegX, 1, opAddrModeIPv4HeaderLen, a.Off)
func (a LoadMemShift) Assemble() (RawInstruction, error) {
return assembleLoad(RegX, 1, opAddrModeMemShift, a.Off)
}
// LoadExtension invokes a linux-specific extension and stores the
+1 -1
View File
@@ -29,7 +29,7 @@ var allInstructions = []Instruction{
LoadIndirect{Off: 42, Size: 2},
LoadIndirect{Off: 42, Size: 4},
LoadIPv4HeaderLen{Off: 42},
LoadMemShift{Off: 42},
LoadExtension{Num: ExtLen},
LoadExtension{Num: ExtProto},
+3 -6
View File
@@ -945,14 +945,11 @@ func (cc *ClientConn) encodeHeaders(req *http.Request, addGzipHeader bool, trail
// Host is :authority, already sent.
// Content-Length is automatic, set below.
continue
case "connection", "proxy-connection", "transfer-encoding", "upgrade":
case "connection", "proxy-connection", "transfer-encoding", "upgrade", "keep-alive":
// Per 8.1.2.2 Connection-Specific Header
// Fields, don't send connection-specific
// fields. We deal with these earlier in
// RoundTrip, deciding whether they're
// error-worthy, but we don't want to mutate
// the user's *Request so at this point, just
// skip over them at this point.
// fields. We have already checked if any
// are error-worthy so just ignore the rest.
continue
case "user-agent":
// Match Go's http1 behavior: at most one
+5
View File
@@ -1642,6 +1642,11 @@ func TestTransportRejectsConnHeaders(t *testing.T) {
value: []string{"123"},
want: "Accept-Encoding,User-Agent",
},
{
key: "Keep-Alive",
value: []string{"doop"},
want: "Accept-Encoding,User-Agent",
},
}
for _, tt := range tests {
+2 -2
View File
@@ -24,7 +24,7 @@ func setsockoptIPMreq(fd, name int, ifi *net.Interface, grp net.IP) error {
func getsockoptInterface(fd, name int) (*net.Interface, error) {
var b [4]byte
l := sysSockoptLen(4)
l := uint32(4)
if err := getsockopt(fd, iana.ProtocolIP, name, unsafe.Pointer(&b[0]), &l); err != nil {
return nil, os.NewSyscallError("getsockopt", err)
}
@@ -42,5 +42,5 @@ func setsockoptInterface(fd, name int, ifi *net.Interface) error {
}
var b [4]byte
copy(b[:], ip)
return os.NewSyscallError("setsockopt", setsockopt(fd, iana.ProtocolIP, name, unsafe.Pointer(&b[0]), sysSockoptLen(4)))
return os.NewSyscallError("setsockopt", setsockopt(fd, iana.ProtocolIP, name, unsafe.Pointer(&b[0]), uint32(4)))
}
+1 -1
View File
@@ -16,7 +16,7 @@ import (
func getsockoptIPMreqn(fd, name int) (*net.Interface, error) {
var mreqn sysIPMreqn
l := sysSockoptLen(sysSizeofIPMreqn)
l := uint32(sysSizeofIPMreqn)
if err := getsockopt(fd, iana.ProtocolIP, name, unsafe.Pointer(&mreqn), &l); err != nil {
return nil, os.NewSyscallError("getsockopt", err)
}
+2 -2
View File
@@ -23,7 +23,7 @@ func setsockoptGroupReq(fd, name int, ifi *net.Interface, grp net.IP) error {
}
gr.setGroup(grp)
var p unsafe.Pointer
var l sysSockoptLen
var l uint32
if freebsd32o64 {
var d [sysSizeofGroupReq + 4]byte
s := (*[sysSizeofGroupReq]byte)(unsafe.Pointer(&gr))
@@ -45,7 +45,7 @@ func setsockoptGroupSourceReq(fd, name int, ifi *net.Interface, grp, src net.IP)
}
gsr.setSourceGroup(grp, src)
var p unsafe.Pointer
var l sysSockoptLen
var l uint32
if freebsd32o64 {
var d [sysSizeofGroupSourceReq + 4]byte
s := (*[sysSizeofGroupSourceReq]byte)(unsafe.Pointer(&gsr))
+5 -5
View File
@@ -21,10 +21,10 @@ func getInt(fd int, opt *sockOpt) (int, error) {
var i int32
var b byte
p := unsafe.Pointer(&i)
l := sysSockoptLen(4)
l := uint32(4)
if opt.typ == ssoTypeByte {
p = unsafe.Pointer(&b)
l = sysSockoptLen(1)
l = 1
}
if err := getsockopt(fd, iana.ProtocolIP, opt.name, p, &l); err != nil {
return 0, os.NewSyscallError("getsockopt", err)
@@ -42,11 +42,11 @@ func setInt(fd int, opt *sockOpt, v int) error {
i := int32(v)
var b byte
p := unsafe.Pointer(&i)
l := sysSockoptLen(4)
l := uint32(4)
if opt.typ == ssoTypeByte {
b = byte(v)
p = unsafe.Pointer(&b)
l = sysSockoptLen(1)
l = 1
}
return os.NewSyscallError("setsockopt", setsockopt(fd, iana.ProtocolIP, opt.name, p, l))
}
@@ -84,7 +84,7 @@ func getICMPFilter(fd int, opt *sockOpt) (*ICMPFilter, error) {
return nil, errOpNoSupport
}
var f ICMPFilter
l := sysSockoptLen(sysSizeofICMPFilter)
l := uint32(sysSizeofICMPFilter)
if err := getsockopt(fd, iana.ProtocolReserved, opt.name, unsafe.Pointer(&f.sysICMPFilter), &l); err != nil {
return nil, os.NewSyscallError("getsockopt", err)
}
-2
View File
@@ -11,8 +11,6 @@ import (
"syscall"
)
type sysSockoptLen int32
var (
ctlOpts = [ctlMax]ctlOpt{
ctlTTL: {sysIP_RECVTTL, 1, marshalTTL, parseTTL},
-2
View File
@@ -10,8 +10,6 @@ import (
"unsafe"
)
type sysSockoptLen int32
var (
ctlOpts = [ctlMax]ctlOpt{
ctlTTL: {sysIP_RECVTTL, 1, marshalTTL, parseTTL},
-2
View File
@@ -12,8 +12,6 @@ import (
"unsafe"
)
type sysSockoptLen int32
var (
ctlOpts = [ctlMax]ctlOpt{
ctlTTL: {sysIP_RECVTTL, 1, marshalTTL, parseTTL},
-2
View File
@@ -10,8 +10,6 @@ import (
"unsafe"
)
type sysSockoptLen int32
var (
ctlOpts = [ctlMax]ctlOpt{
ctlTTL: {sysIP_TTL, 1, marshalTTL, parseTTL},
-2
View File
@@ -9,8 +9,6 @@ import (
"syscall"
)
type sysSockoptLen int32
var (
ctlOpts = [ctlMax]ctlOpt{
ctlTTL: {sysIP_RECVTTL, 1, marshalTTL, parseTTL},
-2
View File
@@ -6,8 +6,6 @@
package ipv4
type sysSockoptLen int32
var (
ctlOpts = [ctlMax]ctlOpt{}
+2 -2
View File
@@ -16,14 +16,14 @@ const (
func socketcall(call int, a0, a1, a2, a3, a4, a5 uintptr) (int, syscall.Errno)
func getsockopt(fd, level, name int, v unsafe.Pointer, l *sysSockoptLen) error {
func getsockopt(fd, level, name int, v unsafe.Pointer, l *uint32) error {
if _, errno := socketcall(sysGETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 {
return error(errno)
}
return nil
}
func setsockopt(fd, level, name int, v unsafe.Pointer, l sysSockoptLen) error {
func setsockopt(fd, level, name int, v unsafe.Pointer, l uint32) error {
if _, errno := socketcall(sysSETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 {
return error(errno)
}
+2 -2
View File
@@ -11,14 +11,14 @@ import (
"unsafe"
)
func getsockopt(fd, level, name int, v unsafe.Pointer, l *sysSockoptLen) error {
func getsockopt(fd, level, name int, v unsafe.Pointer, l *uint32) error {
if _, _, errno := syscall.Syscall6(syscall.SYS_GETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 {
return error(errno)
}
return nil
}
func setsockopt(fd, level, name int, v unsafe.Pointer, l sysSockoptLen) error {
func setsockopt(fd, level, name int, v unsafe.Pointer, l uint32) error {
if _, _, errno := syscall.Syscall6(syscall.SYS_SETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 {
return error(errno)
}
+2 -2
View File
@@ -21,7 +21,7 @@ func setsockoptGroupReq(fd int, opt *sockOpt, ifi *net.Interface, grp net.IP) er
}
gr.setGroup(grp)
var p unsafe.Pointer
var l sysSockoptLen
var l uint32
if freebsd32o64 {
var d [sysSizeofGroupReq + 4]byte
s := (*[sysSizeofGroupReq]byte)(unsafe.Pointer(&gr))
@@ -43,7 +43,7 @@ func setsockoptGroupSourceReq(fd int, opt *sockOpt, ifi *net.Interface, grp, src
}
gsr.setSourceGroup(grp, src)
var p unsafe.Pointer
var l sysSockoptLen
var l uint32
if freebsd32o64 {
var d [sysSizeofGroupSourceReq + 4]byte
s := (*[sysSizeofGroupSourceReq]byte)(unsafe.Pointer(&gsr))
+6 -6
View File
@@ -17,7 +17,7 @@ func getInt(fd int, opt *sockOpt) (int, error) {
return 0, errOpNoSupport
}
var i int32
l := sysSockoptLen(4)
l := uint32(4)
if err := getsockopt(fd, opt.level, opt.name, unsafe.Pointer(&i), &l); err != nil {
return 0, os.NewSyscallError("getsockopt", err)
}
@@ -29,7 +29,7 @@ func setInt(fd int, opt *sockOpt, v int) error {
return errOpNoSupport
}
i := int32(v)
return os.NewSyscallError("setsockopt", setsockopt(fd, opt.level, opt.name, unsafe.Pointer(&i), sysSockoptLen(4)))
return os.NewSyscallError("setsockopt", setsockopt(fd, opt.level, opt.name, unsafe.Pointer(&i), 4))
}
func getInterface(fd int, opt *sockOpt) (*net.Interface, error) {
@@ -37,7 +37,7 @@ func getInterface(fd int, opt *sockOpt) (*net.Interface, error) {
return nil, errOpNoSupport
}
var i int32
l := sysSockoptLen(4)
l := uint32(4)
if err := getsockopt(fd, opt.level, opt.name, unsafe.Pointer(&i), &l); err != nil {
return nil, os.NewSyscallError("getsockopt", err)
}
@@ -59,7 +59,7 @@ func setInterface(fd int, opt *sockOpt, ifi *net.Interface) error {
if ifi != nil {
i = int32(ifi.Index)
}
return os.NewSyscallError("setsockopt", setsockopt(fd, opt.level, opt.name, unsafe.Pointer(&i), sysSockoptLen(4)))
return os.NewSyscallError("setsockopt", setsockopt(fd, opt.level, opt.name, unsafe.Pointer(&i), 4))
}
func getICMPFilter(fd int, opt *sockOpt) (*ICMPFilter, error) {
@@ -67,7 +67,7 @@ func getICMPFilter(fd int, opt *sockOpt) (*ICMPFilter, error) {
return nil, errOpNoSupport
}
var f ICMPFilter
l := sysSockoptLen(sysSizeofICMPv6Filter)
l := uint32(sysSizeofICMPv6Filter)
if err := getsockopt(fd, opt.level, opt.name, unsafe.Pointer(&f.sysICMPv6Filter), &l); err != nil {
return nil, os.NewSyscallError("getsockopt", err)
}
@@ -86,7 +86,7 @@ func getMTUInfo(fd int, opt *sockOpt) (*net.Interface, int, error) {
return nil, 0, errOpNoSupport
}
var mi sysIPv6Mtuinfo
l := sysSockoptLen(sysSizeofIPv6Mtuinfo)
l := uint32(sysSizeofIPv6Mtuinfo)
if err := getsockopt(fd, opt.level, opt.name, unsafe.Pointer(&mi), &l); err != nil {
return nil, 0, os.NewSyscallError("getsockopt", err)
}
-2
View File
@@ -13,8 +13,6 @@ import (
"golang.org/x/net/internal/iana"
)
type sysSockoptLen int32
var (
ctlOpts = [ctlMax]ctlOpt{
ctlTrafficClass: {sysIPV6_TCLASS, 4, marshalTrafficClass, parseTrafficClass},
-2
View File
@@ -12,8 +12,6 @@ import (
"golang.org/x/net/internal/iana"
)
type sysSockoptLen int32
var (
ctlOpts = [ctlMax]ctlOpt{
ctlHopLimit: {sysIPV6_2292HOPLIMIT, 4, marshal2292HopLimit, parseHopLimit},
-2
View File
@@ -14,8 +14,6 @@ import (
"golang.org/x/net/internal/iana"
)
type sysSockoptLen int32
var (
ctlOpts = [ctlMax]ctlOpt{
ctlTrafficClass: {sysIPV6_TCLASS, 4, marshalTrafficClass, parseTrafficClass},
-2
View File
@@ -12,8 +12,6 @@ import (
"golang.org/x/net/internal/iana"
)
type sysSockoptLen int32
var (
ctlOpts = [ctlMax]ctlOpt{
ctlTrafficClass: {sysIPV6_TCLASS, 4, marshalTrafficClass, parseTrafficClass},
-2
View File
@@ -6,8 +6,6 @@
package ipv6
type sysSockoptLen int32
var (
ctlOpts = [ctlMax]ctlOpt{}
+2 -2
View File
@@ -16,14 +16,14 @@ const (
func socketcall(call int, a0, a1, a2, a3, a4, a5 uintptr) (int, syscall.Errno)
func getsockopt(fd, level, name int, v unsafe.Pointer, l *sysSockoptLen) error {
func getsockopt(fd, level, name int, v unsafe.Pointer, l *uint32) error {
if _, errno := socketcall(sysGETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 {
return error(errno)
}
return nil
}
func setsockopt(fd, level, name int, v unsafe.Pointer, l sysSockoptLen) error {
func setsockopt(fd, level, name int, v unsafe.Pointer, l uint32) error {
if _, errno := socketcall(sysSETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 {
return error(errno)
}
+2 -2
View File
@@ -11,14 +11,14 @@ import (
"unsafe"
)
func getsockopt(fd, level, name int, v unsafe.Pointer, l *sysSockoptLen) error {
func getsockopt(fd, level, name int, v unsafe.Pointer, l *uint32) error {
if _, _, errno := syscall.Syscall6(syscall.SYS_GETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 {
return error(errno)
}
return nil
}
func setsockopt(fd, level, name int, v unsafe.Pointer, l sysSockoptLen) error {
func setsockopt(fd, level, name int, v unsafe.Pointer, l uint32) error {
if _, _, errno := syscall.Syscall6(syscall.SYS_SETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 {
return error(errno)
}
-3
View File
@@ -468,9 +468,6 @@ function addGeneralStyle() {
document.querySelector('head').appendChild(el);
};
function showHelpText() {
};
function handleDomLoaded() {
slideEls = document.querySelectorAll('section.slides > article');
+3 -1
View File
@@ -1289,7 +1289,9 @@ func (a *analysis) generate() {
a.genMethodsOf(T)
}
// Generate constraints for entire program.
// Generate constraints for functions as they become reachable
// from the roots. (No constraints are generated for functions
// that are dead in this analysis scope.)
for len(a.genq) > 0 {
cgn := a.genq[0]
a.genq = a.genq[1:]