repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
alecthomas/kingpin
values_generated.go
BoolList
func (p *parserMixin) BoolList() (target *[]bool) { target = new([]bool) p.BoolListVar(target) return }
go
func (p *parserMixin) BoolList() (target *[]bool) { target = new([]bool) p.BoolListVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "BoolList", "(", ")", "(", "target", "*", "[", "]", "bool", ")", "{", "target", "=", "new", "(", "[", "]", "bool", ")", "\n", "p", ".", "BoolListVar", "(", "target", ")", "\n", "return", "\n", "}" ]
// BoolList accumulates bool values into a slice.
[ "BoolList", "accumulates", "bool", "values", "into", "a", "slice", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L45-L49
train
alecthomas/kingpin
values_generated.go
String
func (p *parserMixin) String() (target *string) { target = new(string) p.StringVar(target) return }
go
func (p *parserMixin) String() (target *string) { target = new(string) p.StringVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "String", "(", ")", "(", "target", "*", "string", ")", "{", "target", "=", "new", "(", "string", ")", "\n", "p", ".", "StringVar", "(", "target", ")", "\n", "return", "\n", "}" ]
// String parses the next command-line value as string.
[ "String", "parses", "the", "next", "command", "-", "line", "value", "as", "string", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L77-L81
train
alecthomas/kingpin
values_generated.go
Strings
func (p *parserMixin) Strings() (target *[]string) { target = new([]string) p.StringsVar(target) return }
go
func (p *parserMixin) Strings() (target *[]string) { target = new([]string) p.StringsVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Strings", "(", ")", "(", "target", "*", "[", "]", "string", ")", "{", "target", "=", "new", "(", "[", "]", "string", ")", "\n", "p", ".", "StringsVar", "(", "target", ")", "\n", "return", "\n", "}" ]
// Strings accumulates string values into a slice.
[ "Strings", "accumulates", "string", "values", "into", "a", "slice", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L88-L92
train
alecthomas/kingpin
values_generated.go
Uint
func (p *parserMixin) Uint() (target *uint) { target = new(uint) p.UintVar(target) return }
go
func (p *parserMixin) Uint() (target *uint) { target = new(uint) p.UintVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Uint", "(", ")", "(", "target", "*", "uint", ")", "{", "target", "=", "new", "(", "uint", ")", "\n", "p", ".", "UintVar", "(", "target", ")", "\n", "return", "\n", "}" ]
// Uint parses the next command-line value as uint.
[ "Uint", "parses", "the", "next", "command", "-", "line", "value", "as", "uint", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L120-L124
train
alecthomas/kingpin
values_generated.go
Uints
func (p *parserMixin) Uints() (target *[]uint) { target = new([]uint) p.UintsVar(target) return }
go
func (p *parserMixin) Uints() (target *[]uint) { target = new([]uint) p.UintsVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Uints", "(", ")", "(", "target", "*", "[", "]", "uint", ")", "{", "target", "=", "new", "(", "[", "]", "uint", ")", "\n", "p", ".", "UintsVar", "(", "target", ")", "\n", "return", "\n", "}" ]
// Uints accumulates uint values into a slice.
[ "Uints", "accumulates", "uint", "values", "into", "a", "slice", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L131-L135
train
alecthomas/kingpin
values_generated.go
Uint8
func (p *parserMixin) Uint8() (target *uint8) { target = new(uint8) p.Uint8Var(target) return }
go
func (p *parserMixin) Uint8() (target *uint8) { target = new(uint8) p.Uint8Var(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Uint8", "(", ")", "(", "target", "*", "uint8", ")", "{", "target", "=", "new", "(", "uint8", ")", "\n", "p", ".", "Uint8Var", "(", "target", ")", "\n", "return", "\n", "}" ]
// Uint8 parses the next command-line value as uint8.
[ "Uint8", "parses", "the", "next", "command", "-", "line", "value", "as", "uint8", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L163-L167
train
alecthomas/kingpin
values_generated.go
Uint8List
func (p *parserMixin) Uint8List() (target *[]uint8) { target = new([]uint8) p.Uint8ListVar(target) return }
go
func (p *parserMixin) Uint8List() (target *[]uint8) { target = new([]uint8) p.Uint8ListVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Uint8List", "(", ")", "(", "target", "*", "[", "]", "uint8", ")", "{", "target", "=", "new", "(", "[", "]", "uint8", ")", "\n", "p", ".", "Uint8ListVar", "(", "target", ")", "\n", "return", "\n", "}" ]
// Uint8List accumulates uint8 values into a slice.
[ "Uint8List", "accumulates", "uint8", "values", "into", "a", "slice", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L174-L178
train
alecthomas/kingpin
values_generated.go
Uint16
func (p *parserMixin) Uint16() (target *uint16) { target = new(uint16) p.Uint16Var(target) return }
go
func (p *parserMixin) Uint16() (target *uint16) { target = new(uint16) p.Uint16Var(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Uint16", "(", ")", "(", "target", "*", "uint16", ")", "{", "target", "=", "new", "(", "uint16", ")", "\n", "p", ".", "Uint16Var", "(", "target", ")", "\n", "return", "\n", "}" ]
// Uint16 parses the next command-line value as uint16.
[ "Uint16", "parses", "the", "next", "command", "-", "line", "value", "as", "uint16", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L206-L210
train
alecthomas/kingpin
values_generated.go
Uint16List
func (p *parserMixin) Uint16List() (target *[]uint16) { target = new([]uint16) p.Uint16ListVar(target) return }
go
func (p *parserMixin) Uint16List() (target *[]uint16) { target = new([]uint16) p.Uint16ListVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Uint16List", "(", ")", "(", "target", "*", "[", "]", "uint16", ")", "{", "target", "=", "new", "(", "[", "]", "uint16", ")", "\n", "p", ".", "Uint16ListVar", "(", "target", ")", "\n", "return", "\n", "}...
// Uint16List accumulates uint16 values into a slice.
[ "Uint16List", "accumulates", "uint16", "values", "into", "a", "slice", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L217-L221
train
alecthomas/kingpin
values_generated.go
Uint32
func (p *parserMixin) Uint32() (target *uint32) { target = new(uint32) p.Uint32Var(target) return }
go
func (p *parserMixin) Uint32() (target *uint32) { target = new(uint32) p.Uint32Var(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Uint32", "(", ")", "(", "target", "*", "uint32", ")", "{", "target", "=", "new", "(", "uint32", ")", "\n", "p", ".", "Uint32Var", "(", "target", ")", "\n", "return", "\n", "}" ]
// Uint32 parses the next command-line value as uint32.
[ "Uint32", "parses", "the", "next", "command", "-", "line", "value", "as", "uint32", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L249-L253
train
alecthomas/kingpin
values_generated.go
Uint32List
func (p *parserMixin) Uint32List() (target *[]uint32) { target = new([]uint32) p.Uint32ListVar(target) return }
go
func (p *parserMixin) Uint32List() (target *[]uint32) { target = new([]uint32) p.Uint32ListVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Uint32List", "(", ")", "(", "target", "*", "[", "]", "uint32", ")", "{", "target", "=", "new", "(", "[", "]", "uint32", ")", "\n", "p", ".", "Uint32ListVar", "(", "target", ")", "\n", "return", "\n", "}...
// Uint32List accumulates uint32 values into a slice.
[ "Uint32List", "accumulates", "uint32", "values", "into", "a", "slice", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L260-L264
train
alecthomas/kingpin
values_generated.go
Uint64
func (p *parserMixin) Uint64() (target *uint64) { target = new(uint64) p.Uint64Var(target) return }
go
func (p *parserMixin) Uint64() (target *uint64) { target = new(uint64) p.Uint64Var(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Uint64", "(", ")", "(", "target", "*", "uint64", ")", "{", "target", "=", "new", "(", "uint64", ")", "\n", "p", ".", "Uint64Var", "(", "target", ")", "\n", "return", "\n", "}" ]
// Uint64 parses the next command-line value as uint64.
[ "Uint64", "parses", "the", "next", "command", "-", "line", "value", "as", "uint64", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L292-L296
train
alecthomas/kingpin
values_generated.go
Uint64List
func (p *parserMixin) Uint64List() (target *[]uint64) { target = new([]uint64) p.Uint64ListVar(target) return }
go
func (p *parserMixin) Uint64List() (target *[]uint64) { target = new([]uint64) p.Uint64ListVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Uint64List", "(", ")", "(", "target", "*", "[", "]", "uint64", ")", "{", "target", "=", "new", "(", "[", "]", "uint64", ")", "\n", "p", ".", "Uint64ListVar", "(", "target", ")", "\n", "return", "\n", "}...
// Uint64List accumulates uint64 values into a slice.
[ "Uint64List", "accumulates", "uint64", "values", "into", "a", "slice", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L303-L307
train
alecthomas/kingpin
values_generated.go
Int
func (p *parserMixin) Int() (target *int) { target = new(int) p.IntVar(target) return }
go
func (p *parserMixin) Int() (target *int) { target = new(int) p.IntVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Int", "(", ")", "(", "target", "*", "int", ")", "{", "target", "=", "new", "(", "int", ")", "\n", "p", ".", "IntVar", "(", "target", ")", "\n", "return", "\n", "}" ]
// Int parses the next command-line value as int.
[ "Int", "parses", "the", "next", "command", "-", "line", "value", "as", "int", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L335-L339
train
alecthomas/kingpin
values_generated.go
Ints
func (p *parserMixin) Ints() (target *[]int) { target = new([]int) p.IntsVar(target) return }
go
func (p *parserMixin) Ints() (target *[]int) { target = new([]int) p.IntsVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Ints", "(", ")", "(", "target", "*", "[", "]", "int", ")", "{", "target", "=", "new", "(", "[", "]", "int", ")", "\n", "p", ".", "IntsVar", "(", "target", ")", "\n", "return", "\n", "}" ]
// Ints accumulates int values into a slice.
[ "Ints", "accumulates", "int", "values", "into", "a", "slice", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L346-L350
train
alecthomas/kingpin
values_generated.go
Int8
func (p *parserMixin) Int8() (target *int8) { target = new(int8) p.Int8Var(target) return }
go
func (p *parserMixin) Int8() (target *int8) { target = new(int8) p.Int8Var(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Int8", "(", ")", "(", "target", "*", "int8", ")", "{", "target", "=", "new", "(", "int8", ")", "\n", "p", ".", "Int8Var", "(", "target", ")", "\n", "return", "\n", "}" ]
// Int8 parses the next command-line value as int8.
[ "Int8", "parses", "the", "next", "command", "-", "line", "value", "as", "int8", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L378-L382
train
alecthomas/kingpin
values_generated.go
Int8List
func (p *parserMixin) Int8List() (target *[]int8) { target = new([]int8) p.Int8ListVar(target) return }
go
func (p *parserMixin) Int8List() (target *[]int8) { target = new([]int8) p.Int8ListVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Int8List", "(", ")", "(", "target", "*", "[", "]", "int8", ")", "{", "target", "=", "new", "(", "[", "]", "int8", ")", "\n", "p", ".", "Int8ListVar", "(", "target", ")", "\n", "return", "\n", "}" ]
// Int8List accumulates int8 values into a slice.
[ "Int8List", "accumulates", "int8", "values", "into", "a", "slice", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L389-L393
train
alecthomas/kingpin
values_generated.go
Int16
func (p *parserMixin) Int16() (target *int16) { target = new(int16) p.Int16Var(target) return }
go
func (p *parserMixin) Int16() (target *int16) { target = new(int16) p.Int16Var(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Int16", "(", ")", "(", "target", "*", "int16", ")", "{", "target", "=", "new", "(", "int16", ")", "\n", "p", ".", "Int16Var", "(", "target", ")", "\n", "return", "\n", "}" ]
// Int16 parses the next command-line value as int16.
[ "Int16", "parses", "the", "next", "command", "-", "line", "value", "as", "int16", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L421-L425
train
alecthomas/kingpin
values_generated.go
Int16List
func (p *parserMixin) Int16List() (target *[]int16) { target = new([]int16) p.Int16ListVar(target) return }
go
func (p *parserMixin) Int16List() (target *[]int16) { target = new([]int16) p.Int16ListVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Int16List", "(", ")", "(", "target", "*", "[", "]", "int16", ")", "{", "target", "=", "new", "(", "[", "]", "int16", ")", "\n", "p", ".", "Int16ListVar", "(", "target", ")", "\n", "return", "\n", "}" ]
// Int16List accumulates int16 values into a slice.
[ "Int16List", "accumulates", "int16", "values", "into", "a", "slice", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L432-L436
train
alecthomas/kingpin
values_generated.go
Int32
func (p *parserMixin) Int32() (target *int32) { target = new(int32) p.Int32Var(target) return }
go
func (p *parserMixin) Int32() (target *int32) { target = new(int32) p.Int32Var(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Int32", "(", ")", "(", "target", "*", "int32", ")", "{", "target", "=", "new", "(", "int32", ")", "\n", "p", ".", "Int32Var", "(", "target", ")", "\n", "return", "\n", "}" ]
// Int32 parses the next command-line value as int32.
[ "Int32", "parses", "the", "next", "command", "-", "line", "value", "as", "int32", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L464-L468
train
alecthomas/kingpin
values_generated.go
Int32List
func (p *parserMixin) Int32List() (target *[]int32) { target = new([]int32) p.Int32ListVar(target) return }
go
func (p *parserMixin) Int32List() (target *[]int32) { target = new([]int32) p.Int32ListVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Int32List", "(", ")", "(", "target", "*", "[", "]", "int32", ")", "{", "target", "=", "new", "(", "[", "]", "int32", ")", "\n", "p", ".", "Int32ListVar", "(", "target", ")", "\n", "return", "\n", "}" ]
// Int32List accumulates int32 values into a slice.
[ "Int32List", "accumulates", "int32", "values", "into", "a", "slice", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L475-L479
train
alecthomas/kingpin
values_generated.go
Int64
func (p *parserMixin) Int64() (target *int64) { target = new(int64) p.Int64Var(target) return }
go
func (p *parserMixin) Int64() (target *int64) { target = new(int64) p.Int64Var(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Int64", "(", ")", "(", "target", "*", "int64", ")", "{", "target", "=", "new", "(", "int64", ")", "\n", "p", ".", "Int64Var", "(", "target", ")", "\n", "return", "\n", "}" ]
// Int64 parses the next command-line value as int64.
[ "Int64", "parses", "the", "next", "command", "-", "line", "value", "as", "int64", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L507-L511
train
alecthomas/kingpin
values_generated.go
Int64List
func (p *parserMixin) Int64List() (target *[]int64) { target = new([]int64) p.Int64ListVar(target) return }
go
func (p *parserMixin) Int64List() (target *[]int64) { target = new([]int64) p.Int64ListVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Int64List", "(", ")", "(", "target", "*", "[", "]", "int64", ")", "{", "target", "=", "new", "(", "[", "]", "int64", ")", "\n", "p", ".", "Int64ListVar", "(", "target", ")", "\n", "return", "\n", "}" ]
// Int64List accumulates int64 values into a slice.
[ "Int64List", "accumulates", "int64", "values", "into", "a", "slice", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L518-L522
train
alecthomas/kingpin
values_generated.go
Float64
func (p *parserMixin) Float64() (target *float64) { target = new(float64) p.Float64Var(target) return }
go
func (p *parserMixin) Float64() (target *float64) { target = new(float64) p.Float64Var(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Float64", "(", ")", "(", "target", "*", "float64", ")", "{", "target", "=", "new", "(", "float64", ")", "\n", "p", ".", "Float64Var", "(", "target", ")", "\n", "return", "\n", "}" ]
// Float64 parses the next command-line value as float64.
[ "Float64", "parses", "the", "next", "command", "-", "line", "value", "as", "float64", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L550-L554
train
alecthomas/kingpin
values_generated.go
Float64List
func (p *parserMixin) Float64List() (target *[]float64) { target = new([]float64) p.Float64ListVar(target) return }
go
func (p *parserMixin) Float64List() (target *[]float64) { target = new([]float64) p.Float64ListVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Float64List", "(", ")", "(", "target", "*", "[", "]", "float64", ")", "{", "target", "=", "new", "(", "[", "]", "float64", ")", "\n", "p", ".", "Float64ListVar", "(", "target", ")", "\n", "return", "\n", ...
// Float64List accumulates float64 values into a slice.
[ "Float64List", "accumulates", "float64", "values", "into", "a", "slice", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L561-L565
train
alecthomas/kingpin
values_generated.go
Float32
func (p *parserMixin) Float32() (target *float32) { target = new(float32) p.Float32Var(target) return }
go
func (p *parserMixin) Float32() (target *float32) { target = new(float32) p.Float32Var(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Float32", "(", ")", "(", "target", "*", "float32", ")", "{", "target", "=", "new", "(", "float32", ")", "\n", "p", ".", "Float32Var", "(", "target", ")", "\n", "return", "\n", "}" ]
// Float32 parses the next command-line value as float32.
[ "Float32", "parses", "the", "next", "command", "-", "line", "value", "as", "float32", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L593-L597
train
alecthomas/kingpin
values_generated.go
Float32List
func (p *parserMixin) Float32List() (target *[]float32) { target = new([]float32) p.Float32ListVar(target) return }
go
func (p *parserMixin) Float32List() (target *[]float32) { target = new([]float32) p.Float32ListVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "Float32List", "(", ")", "(", "target", "*", "[", "]", "float32", ")", "{", "target", "=", "new", "(", "[", "]", "float32", ")", "\n", "p", ".", "Float32ListVar", "(", "target", ")", "\n", "return", "\n", ...
// Float32List accumulates float32 values into a slice.
[ "Float32List", "accumulates", "float32", "values", "into", "a", "slice", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L604-L608
train
alecthomas/kingpin
values_generated.go
DurationList
func (p *parserMixin) DurationList() (target *[]time.Duration) { target = new([]time.Duration) p.DurationListVar(target) return }
go
func (p *parserMixin) DurationList() (target *[]time.Duration) { target = new([]time.Duration) p.DurationListVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "DurationList", "(", ")", "(", "target", "*", "[", "]", "time", ".", "Duration", ")", "{", "target", "=", "new", "(", "[", "]", "time", ".", "Duration", ")", "\n", "p", ".", "DurationListVar", "(", "target...
// DurationList accumulates time.Duration values into a slice.
[ "DurationList", "accumulates", "time", ".", "Duration", "values", "into", "a", "slice", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L617-L621
train
alecthomas/kingpin
values_generated.go
IPList
func (p *parserMixin) IPList() (target *[]net.IP) { target = new([]net.IP) p.IPListVar(target) return }
go
func (p *parserMixin) IPList() (target *[]net.IP) { target = new([]net.IP) p.IPListVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "IPList", "(", ")", "(", "target", "*", "[", "]", "net", ".", "IP", ")", "{", "target", "=", "new", "(", "[", "]", "net", ".", "IP", ")", "\n", "p", ".", "IPListVar", "(", "target", ")", "\n", "retur...
// IPList accumulates net.IP values into a slice.
[ "IPList", "accumulates", "net", ".", "IP", "values", "into", "a", "slice", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L630-L634
train
alecthomas/kingpin
values_generated.go
ExistingFiles
func (p *parserMixin) ExistingFiles() (target *[]string) { target = new([]string) p.ExistingFilesVar(target) return }
go
func (p *parserMixin) ExistingFiles() (target *[]string) { target = new([]string) p.ExistingFilesVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "ExistingFiles", "(", ")", "(", "target", "*", "[", "]", "string", ")", "{", "target", "=", "new", "(", "[", "]", "string", ")", "\n", "p", ".", "ExistingFilesVar", "(", "target", ")", "\n", "return", "\n"...
// ExistingFiles accumulates string values into a slice.
[ "ExistingFiles", "accumulates", "string", "values", "into", "a", "slice", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L656-L660
train
alecthomas/kingpin
values_generated.go
ExistingDirs
func (p *parserMixin) ExistingDirs() (target *[]string) { target = new([]string) p.ExistingDirsVar(target) return }
go
func (p *parserMixin) ExistingDirs() (target *[]string) { target = new([]string) p.ExistingDirsVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "ExistingDirs", "(", ")", "(", "target", "*", "[", "]", "string", ")", "{", "target", "=", "new", "(", "[", "]", "string", ")", "\n", "p", ".", "ExistingDirsVar", "(", "target", ")", "\n", "return", "\n", ...
// ExistingDirs accumulates string values into a slice.
[ "ExistingDirs", "accumulates", "string", "values", "into", "a", "slice", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L669-L673
train
alecthomas/kingpin
values_generated.go
ExistingFilesOrDirs
func (p *parserMixin) ExistingFilesOrDirs() (target *[]string) { target = new([]string) p.ExistingFilesOrDirsVar(target) return }
go
func (p *parserMixin) ExistingFilesOrDirs() (target *[]string) { target = new([]string) p.ExistingFilesOrDirsVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "ExistingFilesOrDirs", "(", ")", "(", "target", "*", "[", "]", "string", ")", "{", "target", "=", "new", "(", "[", "]", "string", ")", "\n", "p", ".", "ExistingFilesOrDirsVar", "(", "target", ")", "\n", "ret...
// ExistingFilesOrDirs accumulates string values into a slice.
[ "ExistingFilesOrDirs", "accumulates", "string", "values", "into", "a", "slice", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L682-L686
train
alecthomas/kingpin
values_generated.go
ResolvedIP
func (p *parserMixin) ResolvedIP() (target *net.IP) { target = new(net.IP) p.ResolvedIPVar(target) return }
go
func (p *parserMixin) ResolvedIP() (target *net.IP) { target = new(net.IP) p.ResolvedIPVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "ResolvedIP", "(", ")", "(", "target", "*", "net", ".", "IP", ")", "{", "target", "=", "new", "(", "net", ".", "IP", ")", "\n", "p", ".", "ResolvedIPVar", "(", "target", ")", "\n", "return", "\n", "}" ]
// Resolve a hostname or IP to an IP.
[ "Resolve", "a", "hostname", "or", "IP", "to", "an", "IP", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L757-L761
train
alecthomas/kingpin
values_generated.go
ResolvedIPList
func (p *parserMixin) ResolvedIPList() (target *[]net.IP) { target = new([]net.IP) p.ResolvedIPListVar(target) return }
go
func (p *parserMixin) ResolvedIPList() (target *[]net.IP) { target = new([]net.IP) p.ResolvedIPListVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "ResolvedIPList", "(", ")", "(", "target", "*", "[", "]", "net", ".", "IP", ")", "{", "target", "=", "new", "(", "[", "]", "net", ".", "IP", ")", "\n", "p", ".", "ResolvedIPListVar", "(", "target", ")", ...
// ResolvedIPList accumulates net.IP values into a slice.
[ "ResolvedIPList", "accumulates", "net", ".", "IP", "values", "into", "a", "slice", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L768-L772
train
alecthomas/kingpin
values_generated.go
HexBytes
func (p *parserMixin) HexBytes() (target *[]byte) { target = new([]byte) p.HexBytesVar(target) return }
go
func (p *parserMixin) HexBytes() (target *[]byte) { target = new([]byte) p.HexBytesVar(target) return }
[ "func", "(", "p", "*", "parserMixin", ")", "HexBytes", "(", ")", "(", "target", "*", "[", "]", "byte", ")", "{", "target", "=", "new", "(", "[", "]", "byte", ")", "\n", "p", ".", "HexBytesVar", "(", "target", ")", "\n", "return", "\n", "}" ]
// Bytes as a hex string.
[ "Bytes", "as", "a", "hex", "string", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/values_generated.go#L800-L804
train
alecthomas/kingpin
global.go
Parse
func Parse() string { selected := MustParse(CommandLine.Parse(os.Args[1:])) if selected == "" && CommandLine.cmdGroup.have() { Usage() CommandLine.terminate(0) } return selected }
go
func Parse() string { selected := MustParse(CommandLine.Parse(os.Args[1:])) if selected == "" && CommandLine.cmdGroup.have() { Usage() CommandLine.terminate(0) } return selected }
[ "func", "Parse", "(", ")", "string", "{", "selected", ":=", "MustParse", "(", "CommandLine", ".", "Parse", "(", "os", ".", "Args", "[", "1", ":", "]", ")", ")", "\n", "if", "selected", "==", "\"", "\"", "&&", "CommandLine", ".", "cmdGroup", ".", "h...
// Parse and return the selected command. Will call the termination handler if // an error is encountered.
[ "Parse", "and", "return", "the", "selected", "command", ".", "Will", "call", "the", "termination", "handler", "if", "an", "error", "is", "encountered", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/global.go#L38-L45
train
alecthomas/kingpin
global.go
FatalIfError
func FatalIfError(err error, format string, args ...interface{}) { CommandLine.FatalIfError(err, format, args...) }
go
func FatalIfError(err error, format string, args ...interface{}) { CommandLine.FatalIfError(err, format, args...) }
[ "func", "FatalIfError", "(", "err", "error", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "CommandLine", ".", "FatalIfError", "(", "err", ",", "format", ",", "args", "...", ")", "\n", "}" ]
// FatalIfError prints an error and exits if err is not nil. The error is printed // with the given prefix.
[ "FatalIfError", "prints", "an", "error", "and", "exits", "if", "err", "is", "not", "nil", ".", "The", "error", "is", "printed", "with", "the", "given", "prefix", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/global.go#L59-L61
train
alecthomas/kingpin
global.go
FatalUsageContext
func FatalUsageContext(context *ParseContext, format string, args ...interface{}) { CommandLine.FatalUsageContext(context, format, args...) }
go
func FatalUsageContext(context *ParseContext, format string, args ...interface{}) { CommandLine.FatalUsageContext(context, format, args...) }
[ "func", "FatalUsageContext", "(", "context", "*", "ParseContext", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "CommandLine", ".", "FatalUsageContext", "(", "context", ",", "format", ",", "args", "...", ")", "\n", "}" ]
// FatalUsageContext writes a printf formatted error message to stderr, then // usage information for the given ParseContext, before exiting.
[ "FatalUsageContext", "writes", "a", "printf", "formatted", "error", "message", "to", "stderr", "then", "usage", "information", "for", "the", "given", "ParseContext", "before", "exiting", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/global.go#L71-L73
train
alecthomas/kingpin
args.go
GetArg
func (a *argGroup) GetArg(name string) *ArgClause { for _, arg := range a.args { if arg.name == name { return arg } } return nil }
go
func (a *argGroup) GetArg(name string) *ArgClause { for _, arg := range a.args { if arg.name == name { return arg } } return nil }
[ "func", "(", "a", "*", "argGroup", ")", "GetArg", "(", "name", "string", ")", "*", "ArgClause", "{", "for", "_", ",", "arg", ":=", "range", "a", ".", "args", "{", "if", "arg", ".", "name", "==", "name", "{", "return", "arg", "\n", "}", "\n", "}...
// GetArg gets an argument definition. // // This allows existing arguments to be modified after definition but before parsing. Useful for // modular applications.
[ "GetArg", "gets", "an", "argument", "definition", ".", "This", "allows", "existing", "arguments", "to", "be", "modified", "after", "definition", "but", "before", "parsing", ".", "Useful", "for", "modular", "applications", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/args.go#L23-L30
train
alecthomas/kingpin
completions.go
addHintActionBuiltin
func (a *completionsMixin) addHintActionBuiltin(action HintAction) { a.builtinHintActions = append(a.builtinHintActions, action) }
go
func (a *completionsMixin) addHintActionBuiltin(action HintAction) { a.builtinHintActions = append(a.builtinHintActions, action) }
[ "func", "(", "a", "*", "completionsMixin", ")", "addHintActionBuiltin", "(", "action", "HintAction", ")", "{", "a", ".", "builtinHintActions", "=", "append", "(", "a", ".", "builtinHintActions", ",", "action", ")", "\n", "}" ]
// Allow adding of HintActions which are added internally, ie, EnumVar
[ "Allow", "adding", "of", "HintActions", "which", "are", "added", "internally", "ie", "EnumVar" ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/completions.go#L16-L18
train
alecthomas/kingpin
cmd.go
CmdCompletion
func (c *cmdMixin) CmdCompletion(context *ParseContext) []string { var options []string // Count args already satisfied - we won't complete those, and add any // default commands' alternatives, since they weren't listed explicitly // and the user may want to explicitly list something else. argsSatisfied := 0 allSatisfied := false ElementLoop: for _, el := range context.Elements { switch clause := el.Clause.(type) { case *ArgClause: // Each new element should reset the previous state allSatisfied = false options = nil if el.Value != nil && *el.Value != "" { // Get the list of valid options for the last argument validOptions := c.argGroup.args[argsSatisfied].resolveCompletions() if len(validOptions) == 0 { // If there are no options for this argument, // mark is as allSatisfied as we can't suggest anything argsSatisfied++ allSatisfied = true continue ElementLoop } for _, opt := range validOptions { if opt == *el.Value { // We have an exact match // We don't need to suggest any option argsSatisfied++ continue ElementLoop } if strings.HasPrefix(opt, *el.Value) { // If the option match the partially entered argument, add it to the list options = append(options, opt) } } // Avoid further completion as we have done everything we could argsSatisfied++ allSatisfied = true } case *CmdClause: options = append(options, clause.completionAlts...) default: } } if argsSatisfied < len(c.argGroup.args) && !allSatisfied { // Since not all args have been satisfied, show options for the current one options = append(options, c.argGroup.args[argsSatisfied].resolveCompletions()...) } else { // If all args are satisfied, then go back to completing commands for _, cmd := range c.cmdGroup.commandOrder { if !cmd.hidden { options = append(options, cmd.name) } } } return options }
go
func (c *cmdMixin) CmdCompletion(context *ParseContext) []string { var options []string // Count args already satisfied - we won't complete those, and add any // default commands' alternatives, since they weren't listed explicitly // and the user may want to explicitly list something else. argsSatisfied := 0 allSatisfied := false ElementLoop: for _, el := range context.Elements { switch clause := el.Clause.(type) { case *ArgClause: // Each new element should reset the previous state allSatisfied = false options = nil if el.Value != nil && *el.Value != "" { // Get the list of valid options for the last argument validOptions := c.argGroup.args[argsSatisfied].resolveCompletions() if len(validOptions) == 0 { // If there are no options for this argument, // mark is as allSatisfied as we can't suggest anything argsSatisfied++ allSatisfied = true continue ElementLoop } for _, opt := range validOptions { if opt == *el.Value { // We have an exact match // We don't need to suggest any option argsSatisfied++ continue ElementLoop } if strings.HasPrefix(opt, *el.Value) { // If the option match the partially entered argument, add it to the list options = append(options, opt) } } // Avoid further completion as we have done everything we could argsSatisfied++ allSatisfied = true } case *CmdClause: options = append(options, clause.completionAlts...) default: } } if argsSatisfied < len(c.argGroup.args) && !allSatisfied { // Since not all args have been satisfied, show options for the current one options = append(options, c.argGroup.args[argsSatisfied].resolveCompletions()...) } else { // If all args are satisfied, then go back to completing commands for _, cmd := range c.cmdGroup.commandOrder { if !cmd.hidden { options = append(options, cmd.name) } } } return options }
[ "func", "(", "c", "*", "cmdMixin", ")", "CmdCompletion", "(", "context", "*", "ParseContext", ")", "[", "]", "string", "{", "var", "options", "[", "]", "string", "\n\n", "// Count args already satisfied - we won't complete those, and add any", "// default commands' alte...
// CmdCompletion returns completion options for arguments, if that's where // parsing left off, or commands if there aren't any unsatisfied args.
[ "CmdCompletion", "returns", "completion", "options", "for", "arguments", "if", "that", "s", "where", "parsing", "left", "off", "or", "commands", "if", "there", "aren", "t", "any", "unsatisfied", "args", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/cmd.go#L17-L79
train
alecthomas/kingpin
cmd.go
Alias
func (c *CmdClause) Alias(name string) *CmdClause { c.aliases = append(c.aliases, name) return c }
go
func (c *CmdClause) Alias(name string) *CmdClause { c.aliases = append(c.aliases, name) return c }
[ "func", "(", "c", "*", "CmdClause", ")", "Alias", "(", "name", "string", ")", "*", "CmdClause", "{", "c", ".", "aliases", "=", "append", "(", "c", ".", "aliases", ",", "name", ")", "\n", "return", "c", "\n", "}" ]
// Add an Alias for this command.
[ "Add", "an", "Alias", "for", "this", "command", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/cmd.go#L243-L246
train
alecthomas/kingpin
cmd.go
Command
func (c *CmdClause) Command(name, help string) *CmdClause { cmd := c.addCommand(name, help) cmd.parent = c return cmd }
go
func (c *CmdClause) Command(name, help string) *CmdClause { cmd := c.addCommand(name, help) cmd.parent = c return cmd }
[ "func", "(", "c", "*", "CmdClause", ")", "Command", "(", "name", ",", "help", "string", ")", "*", "CmdClause", "{", "cmd", ":=", "c", ".", "addCommand", "(", "name", ",", "help", ")", "\n", "cmd", ".", "parent", "=", "c", "\n", "return", "cmd", "...
// Command adds a new sub-command.
[ "Command", "adds", "a", "new", "sub", "-", "command", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/cmd.go#L263-L267
train
alecthomas/kingpin
parser.go
Next
func (p *ParseContext) Next() *Token { if len(p.peek) > 0 { return p.pop() } // End of tokens. if len(p.args) == 0 { return &Token{Index: p.argi, Type: TokenEOL} } arg := p.args[0] p.next() if p.argsOnly { return &Token{p.argi, TokenArg, arg} } // All remaining args are passed directly. if arg == "--" { p.argsOnly = true return p.Next() } if strings.HasPrefix(arg, "--") { parts := strings.SplitN(arg[2:], "=", 2) token := &Token{p.argi, TokenLong, parts[0]} if len(parts) == 2 { p.Push(&Token{p.argi, TokenArg, parts[1]}) } return token } if strings.HasPrefix(arg, "-") { if len(arg) == 1 { return &Token{Index: p.argi, Type: TokenShort} } shortRune, size := utf8.DecodeRuneInString(arg[1:]) short := string(shortRune) flag, ok := p.flags.short[short] // Not a known short flag, we'll just return it anyway. if !ok { } else if fb, ok := flag.value.(boolFlag); ok && fb.IsBoolFlag() { // Bool short flag. } else { // Short flag with combined argument: -fARG token := &Token{p.argi, TokenShort, short} if len(arg) > size+1 { p.Push(&Token{p.argi, TokenArg, arg[size+1:]}) } return token } if len(arg) > size+1 { p.args = append([]string{"-" + arg[size+1:]}, p.args...) } return &Token{p.argi, TokenShort, short} } else if EnableFileExpansion && strings.HasPrefix(arg, "@") { expanded, err := ExpandArgsFromFile(arg[1:]) if err != nil { return &Token{p.argi, TokenError, err.Error()} } if len(p.args) == 0 { p.args = expanded } else { p.args = append(expanded, p.args...) } return p.Next() } return &Token{p.argi, TokenArg, arg} }
go
func (p *ParseContext) Next() *Token { if len(p.peek) > 0 { return p.pop() } // End of tokens. if len(p.args) == 0 { return &Token{Index: p.argi, Type: TokenEOL} } arg := p.args[0] p.next() if p.argsOnly { return &Token{p.argi, TokenArg, arg} } // All remaining args are passed directly. if arg == "--" { p.argsOnly = true return p.Next() } if strings.HasPrefix(arg, "--") { parts := strings.SplitN(arg[2:], "=", 2) token := &Token{p.argi, TokenLong, parts[0]} if len(parts) == 2 { p.Push(&Token{p.argi, TokenArg, parts[1]}) } return token } if strings.HasPrefix(arg, "-") { if len(arg) == 1 { return &Token{Index: p.argi, Type: TokenShort} } shortRune, size := utf8.DecodeRuneInString(arg[1:]) short := string(shortRune) flag, ok := p.flags.short[short] // Not a known short flag, we'll just return it anyway. if !ok { } else if fb, ok := flag.value.(boolFlag); ok && fb.IsBoolFlag() { // Bool short flag. } else { // Short flag with combined argument: -fARG token := &Token{p.argi, TokenShort, short} if len(arg) > size+1 { p.Push(&Token{p.argi, TokenArg, arg[size+1:]}) } return token } if len(arg) > size+1 { p.args = append([]string{"-" + arg[size+1:]}, p.args...) } return &Token{p.argi, TokenShort, short} } else if EnableFileExpansion && strings.HasPrefix(arg, "@") { expanded, err := ExpandArgsFromFile(arg[1:]) if err != nil { return &Token{p.argi, TokenError, err.Error()} } if len(p.args) == 0 { p.args = expanded } else { p.args = append(expanded, p.args...) } return p.Next() } return &Token{p.argi, TokenArg, arg} }
[ "func", "(", "p", "*", "ParseContext", ")", "Next", "(", ")", "*", "Token", "{", "if", "len", "(", "p", ".", "peek", ")", ">", "0", "{", "return", "p", ".", "pop", "(", ")", "\n", "}", "\n\n", "// End of tokens.", "if", "len", "(", "p", ".", ...
// Next token in the parse context.
[ "Next", "token", "in", "the", "parse", "context", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/parser.go#L161-L231
train
alecthomas/kingpin
usage.go
Usage
func (a *Application) Usage(args []string) { context, err := a.parseContext(true, args) a.FatalIfError(err, "") if err := a.UsageForContextWithTemplate(context, 2, a.usageTemplate); err != nil { panic(err) } }
go
func (a *Application) Usage(args []string) { context, err := a.parseContext(true, args) a.FatalIfError(err, "") if err := a.UsageForContextWithTemplate(context, 2, a.usageTemplate); err != nil { panic(err) } }
[ "func", "(", "a", "*", "Application", ")", "Usage", "(", "args", "[", "]", "string", ")", "{", "context", ",", "err", ":=", "a", ".", "parseContext", "(", "true", ",", "args", ")", "\n", "a", ".", "FatalIfError", "(", "err", ",", "\"", "\"", ")",...
// Usage writes application usage to w. It parses args to determine // appropriate help context, such as which command to show help for.
[ "Usage", "writes", "application", "usage", "to", "w", ".", "It", "parses", "args", "to", "determine", "appropriate", "help", "context", "such", "as", "which", "command", "to", "show", "help", "for", "." ]
ef6e7c151c4fdbd3fe78aad001729fee08fa0932
https://github.com/alecthomas/kingpin/blob/ef6e7c151c4fdbd3fe78aad001729fee08fa0932/usage.go#L46-L52
train
emersion/go-imap
search.go
ParseWithCharset
func (c *SearchCriteria) ParseWithCharset(fields []interface{}, charsetReader func(io.Reader) io.Reader) error { for len(fields) > 0 { var err error if fields, err = c.parseField(fields, charsetReader); err != nil { return err } } return nil }
go
func (c *SearchCriteria) ParseWithCharset(fields []interface{}, charsetReader func(io.Reader) io.Reader) error { for len(fields) > 0 { var err error if fields, err = c.parseField(fields, charsetReader); err != nil { return err } } return nil }
[ "func", "(", "c", "*", "SearchCriteria", ")", "ParseWithCharset", "(", "fields", "[", "]", "interface", "{", "}", ",", "charsetReader", "func", "(", "io", ".", "Reader", ")", "io", ".", "Reader", ")", "error", "{", "for", "len", "(", "fields", ")", "...
// ParseWithCharset parses a search criteria from the provided fields. // charsetReader is an optional function that converts from the fields charset // to UTF-8.
[ "ParseWithCharset", "parses", "a", "search", "criteria", "from", "the", "provided", "fields", ".", "charsetReader", "is", "an", "optional", "function", "that", "converts", "from", "the", "fields", "charset", "to", "UTF", "-", "8", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/search.go#L264-L272
train
emersion/go-imap
backend/backendutil/envelope.go
FetchEnvelope
func FetchEnvelope(h message.Header) (*imap.Envelope, error) { mh := mail.Header{Header: h} env := new(imap.Envelope) env.Date, _ = mh.Date() env.Subject, _ = mh.Subject() env.From, _ = headerAddressList(mh, "From") env.Sender, _ = headerAddressList(mh, "Sender") env.ReplyTo, _ = headerAddressList(mh, "Reply-To") env.To, _ = headerAddressList(mh, "To") env.Cc, _ = headerAddressList(mh, "Cc") env.Bcc, _ = headerAddressList(mh, "Bcc") env.InReplyTo = mh.Get("In-Reply-To") env.MessageId = mh.Get("Message-Id") return env, nil }
go
func FetchEnvelope(h message.Header) (*imap.Envelope, error) { mh := mail.Header{Header: h} env := new(imap.Envelope) env.Date, _ = mh.Date() env.Subject, _ = mh.Subject() env.From, _ = headerAddressList(mh, "From") env.Sender, _ = headerAddressList(mh, "Sender") env.ReplyTo, _ = headerAddressList(mh, "Reply-To") env.To, _ = headerAddressList(mh, "To") env.Cc, _ = headerAddressList(mh, "Cc") env.Bcc, _ = headerAddressList(mh, "Bcc") env.InReplyTo = mh.Get("In-Reply-To") env.MessageId = mh.Get("Message-Id") return env, nil }
[ "func", "FetchEnvelope", "(", "h", "message", ".", "Header", ")", "(", "*", "imap", ".", "Envelope", ",", "error", ")", "{", "mh", ":=", "mail", ".", "Header", "{", "Header", ":", "h", "}", "\n\n", "env", ":=", "new", "(", "imap", ".", "Envelope", ...
// FetchEnvelope returns a message's envelope from its header.
[ "FetchEnvelope", "returns", "a", "message", "s", "envelope", "from", "its", "header", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/backend/backendutil/envelope.go#L34-L50
train
emersion/go-imap
backend/backendutil/flags.go
UpdateFlags
func UpdateFlags(current []string, op imap.FlagsOp, flags []string) []string { switch op { case imap.SetFlags: // TODO: keep \Recent if it is present return flags case imap.AddFlags: // Check for duplicates for _, flag := range current { for i, addFlag := range flags { if addFlag == flag { flags = append(flags[:i], flags[i+1:]...) break } } } return append(current, flags...) case imap.RemoveFlags: // Iterate through flags from the last one to the first one, to be able to // delete some of them. for i := len(current) - 1; i >= 0; i-- { flag := current[i] for _, removeFlag := range flags { if removeFlag == flag { current = append(current[:i], current[i+1:]...) break } } } return current } return current }
go
func UpdateFlags(current []string, op imap.FlagsOp, flags []string) []string { switch op { case imap.SetFlags: // TODO: keep \Recent if it is present return flags case imap.AddFlags: // Check for duplicates for _, flag := range current { for i, addFlag := range flags { if addFlag == flag { flags = append(flags[:i], flags[i+1:]...) break } } } return append(current, flags...) case imap.RemoveFlags: // Iterate through flags from the last one to the first one, to be able to // delete some of them. for i := len(current) - 1; i >= 0; i-- { flag := current[i] for _, removeFlag := range flags { if removeFlag == flag { current = append(current[:i], current[i+1:]...) break } } } return current } return current }
[ "func", "UpdateFlags", "(", "current", "[", "]", "string", ",", "op", "imap", ".", "FlagsOp", ",", "flags", "[", "]", "string", ")", "[", "]", "string", "{", "switch", "op", "{", "case", "imap", ".", "SetFlags", ":", "// TODO: keep \\Recent if it is presen...
// UpdateFlags executes a flag operation on the flag set current.
[ "UpdateFlags", "executes", "a", "flag", "operation", "on", "the", "flag", "set", "current", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/backend/backendutil/flags.go#L8-L40
train
emersion/go-imap
mailbox.go
CanonicalMailboxName
func CanonicalMailboxName(name string) string { if strings.ToUpper(name) == InboxName { return InboxName } return name }
go
func CanonicalMailboxName(name string) string { if strings.ToUpper(name) == InboxName { return InboxName } return name }
[ "func", "CanonicalMailboxName", "(", "name", "string", ")", "string", "{", "if", "strings", ".", "ToUpper", "(", "name", ")", "==", "InboxName", "{", "return", "InboxName", "\n", "}", "\n", "return", "name", "\n", "}" ]
// CanonicalMailboxName returns the canonical form of a mailbox name. Mailbox names can be // case-sensitive or case-insensitive depending on the backend implementation. // The special INBOX mailbox is case-insensitive.
[ "CanonicalMailboxName", "returns", "the", "canonical", "form", "of", "a", "mailbox", "name", ".", "Mailbox", "names", "can", "be", "case", "-", "sensitive", "or", "case", "-", "insensitive", "depending", "on", "the", "backend", "implementation", ".", "The", "s...
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/mailbox.go#L18-L23
train
emersion/go-imap
mailbox.go
Parse
func (info *MailboxInfo) Parse(fields []interface{}) error { if len(fields) < 3 { return errors.New("Mailbox info needs at least 3 fields") } var err error if info.Attributes, err = ParseStringList(fields[0]); err != nil { return err } var ok bool if info.Delimiter, ok = fields[1].(string); !ok { return errors.New("Mailbox delimiter must be a string") } if name, err := ParseString(fields[2]); err != nil { return err } else if name, err := utf7.Encoding.NewDecoder().String(name); err != nil { return err } else { info.Name = CanonicalMailboxName(name) } return nil }
go
func (info *MailboxInfo) Parse(fields []interface{}) error { if len(fields) < 3 { return errors.New("Mailbox info needs at least 3 fields") } var err error if info.Attributes, err = ParseStringList(fields[0]); err != nil { return err } var ok bool if info.Delimiter, ok = fields[1].(string); !ok { return errors.New("Mailbox delimiter must be a string") } if name, err := ParseString(fields[2]); err != nil { return err } else if name, err := utf7.Encoding.NewDecoder().String(name); err != nil { return err } else { info.Name = CanonicalMailboxName(name) } return nil }
[ "func", "(", "info", "*", "MailboxInfo", ")", "Parse", "(", "fields", "[", "]", "interface", "{", "}", ")", "error", "{", "if", "len", "(", "fields", ")", "<", "3", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "...
// Parse mailbox info from fields.
[ "Parse", "mailbox", "info", "from", "fields", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/mailbox.go#L52-L76
train
emersion/go-imap
mailbox.go
Format
func (info *MailboxInfo) Format() []interface{} { name, _ := utf7.Encoding.NewEncoder().String(info.Name) attrs := make([]interface{}, len(info.Attributes)) for i, attr := range info.Attributes { attrs[i] = Atom(attr) } // Thunderbird doesn't understand delimiters if not quoted return []interface{}{attrs, Quoted(info.Delimiter), name} }
go
func (info *MailboxInfo) Format() []interface{} { name, _ := utf7.Encoding.NewEncoder().String(info.Name) attrs := make([]interface{}, len(info.Attributes)) for i, attr := range info.Attributes { attrs[i] = Atom(attr) } // Thunderbird doesn't understand delimiters if not quoted return []interface{}{attrs, Quoted(info.Delimiter), name} }
[ "func", "(", "info", "*", "MailboxInfo", ")", "Format", "(", ")", "[", "]", "interface", "{", "}", "{", "name", ",", "_", ":=", "utf7", ".", "Encoding", ".", "NewEncoder", "(", ")", ".", "String", "(", "info", ".", "Name", ")", "\n", "attrs", ":=...
// Format mailbox info to fields.
[ "Format", "mailbox", "info", "to", "fields", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/mailbox.go#L79-L87
train
emersion/go-imap
mailbox.go
Match
func (info *MailboxInfo) Match(reference, pattern string) bool { name := info.Name if strings.HasPrefix(pattern, info.Delimiter) { reference = "" pattern = strings.TrimPrefix(pattern, info.Delimiter) } if reference != "" { if !strings.HasSuffix(reference, info.Delimiter) { reference += info.Delimiter } if !strings.HasPrefix(name, reference) { return false } name = strings.TrimPrefix(name, reference) } return info.match(name, pattern) }
go
func (info *MailboxInfo) Match(reference, pattern string) bool { name := info.Name if strings.HasPrefix(pattern, info.Delimiter) { reference = "" pattern = strings.TrimPrefix(pattern, info.Delimiter) } if reference != "" { if !strings.HasSuffix(reference, info.Delimiter) { reference += info.Delimiter } if !strings.HasPrefix(name, reference) { return false } name = strings.TrimPrefix(name, reference) } return info.match(name, pattern) }
[ "func", "(", "info", "*", "MailboxInfo", ")", "Match", "(", "reference", ",", "pattern", "string", ")", "bool", "{", "name", ":=", "info", ".", "Name", "\n\n", "if", "strings", ".", "HasPrefix", "(", "pattern", ",", "info", ".", "Delimiter", ")", "{", ...
// Match checks if a reference and a pattern matches this mailbox name, as // defined in RFC 3501 section 6.3.8.
[ "Match", "checks", "if", "a", "reference", "and", "a", "pattern", "matches", "this", "mailbox", "name", "as", "defined", "in", "RFC", "3501", "section", "6", ".", "3", ".", "8", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/mailbox.go#L123-L141
train
emersion/go-imap
mailbox.go
NewMailboxStatus
func NewMailboxStatus(name string, items []StatusItem) *MailboxStatus { status := &MailboxStatus{ Name: name, Items: make(map[StatusItem]interface{}), } for _, k := range items { status.Items[k] = nil } return status }
go
func NewMailboxStatus(name string, items []StatusItem) *MailboxStatus { status := &MailboxStatus{ Name: name, Items: make(map[StatusItem]interface{}), } for _, k := range items { status.Items[k] = nil } return status }
[ "func", "NewMailboxStatus", "(", "name", "string", ",", "items", "[", "]", "StatusItem", ")", "*", "MailboxStatus", "{", "status", ":=", "&", "MailboxStatus", "{", "Name", ":", "name", ",", "Items", ":", "make", "(", "map", "[", "StatusItem", "]", "inter...
// Create a new mailbox status that will contain the specified items.
[ "Create", "a", "new", "mailbox", "status", "that", "will", "contain", "the", "specified", "items", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/mailbox.go#L179-L190
train
emersion/go-imap
backend/updates.go
NewUpdate
func NewUpdate(username, mailbox string) Update { return &update{ username: username, mailbox: mailbox, } }
go
func NewUpdate(username, mailbox string) Update { return &update{ username: username, mailbox: mailbox, } }
[ "func", "NewUpdate", "(", "username", ",", "mailbox", "string", ")", "Update", "{", "return", "&", "update", "{", "username", ":", "username", ",", "mailbox", ":", "mailbox", ",", "}", "\n", "}" ]
// NewUpdate creates a new update.
[ "NewUpdate", "creates", "a", "new", "update", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/backend/updates.go#L22-L27
train
emersion/go-imap
client/client.go
State
func (c *Client) State() imap.ConnState { c.locker.Lock() state := c.state c.locker.Unlock() return state }
go
func (c *Client) State() imap.ConnState { c.locker.Lock() state := c.state c.locker.Unlock() return state }
[ "func", "(", "c", "*", "Client", ")", "State", "(", ")", "imap", ".", "ConnState", "{", "c", ".", "locker", ".", "Lock", "(", ")", "\n", "state", ":=", "c", ".", "state", "\n", "c", ".", "locker", ".", "Unlock", "(", ")", "\n", "return", "state...
// State returns the current connection state.
[ "State", "returns", "the", "current", "connection", "state", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/client.go#L278-L283
train
emersion/go-imap
client/client.go
Mailbox
func (c *Client) Mailbox() *imap.MailboxStatus { // c.Mailbox fields are not supposed to change, so we can return the pointer. c.locker.Lock() mbox := c.mailbox c.locker.Unlock() return mbox }
go
func (c *Client) Mailbox() *imap.MailboxStatus { // c.Mailbox fields are not supposed to change, so we can return the pointer. c.locker.Lock() mbox := c.mailbox c.locker.Unlock() return mbox }
[ "func", "(", "c", "*", "Client", ")", "Mailbox", "(", ")", "*", "imap", ".", "MailboxStatus", "{", "// c.Mailbox fields are not supposed to change, so we can return the pointer.", "c", ".", "locker", ".", "Lock", "(", ")", "\n", "mbox", ":=", "c", ".", "mailbox"...
// Mailbox returns the selected mailbox. It returns nil if there isn't one.
[ "Mailbox", "returns", "the", "selected", "mailbox", ".", "It", "returns", "nil", "if", "there", "isn", "t", "one", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/client.go#L286-L292
train
emersion/go-imap
client/client.go
SetState
func (c *Client) SetState(state imap.ConnState, mailbox *imap.MailboxStatus) { c.locker.Lock() c.state = state c.mailbox = mailbox c.locker.Unlock() }
go
func (c *Client) SetState(state imap.ConnState, mailbox *imap.MailboxStatus) { c.locker.Lock() c.state = state c.mailbox = mailbox c.locker.Unlock() }
[ "func", "(", "c", "*", "Client", ")", "SetState", "(", "state", "imap", ".", "ConnState", ",", "mailbox", "*", "imap", ".", "MailboxStatus", ")", "{", "c", ".", "locker", ".", "Lock", "(", ")", "\n", "c", ".", "state", "=", "state", "\n", "c", "....
// SetState sets this connection's internal state. // // This function should not be called directly, it must only be used by // libraries implementing extensions of the IMAP protocol.
[ "SetState", "sets", "this", "connection", "s", "internal", "state", ".", "This", "function", "should", "not", "be", "called", "directly", "it", "must", "only", "be", "used", "by", "libraries", "implementing", "extensions", "of", "the", "IMAP", "protocol", "." ...
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/client.go#L298-L303
train
emersion/go-imap
client/client.go
Execute
func (c *Client) Execute(cmdr imap.Commander, h responses.Handler) (*imap.StatusResp, error) { return c.execute(cmdr, h) }
go
func (c *Client) Execute(cmdr imap.Commander, h responses.Handler) (*imap.StatusResp, error) { return c.execute(cmdr, h) }
[ "func", "(", "c", "*", "Client", ")", "Execute", "(", "cmdr", "imap", ".", "Commander", ",", "h", "responses", ".", "Handler", ")", "(", "*", "imap", ".", "StatusResp", ",", "error", ")", "{", "return", "c", ".", "execute", "(", "cmdr", ",", "h", ...
// Execute executes a generic command. cmdr is a value that can be converted to // a raw command and h is a response handler. The function returns when the // command has completed or failed, in this case err is nil. A non-nil err value // indicates a network error. // // This function should not be called directly, it must only be used by // libraries implementing extensions of the IMAP protocol.
[ "Execute", "executes", "a", "generic", "command", ".", "cmdr", "is", "a", "value", "that", "can", "be", "converted", "to", "a", "raw", "command", "and", "h", "is", "a", "response", "handler", ".", "The", "function", "returns", "when", "the", "command", "...
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/client.go#L312-L314
train
emersion/go-imap
client/client.go
New
func New(conn net.Conn) (*Client, error) { continues := make(chan bool) w := imap.NewClientWriter(nil, continues) r := imap.NewReader(nil) c := &Client{ conn: imap.NewConn(conn, r, w), replies: make(chan []byte), loggedOut: make(chan struct{}), state: imap.ConnectingState, ErrorLog: log.New(os.Stderr, "imap/client: ", log.LstdFlags), } c.handleContinuationReqs(continues) c.handleUnilateral() err := c.handleGreetAndStartReading() return c, err }
go
func New(conn net.Conn) (*Client, error) { continues := make(chan bool) w := imap.NewClientWriter(nil, continues) r := imap.NewReader(nil) c := &Client{ conn: imap.NewConn(conn, r, w), replies: make(chan []byte), loggedOut: make(chan struct{}), state: imap.ConnectingState, ErrorLog: log.New(os.Stderr, "imap/client: ", log.LstdFlags), } c.handleContinuationReqs(continues) c.handleUnilateral() err := c.handleGreetAndStartReading() return c, err }
[ "func", "New", "(", "conn", "net", ".", "Conn", ")", "(", "*", "Client", ",", "error", ")", "{", "continues", ":=", "make", "(", "chan", "bool", ")", "\n", "w", ":=", "imap", ".", "NewClientWriter", "(", "nil", ",", "continues", ")", "\n", "r", "...
// New creates a new client from an existing connection.
[ "New", "creates", "a", "new", "client", "from", "an", "existing", "connection", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/client.go#L558-L575
train
emersion/go-imap
client/client.go
Dial
func Dial(addr string) (c *Client, err error) { conn, err := net.Dial("tcp", addr) if err != nil { return } c, err = New(conn) return }
go
func Dial(addr string) (c *Client, err error) { conn, err := net.Dial("tcp", addr) if err != nil { return } c, err = New(conn) return }
[ "func", "Dial", "(", "addr", "string", ")", "(", "c", "*", "Client", ",", "err", "error", ")", "{", "conn", ",", "err", ":=", "net", ".", "Dial", "(", "\"", "\"", ",", "addr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n...
// Dial connects to an IMAP server using an unencrypted connection.
[ "Dial", "connects", "to", "an", "IMAP", "server", "using", "an", "unencrypted", "connection", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/client.go#L578-L586
train
emersion/go-imap
client/client.go
DialWithDialer
func DialWithDialer(dialer *net.Dialer, address string) (c *Client, err error) { conn, err := dialer.Dial("tcp", address) if err != nil { return nil, err } // We don't return to the caller until we try to receive a greeting. As such, // there is no way to set the client's Timeout for that action. As a // workaround, if the dialer has a timeout set, use that for the connection's // deadline. if dialer.Timeout > 0 { err = conn.SetDeadline(time.Now().Add(dialer.Timeout)) if err != nil { return } } c, err = New(conn) return }
go
func DialWithDialer(dialer *net.Dialer, address string) (c *Client, err error) { conn, err := dialer.Dial("tcp", address) if err != nil { return nil, err } // We don't return to the caller until we try to receive a greeting. As such, // there is no way to set the client's Timeout for that action. As a // workaround, if the dialer has a timeout set, use that for the connection's // deadline. if dialer.Timeout > 0 { err = conn.SetDeadline(time.Now().Add(dialer.Timeout)) if err != nil { return } } c, err = New(conn) return }
[ "func", "DialWithDialer", "(", "dialer", "*", "net", ".", "Dialer", ",", "address", "string", ")", "(", "c", "*", "Client", ",", "err", "error", ")", "{", "conn", ",", "err", ":=", "dialer", ".", "Dial", "(", "\"", "\"", ",", "address", ")", "\n", ...
// DialWithDialer connects to an IMAP server using an unencrypted connection // using dialer.Dial. // // Among other uses, this allows to apply a dial timeout.
[ "DialWithDialer", "connects", "to", "an", "IMAP", "server", "using", "an", "unencrypted", "connection", "using", "dialer", ".", "Dial", ".", "Among", "other", "uses", "this", "allows", "to", "apply", "a", "dial", "timeout", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/client.go#L592-L611
train
emersion/go-imap
client/client.go
DialTLS
func DialTLS(addr string, tlsConfig *tls.Config) (c *Client, err error) { conn, err := tls.Dial("tcp", addr, tlsConfig) if err != nil { return } c, err = New(conn) c.isTLS = true return }
go
func DialTLS(addr string, tlsConfig *tls.Config) (c *Client, err error) { conn, err := tls.Dial("tcp", addr, tlsConfig) if err != nil { return } c, err = New(conn) c.isTLS = true return }
[ "func", "DialTLS", "(", "addr", "string", ",", "tlsConfig", "*", "tls", ".", "Config", ")", "(", "c", "*", "Client", ",", "err", "error", ")", "{", "conn", ",", "err", ":=", "tls", ".", "Dial", "(", "\"", "\"", ",", "addr", ",", "tlsConfig", ")",...
// DialTLS connects to an IMAP server using an encrypted connection.
[ "DialTLS", "connects", "to", "an", "IMAP", "server", "using", "an", "encrypted", "connection", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/client.go#L614-L623
train
emersion/go-imap
client/client.go
DialWithDialerTLS
func DialWithDialerTLS(dialer *net.Dialer, addr string, tlsConfig *tls.Config) (c *Client, err error) { conn, err := tls.DialWithDialer(dialer, "tcp", addr, tlsConfig) if err != nil { return } // We don't return to the caller until we try to receive a greeting. As such, // there is no way to set the client's Timeout for that action. As a // workaround, if the dialer has a timeout set, use that for the connection's // deadline. if dialer.Timeout > 0 { err = conn.SetDeadline(time.Now().Add(dialer.Timeout)) if err != nil { return } } c, err = New(conn) c.isTLS = true return }
go
func DialWithDialerTLS(dialer *net.Dialer, addr string, tlsConfig *tls.Config) (c *Client, err error) { conn, err := tls.DialWithDialer(dialer, "tcp", addr, tlsConfig) if err != nil { return } // We don't return to the caller until we try to receive a greeting. As such, // there is no way to set the client's Timeout for that action. As a // workaround, if the dialer has a timeout set, use that for the connection's // deadline. if dialer.Timeout > 0 { err = conn.SetDeadline(time.Now().Add(dialer.Timeout)) if err != nil { return } } c, err = New(conn) c.isTLS = true return }
[ "func", "DialWithDialerTLS", "(", "dialer", "*", "net", ".", "Dialer", ",", "addr", "string", ",", "tlsConfig", "*", "tls", ".", "Config", ")", "(", "c", "*", "Client", ",", "err", "error", ")", "{", "conn", ",", "err", ":=", "tls", ".", "DialWithDia...
// DialWithDialerTLS connects to an IMAP server using an encrypted connection // using dialer.Dial. // // Among other uses, this allows to apply a dial timeout.
[ "DialWithDialerTLS", "connects", "to", "an", "IMAP", "server", "using", "an", "encrypted", "connection", "using", "dialer", ".", "Dial", ".", "Among", "other", "uses", "this", "allows", "to", "apply", "a", "dial", "timeout", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/client.go#L629-L650
train
emersion/go-imap
write.go
FormatStringList
func FormatStringList(list []string) (fields []interface{}) { fields = make([]interface{}, len(list)) for i, v := range list { fields[i] = v } return }
go
func FormatStringList(list []string) (fields []interface{}) { fields = make([]interface{}, len(list)) for i, v := range list { fields[i] = v } return }
[ "func", "FormatStringList", "(", "list", "[", "]", "string", ")", "(", "fields", "[", "]", "interface", "{", "}", ")", "{", "fields", "=", "make", "(", "[", "]", "interface", "{", "}", ",", "len", "(", "list", ")", ")", "\n", "for", "i", ",", "...
// Convert a string list to a field list.
[ "Convert", "a", "string", "list", "to", "a", "field", "list", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/write.go#L33-L39
train
emersion/go-imap
write.go
isAscii
func isAscii(s string) bool { for _, c := range s { if c > unicode.MaxASCII || unicode.IsControl(c) { return false } } return true }
go
func isAscii(s string) bool { for _, c := range s { if c > unicode.MaxASCII || unicode.IsControl(c) { return false } } return true }
[ "func", "isAscii", "(", "s", "string", ")", "bool", "{", "for", "_", ",", "c", ":=", "range", "s", "{", "if", "c", ">", "unicode", ".", "MaxASCII", "||", "unicode", ".", "IsControl", "(", "c", ")", "{", "return", "false", "\n", "}", "\n", "}", ...
// Check if a string is 8-bit clean.
[ "Check", "if", "a", "string", "is", "8", "-", "bit", "clean", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/write.go#L42-L49
train
emersion/go-imap
write.go
writeString
func (w *Writer) writeString(s string) error { _, err := io.WriteString(w.Writer, s) return err }
go
func (w *Writer) writeString(s string) error { _, err := io.WriteString(w.Writer, s) return err }
[ "func", "(", "w", "*", "Writer", ")", "writeString", "(", "s", "string", ")", "error", "{", "_", ",", "err", ":=", "io", ".", "WriteString", "(", "w", ".", "Writer", ",", "s", ")", "\n", "return", "err", "\n", "}" ]
// Helper function to write a string to w.
[ "Helper", "function", "to", "write", "a", "string", "to", "w", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/write.go#L59-L62
train
emersion/go-imap
utf7/decoder.go
decode
func decode(b64 []byte) []byte { var b []byte // Allocate a single block of memory large enough to store the Base64 data // (if padding is required), UTF-16-BE bytes, and decoded UTF-8 bytes. // Since a 2-byte UTF-16 sequence may expand into a 3-byte UTF-8 sequence, // double the space allocation for UTF-8. if n := len(b64); b64[n-1] == '=' { return nil } else if n&3 == 0 { b = make([]byte, b64Enc.DecodedLen(n)*3) } else { n += 4 - n&3 b = make([]byte, n+b64Enc.DecodedLen(n)*3) copy(b[copy(b, b64):n], []byte("==")) b64, b = b[:n], b[n:] } // Decode Base64 into the first 1/3rd of b n, err := b64Enc.Decode(b, b64) if err != nil || n&1 == 1 { return nil } // Decode UTF-16-BE into the remaining 2/3rds of b b, s := b[:n], b[n:] j := 0 for i := 0; i < n; i += 2 { r := rune(b[i])<<8 | rune(b[i+1]) if utf16.IsSurrogate(r) { if i += 2; i == n { return nil } r2 := rune(b[i])<<8 | rune(b[i+1]) if r = utf16.DecodeRune(r, r2); r == repl { return nil } } else if min <= r && r <= max { return nil } j += utf8.EncodeRune(s[j:], r) } return s[:j] }
go
func decode(b64 []byte) []byte { var b []byte // Allocate a single block of memory large enough to store the Base64 data // (if padding is required), UTF-16-BE bytes, and decoded UTF-8 bytes. // Since a 2-byte UTF-16 sequence may expand into a 3-byte UTF-8 sequence, // double the space allocation for UTF-8. if n := len(b64); b64[n-1] == '=' { return nil } else if n&3 == 0 { b = make([]byte, b64Enc.DecodedLen(n)*3) } else { n += 4 - n&3 b = make([]byte, n+b64Enc.DecodedLen(n)*3) copy(b[copy(b, b64):n], []byte("==")) b64, b = b[:n], b[n:] } // Decode Base64 into the first 1/3rd of b n, err := b64Enc.Decode(b, b64) if err != nil || n&1 == 1 { return nil } // Decode UTF-16-BE into the remaining 2/3rds of b b, s := b[:n], b[n:] j := 0 for i := 0; i < n; i += 2 { r := rune(b[i])<<8 | rune(b[i+1]) if utf16.IsSurrogate(r) { if i += 2; i == n { return nil } r2 := rune(b[i])<<8 | rune(b[i+1]) if r = utf16.DecodeRune(r, r2); r == repl { return nil } } else if min <= r && r <= max { return nil } j += utf8.EncodeRune(s[j:], r) } return s[:j] }
[ "func", "decode", "(", "b64", "[", "]", "byte", ")", "[", "]", "byte", "{", "var", "b", "[", "]", "byte", "\n\n", "// Allocate a single block of memory large enough to store the Base64 data", "// (if padding is required), UTF-16-BE bytes, and decoded UTF-8 bytes.", "// Since ...
// Extracts UTF-16-BE bytes from base64 data and converts them to UTF-8. // A nil slice is returned if the encoding is invalid.
[ "Extracts", "UTF", "-", "16", "-", "BE", "bytes", "from", "base64", "data", "and", "converts", "them", "to", "UTF", "-", "8", ".", "A", "nil", "slice", "is", "returned", "if", "the", "encoding", "is", "invalid", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/utf7/decoder.go#L105-L148
train
emersion/go-imap
imap.go
Expand
func (item FetchItem) Expand() []FetchItem { switch item { case FetchAll: return []FetchItem{FetchFlags, FetchInternalDate, FetchRFC822Size, FetchEnvelope} case FetchFast: return []FetchItem{FetchFlags, FetchInternalDate, FetchRFC822Size} case FetchFull: return []FetchItem{FetchFlags, FetchInternalDate, FetchRFC822Size, FetchEnvelope, FetchBody} default: return []FetchItem{item} } }
go
func (item FetchItem) Expand() []FetchItem { switch item { case FetchAll: return []FetchItem{FetchFlags, FetchInternalDate, FetchRFC822Size, FetchEnvelope} case FetchFast: return []FetchItem{FetchFlags, FetchInternalDate, FetchRFC822Size} case FetchFull: return []FetchItem{FetchFlags, FetchInternalDate, FetchRFC822Size, FetchEnvelope, FetchBody} default: return []FetchItem{item} } }
[ "func", "(", "item", "FetchItem", ")", "Expand", "(", ")", "[", "]", "FetchItem", "{", "switch", "item", "{", "case", "FetchAll", ":", "return", "[", "]", "FetchItem", "{", "FetchFlags", ",", "FetchInternalDate", ",", "FetchRFC822Size", ",", "FetchEnvelope",...
// Expand expands the item if it's a macro.
[ "Expand", "expands", "the", "item", "if", "it", "s", "a", "macro", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/imap.go#L46-L57
train
emersion/go-imap
imap.go
FormatFlagsOp
func FormatFlagsOp(op FlagsOp, silent bool) StoreItem { s := string(op) if silent { s += silentOp } return StoreItem(s) }
go
func FormatFlagsOp(op FlagsOp, silent bool) StoreItem { s := string(op) if silent { s += silentOp } return StoreItem(s) }
[ "func", "FormatFlagsOp", "(", "op", "FlagsOp", ",", "silent", "bool", ")", "StoreItem", "{", "s", ":=", "string", "(", "op", ")", "\n", "if", "silent", "{", "s", "+=", "silentOp", "\n", "}", "\n", "return", "StoreItem", "(", "s", ")", "\n", "}" ]
// FormatFlagsOp returns the StoreItem that executes the flags operation op.
[ "FormatFlagsOp", "returns", "the", "StoreItem", "that", "executes", "the", "flags", "operation", "op", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/imap.go#L79-L85
train
emersion/go-imap
imap.go
ParseFlagsOp
func ParseFlagsOp(item StoreItem) (op FlagsOp, silent bool, err error) { itemStr := string(item) silent = strings.HasSuffix(itemStr, silentOp) if silent { itemStr = strings.TrimSuffix(itemStr, silentOp) } op = FlagsOp(itemStr) if op != SetFlags && op != AddFlags && op != RemoveFlags { err = errors.New("Unsupported STORE operation") } return }
go
func ParseFlagsOp(item StoreItem) (op FlagsOp, silent bool, err error) { itemStr := string(item) silent = strings.HasSuffix(itemStr, silentOp) if silent { itemStr = strings.TrimSuffix(itemStr, silentOp) } op = FlagsOp(itemStr) if op != SetFlags && op != AddFlags && op != RemoveFlags { err = errors.New("Unsupported STORE operation") } return }
[ "func", "ParseFlagsOp", "(", "item", "StoreItem", ")", "(", "op", "FlagsOp", ",", "silent", "bool", ",", "err", "error", ")", "{", "itemStr", ":=", "string", "(", "item", ")", "\n", "silent", "=", "strings", ".", "HasSuffix", "(", "itemStr", ",", "sile...
// ParseFlagsOp parses a flags operation from StoreItem.
[ "ParseFlagsOp", "parses", "a", "flags", "operation", "from", "StoreItem", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/imap.go#L88-L100
train
emersion/go-imap
client/cmd_any.go
Capability
func (c *Client) Capability() (map[string]bool, error) { cmd := &commands.Capability{} if status, err := c.execute(cmd, nil); err != nil { return nil, err } else if err := status.Err(); err != nil { return nil, err } c.locker.Lock() caps := c.caps c.locker.Unlock() return caps, nil }
go
func (c *Client) Capability() (map[string]bool, error) { cmd := &commands.Capability{} if status, err := c.execute(cmd, nil); err != nil { return nil, err } else if err := status.Err(); err != nil { return nil, err } c.locker.Lock() caps := c.caps c.locker.Unlock() return caps, nil }
[ "func", "(", "c", "*", "Client", ")", "Capability", "(", ")", "(", "map", "[", "string", "]", "bool", ",", "error", ")", "{", "cmd", ":=", "&", "commands", ".", "Capability", "{", "}", "\n\n", "if", "status", ",", "err", ":=", "c", ".", "execute"...
// Capability requests a listing of capabilities that the server supports. // Capabilities are often returned by the server with the greeting or with the // STARTTLS and LOGIN responses, so usually explicitly requesting capabilities // isn't needed. // // Most of the time, Support should be used instead.
[ "Capability", "requests", "a", "listing", "of", "capabilities", "that", "the", "server", "supports", ".", "Capabilities", "are", "often", "returned", "by", "the", "server", "with", "the", "greeting", "or", "with", "the", "STARTTLS", "and", "LOGIN", "responses", ...
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_any.go#L20-L33
train
emersion/go-imap
client/cmd_any.go
Support
func (c *Client) Support(cap string) (bool, error) { c.locker.Lock() ok := c.caps != nil c.locker.Unlock() // If capabilities are not cached, request them if !ok { if _, err := c.Capability(); err != nil { return false, err } } c.locker.Lock() supported := c.caps[cap] c.locker.Unlock() return supported, nil }
go
func (c *Client) Support(cap string) (bool, error) { c.locker.Lock() ok := c.caps != nil c.locker.Unlock() // If capabilities are not cached, request them if !ok { if _, err := c.Capability(); err != nil { return false, err } } c.locker.Lock() supported := c.caps[cap] c.locker.Unlock() return supported, nil }
[ "func", "(", "c", "*", "Client", ")", "Support", "(", "cap", "string", ")", "(", "bool", ",", "error", ")", "{", "c", ".", "locker", ".", "Lock", "(", ")", "\n", "ok", ":=", "c", ".", "caps", "!=", "nil", "\n", "c", ".", "locker", ".", "Unloc...
// Support checks if cap is a capability supported by the server. If the server // hasn't sent its capabilities yet, Support requests them.
[ "Support", "checks", "if", "cap", "is", "a", "capability", "supported", "by", "the", "server", ".", "If", "the", "server", "hasn", "t", "sent", "its", "capabilities", "yet", "Support", "requests", "them", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_any.go#L37-L53
train
emersion/go-imap
client/cmd_any.go
Noop
func (c *Client) Noop() error { cmd := new(commands.Noop) status, err := c.execute(cmd, nil) if err != nil { return err } return status.Err() }
go
func (c *Client) Noop() error { cmd := new(commands.Noop) status, err := c.execute(cmd, nil) if err != nil { return err } return status.Err() }
[ "func", "(", "c", "*", "Client", ")", "Noop", "(", ")", "error", "{", "cmd", ":=", "new", "(", "commands", ".", "Noop", ")", "\n\n", "status", ",", "err", ":=", "c", ".", "execute", "(", "cmd", ",", "nil", ")", "\n", "if", "err", "!=", "nil", ...
// Noop always succeeds and does nothing. // // It can be used as a periodic poll for new messages or message status updates // during a period of inactivity. It can also be used to reset any inactivity // autologout timer on the server.
[ "Noop", "always", "succeeds", "and", "does", "nothing", ".", "It", "can", "be", "used", "as", "a", "periodic", "poll", "for", "new", "messages", "or", "message", "status", "updates", "during", "a", "period", "of", "inactivity", ".", "It", "can", "also", ...
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_any.go#L60-L68
train
emersion/go-imap
client/cmd_any.go
Logout
func (c *Client) Logout() error { if c.State() == imap.LogoutState { return ErrAlreadyLoggedOut } cmd := new(commands.Logout) if status, err := c.execute(cmd, nil); err == errClosed { // Server closed connection, that's what we want anyway return nil } else if err != nil { return err } else if status != nil { return status.Err() } return nil }
go
func (c *Client) Logout() error { if c.State() == imap.LogoutState { return ErrAlreadyLoggedOut } cmd := new(commands.Logout) if status, err := c.execute(cmd, nil); err == errClosed { // Server closed connection, that's what we want anyway return nil } else if err != nil { return err } else if status != nil { return status.Err() } return nil }
[ "func", "(", "c", "*", "Client", ")", "Logout", "(", ")", "error", "{", "if", "c", ".", "State", "(", ")", "==", "imap", ".", "LogoutState", "{", "return", "ErrAlreadyLoggedOut", "\n", "}", "\n\n", "cmd", ":=", "new", "(", "commands", ".", "Logout", ...
// Logout gracefully closes the connection.
[ "Logout", "gracefully", "closes", "the", "connection", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_any.go#L71-L87
train
emersion/go-imap
client/cmd_selected.go
Check
func (c *Client) Check() error { if c.State() != imap.SelectedState { return ErrNoMailboxSelected } cmd := new(commands.Check) status, err := c.execute(cmd, nil) if err != nil { return err } return status.Err() }
go
func (c *Client) Check() error { if c.State() != imap.SelectedState { return ErrNoMailboxSelected } cmd := new(commands.Check) status, err := c.execute(cmd, nil) if err != nil { return err } return status.Err() }
[ "func", "(", "c", "*", "Client", ")", "Check", "(", ")", "error", "{", "if", "c", ".", "State", "(", ")", "!=", "imap", ".", "SelectedState", "{", "return", "ErrNoMailboxSelected", "\n", "}", "\n\n", "cmd", ":=", "new", "(", "commands", ".", "Check",...
// Check requests a checkpoint of the currently selected mailbox. A checkpoint // refers to any implementation-dependent housekeeping associated with the // mailbox that is not normally executed as part of each command.
[ "Check", "requests", "a", "checkpoint", "of", "the", "currently", "selected", "mailbox", ".", "A", "checkpoint", "refers", "to", "any", "implementation", "-", "dependent", "housekeeping", "associated", "with", "the", "mailbox", "that", "is", "not", "normally", "...
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_selected.go#L18-L31
train
emersion/go-imap
client/cmd_selected.go
Close
func (c *Client) Close() error { if c.State() != imap.SelectedState { return ErrNoMailboxSelected } cmd := new(commands.Close) status, err := c.execute(cmd, nil) if err != nil { return err } else if err := status.Err(); err != nil { return err } c.locker.Lock() c.state = imap.AuthenticatedState c.mailbox = nil c.locker.Unlock() return nil }
go
func (c *Client) Close() error { if c.State() != imap.SelectedState { return ErrNoMailboxSelected } cmd := new(commands.Close) status, err := c.execute(cmd, nil) if err != nil { return err } else if err := status.Err(); err != nil { return err } c.locker.Lock() c.state = imap.AuthenticatedState c.mailbox = nil c.locker.Unlock() return nil }
[ "func", "(", "c", "*", "Client", ")", "Close", "(", ")", "error", "{", "if", "c", ".", "State", "(", ")", "!=", "imap", ".", "SelectedState", "{", "return", "ErrNoMailboxSelected", "\n", "}", "\n\n", "cmd", ":=", "new", "(", "commands", ".", "Close",...
// Close permanently removes all messages that have the \Deleted flag set from // the currently selected mailbox, and returns to the authenticated state from // the selected state.
[ "Close", "permanently", "removes", "all", "messages", "that", "have", "the", "\\", "Deleted", "flag", "set", "from", "the", "currently", "selected", "mailbox", "and", "returns", "to", "the", "authenticated", "state", "from", "the", "selected", "state", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_selected.go#L36-L55
train
emersion/go-imap
client/cmd_selected.go
Expunge
func (c *Client) Expunge(ch chan uint32) error { if c.State() != imap.SelectedState { return ErrNoMailboxSelected } cmd := new(commands.Expunge) var h responses.Handler if ch != nil { h = &responses.Expunge{SeqNums: ch} defer close(ch) } status, err := c.execute(cmd, h) if err != nil { return err } return status.Err() }
go
func (c *Client) Expunge(ch chan uint32) error { if c.State() != imap.SelectedState { return ErrNoMailboxSelected } cmd := new(commands.Expunge) var h responses.Handler if ch != nil { h = &responses.Expunge{SeqNums: ch} defer close(ch) } status, err := c.execute(cmd, h) if err != nil { return err } return status.Err() }
[ "func", "(", "c", "*", "Client", ")", "Expunge", "(", "ch", "chan", "uint32", ")", "error", "{", "if", "c", ".", "State", "(", ")", "!=", "imap", ".", "SelectedState", "{", "return", "ErrNoMailboxSelected", "\n", "}", "\n\n", "cmd", ":=", "new", "(",...
// Expunge permanently removes all messages that have the \Deleted flag set from // the currently selected mailbox. If ch is not nil, sends sequence IDs of each // deleted message to this channel.
[ "Expunge", "permanently", "removes", "all", "messages", "that", "have", "the", "\\", "Deleted", "flag", "set", "from", "the", "currently", "selected", "mailbox", ".", "If", "ch", "is", "not", "nil", "sends", "sequence", "IDs", "of", "each", "deleted", "messa...
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_selected.go#L65-L83
train
emersion/go-imap
client/cmd_selected.go
UidSearch
func (c *Client) UidSearch(criteria *imap.SearchCriteria) (uids []uint32, err error) { return c.search(true, criteria) }
go
func (c *Client) UidSearch(criteria *imap.SearchCriteria) (uids []uint32, err error) { return c.search(true, criteria) }
[ "func", "(", "c", "*", "Client", ")", "UidSearch", "(", "criteria", "*", "imap", ".", "SearchCriteria", ")", "(", "uids", "[", "]", "uint32", ",", "err", "error", ")", "{", "return", "c", ".", "search", "(", "true", ",", "criteria", ")", "\n", "}" ...
// UidSearch is identical to Search, but UIDs are returned instead of message // sequence numbers.
[ "UidSearch", "is", "identical", "to", "Search", "but", "UIDs", "are", "returned", "instead", "of", "message", "sequence", "numbers", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_selected.go#L132-L134
train
emersion/go-imap
client/cmd_selected.go
Fetch
func (c *Client) Fetch(seqset *imap.SeqSet, items []imap.FetchItem, ch chan *imap.Message) error { return c.fetch(false, seqset, items, ch) }
go
func (c *Client) Fetch(seqset *imap.SeqSet, items []imap.FetchItem, ch chan *imap.Message) error { return c.fetch(false, seqset, items, ch) }
[ "func", "(", "c", "*", "Client", ")", "Fetch", "(", "seqset", "*", "imap", ".", "SeqSet", ",", "items", "[", "]", "imap", ".", "FetchItem", ",", "ch", "chan", "*", "imap", ".", "Message", ")", "error", "{", "return", "c", ".", "fetch", "(", "fals...
// Fetch retrieves data associated with a message in the mailbox. See RFC 3501 // section 6.4.5 for a list of items that can be requested.
[ "Fetch", "retrieves", "data", "associated", "with", "a", "message", "in", "the", "mailbox", ".", "See", "RFC", "3501", "section", "6", ".", "4", ".", "5", "for", "a", "list", "of", "items", "that", "can", "be", "requested", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_selected.go#L162-L164
train
emersion/go-imap
client/cmd_selected.go
UidFetch
func (c *Client) UidFetch(seqset *imap.SeqSet, items []imap.FetchItem, ch chan *imap.Message) error { return c.fetch(true, seqset, items, ch) }
go
func (c *Client) UidFetch(seqset *imap.SeqSet, items []imap.FetchItem, ch chan *imap.Message) error { return c.fetch(true, seqset, items, ch) }
[ "func", "(", "c", "*", "Client", ")", "UidFetch", "(", "seqset", "*", "imap", ".", "SeqSet", ",", "items", "[", "]", "imap", ".", "FetchItem", ",", "ch", "chan", "*", "imap", ".", "Message", ")", "error", "{", "return", "c", ".", "fetch", "(", "t...
// UidFetch is identical to Fetch, but seqset is interpreted as containing // unique identifiers instead of message sequence numbers.
[ "UidFetch", "is", "identical", "to", "Fetch", "but", "seqset", "is", "interpreted", "as", "containing", "unique", "identifiers", "instead", "of", "message", "sequence", "numbers", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_selected.go#L168-L170
train
emersion/go-imap
client/cmd_selected.go
Store
func (c *Client) Store(seqset *imap.SeqSet, item imap.StoreItem, value interface{}, ch chan *imap.Message) error { return c.store(false, seqset, item, value, ch) }
go
func (c *Client) Store(seqset *imap.SeqSet, item imap.StoreItem, value interface{}, ch chan *imap.Message) error { return c.store(false, seqset, item, value, ch) }
[ "func", "(", "c", "*", "Client", ")", "Store", "(", "seqset", "*", "imap", ".", "SeqSet", ",", "item", "imap", ".", "StoreItem", ",", "value", "interface", "{", "}", ",", "ch", "chan", "*", "imap", ".", "Message", ")", "error", "{", "return", "c", ...
// Store alters data associated with a message in the mailbox. If ch is not nil, // the updated value of the data will be sent to this channel. See RFC 3501 // section 6.4.6 for a list of items that can be updated.
[ "Store", "alters", "data", "associated", "with", "a", "message", "in", "the", "mailbox", ".", "If", "ch", "is", "not", "nil", "the", "updated", "value", "of", "the", "data", "will", "be", "sent", "to", "this", "channel", ".", "See", "RFC", "3501", "sec...
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_selected.go#L220-L222
train
emersion/go-imap
client/cmd_selected.go
UidStore
func (c *Client) UidStore(seqset *imap.SeqSet, item imap.StoreItem, value interface{}, ch chan *imap.Message) error { return c.store(true, seqset, item, value, ch) }
go
func (c *Client) UidStore(seqset *imap.SeqSet, item imap.StoreItem, value interface{}, ch chan *imap.Message) error { return c.store(true, seqset, item, value, ch) }
[ "func", "(", "c", "*", "Client", ")", "UidStore", "(", "seqset", "*", "imap", ".", "SeqSet", ",", "item", "imap", ".", "StoreItem", ",", "value", "interface", "{", "}", ",", "ch", "chan", "*", "imap", ".", "Message", ")", "error", "{", "return", "c...
// UidStore is identical to Store, but seqset is interpreted as containing // unique identifiers instead of message sequence numbers.
[ "UidStore", "is", "identical", "to", "Store", "but", "seqset", "is", "interpreted", "as", "containing", "unique", "identifiers", "instead", "of", "message", "sequence", "numbers", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_selected.go#L226-L228
train
emersion/go-imap
client/cmd_selected.go
UidCopy
func (c *Client) UidCopy(seqset *imap.SeqSet, dest string) error { return c.copy(true, seqset, dest) }
go
func (c *Client) UidCopy(seqset *imap.SeqSet, dest string) error { return c.copy(true, seqset, dest) }
[ "func", "(", "c", "*", "Client", ")", "UidCopy", "(", "seqset", "*", "imap", ".", "SeqSet", ",", "dest", "string", ")", "error", "{", "return", "c", ".", "copy", "(", "true", ",", "seqset", ",", "dest", ")", "\n", "}" ]
// UidCopy is identical to Copy, but seqset is interpreted as containing unique // identifiers instead of message sequence numbers.
[ "UidCopy", "is", "identical", "to", "Copy", "but", "seqset", "is", "interpreted", "as", "containing", "unique", "identifiers", "instead", "of", "message", "sequence", "numbers", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/client/cmd_selected.go#L258-L260
train
emersion/go-imap
conn.go
NewDebugWriter
func NewDebugWriter(local, remote io.Writer) io.Writer { return &debugWriter{Writer: local, local: local, remote: remote} }
go
func NewDebugWriter(local, remote io.Writer) io.Writer { return &debugWriter{Writer: local, local: local, remote: remote} }
[ "func", "NewDebugWriter", "(", "local", ",", "remote", "io", ".", "Writer", ")", "io", ".", "Writer", "{", "return", "&", "debugWriter", "{", "Writer", ":", "local", ",", "local", ":", "local", ",", "remote", ":", "remote", "}", "\n", "}" ]
// NewDebugWriter creates a new io.Writer that will write local network activity // to local and remote network activity to remote.
[ "NewDebugWriter", "creates", "a", "new", "io", ".", "Writer", "that", "will", "write", "local", "network", "activity", "to", "local", "and", "remote", "network", "activity", "to", "remote", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/conn.go#L117-L119
train
emersion/go-imap
conn.go
NewConn
func NewConn(conn net.Conn, r *Reader, w *Writer) *Conn { c := &Conn{Conn: conn, Reader: r, Writer: w} c.init() return c }
go
func NewConn(conn net.Conn, r *Reader, w *Writer) *Conn { c := &Conn{Conn: conn, Reader: r, Writer: w} c.init() return c }
[ "func", "NewConn", "(", "conn", "net", ".", "Conn", ",", "r", "*", "Reader", ",", "w", "*", "Writer", ")", "*", "Conn", "{", "c", ":=", "&", "Conn", "{", "Conn", ":", "conn", ",", "Reader", ":", "r", ",", "Writer", ":", "w", "}", "\n\n", "c",...
// NewConn creates a new IMAP connection.
[ "NewConn", "creates", "a", "new", "IMAP", "connection", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/conn.go#L154-L159
train
emersion/go-imap
seqset.go
Less
func (s Seq) Less(q uint32) bool { return (s.Stop < q || q == 0) && s.Stop != 0 }
go
func (s Seq) Less(q uint32) bool { return (s.Stop < q || q == 0) && s.Stop != 0 }
[ "func", "(", "s", "Seq", ")", "Less", "(", "q", "uint32", ")", "bool", "{", "return", "(", "s", ".", "Stop", "<", "q", "||", "q", "==", "0", ")", "&&", "s", ".", "Stop", "!=", "0", "\n", "}" ]
// Less returns true if s precedes and does not contain seq-number q.
[ "Less", "returns", "true", "if", "s", "precedes", "and", "does", "not", "contain", "seq", "-", "number", "q", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/seqset.go#L65-L67
train
emersion/go-imap
seqset.go
Merge
func (s Seq) Merge(t Seq) (union Seq, ok bool) { if union = s; s == t { ok = true return } if s.Start != 0 && t.Start != 0 { // s and t are any combination of "n", "n:m", or "n:*" if s.Start > t.Start { s, t = t, s } // s starts at or before t, check where it ends if (s.Stop >= t.Stop && t.Stop != 0) || s.Stop == 0 { return s, true // s is a superset of t } // s is "n" or "n:m", if m == ^uint32(0) then t is "n:*" if s.Stop+1 >= t.Start || s.Stop == ^uint32(0) { return Seq{s.Start, t.Stop}, true // s intersects or touches t } return } // exactly one of s and t is "*" if s.Start == 0 { if t.Stop == 0 { return t, true // s is "*", t is "n:*" } } else if s.Stop == 0 { return s, true // s is "n:*", t is "*" } return }
go
func (s Seq) Merge(t Seq) (union Seq, ok bool) { if union = s; s == t { ok = true return } if s.Start != 0 && t.Start != 0 { // s and t are any combination of "n", "n:m", or "n:*" if s.Start > t.Start { s, t = t, s } // s starts at or before t, check where it ends if (s.Stop >= t.Stop && t.Stop != 0) || s.Stop == 0 { return s, true // s is a superset of t } // s is "n" or "n:m", if m == ^uint32(0) then t is "n:*" if s.Stop+1 >= t.Start || s.Stop == ^uint32(0) { return Seq{s.Start, t.Stop}, true // s intersects or touches t } return } // exactly one of s and t is "*" if s.Start == 0 { if t.Stop == 0 { return t, true // s is "*", t is "n:*" } } else if s.Stop == 0 { return s, true // s is "n:*", t is "*" } return }
[ "func", "(", "s", "Seq", ")", "Merge", "(", "t", "Seq", ")", "(", "union", "Seq", ",", "ok", "bool", ")", "{", "if", "union", "=", "s", ";", "s", "==", "t", "{", "ok", "=", "true", "\n", "return", "\n", "}", "\n", "if", "s", ".", "Start", ...
// Merge combines sequence values s and t into a single union if the two // intersect or one is a superset of the other. The order of s and t does not // matter. If the values cannot be merged, s is returned unmodified and ok is // set to false.
[ "Merge", "combines", "sequence", "values", "s", "and", "t", "into", "a", "single", "union", "if", "the", "two", "intersect", "or", "one", "is", "a", "superset", "of", "the", "other", ".", "The", "order", "of", "s", "and", "t", "does", "not", "matter", ...
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/seqset.go#L73-L102
train
emersion/go-imap
seqset.go
String
func (s Seq) String() string { if s.Start == s.Stop { if s.Start == 0 { return "*" } return strconv.FormatUint(uint64(s.Start), 10) } b := strconv.AppendUint(make([]byte, 0, 24), uint64(s.Start), 10) if s.Stop == 0 { return string(append(b, ':', '*')) } return string(strconv.AppendUint(append(b, ':'), uint64(s.Stop), 10)) }
go
func (s Seq) String() string { if s.Start == s.Stop { if s.Start == 0 { return "*" } return strconv.FormatUint(uint64(s.Start), 10) } b := strconv.AppendUint(make([]byte, 0, 24), uint64(s.Start), 10) if s.Stop == 0 { return string(append(b, ':', '*')) } return string(strconv.AppendUint(append(b, ':'), uint64(s.Stop), 10)) }
[ "func", "(", "s", "Seq", ")", "String", "(", ")", "string", "{", "if", "s", ".", "Start", "==", "s", ".", "Stop", "{", "if", "s", ".", "Start", "==", "0", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "strconv", ".", "FormatUint", "(", ...
// String returns sequence value s as a seq-number or seq-range string.
[ "String", "returns", "sequence", "value", "s", "as", "a", "seq", "-", "number", "or", "seq", "-", "range", "string", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/seqset.go#L105-L117
train
emersion/go-imap
seqset.go
ParseSeqSet
func ParseSeqSet(set string) (s *SeqSet, err error) { s = new(SeqSet) return s, s.Add(set) }
go
func ParseSeqSet(set string) (s *SeqSet, err error) { s = new(SeqSet) return s, s.Add(set) }
[ "func", "ParseSeqSet", "(", "set", "string", ")", "(", "s", "*", "SeqSet", ",", "err", "error", ")", "{", "s", "=", "new", "(", "SeqSet", ")", "\n", "return", "s", ",", "s", ".", "Add", "(", "set", ")", "\n", "}" ]
// ParseSeqSet returns a new SeqSet instance after parsing the set string.
[ "ParseSeqSet", "returns", "a", "new", "SeqSet", "instance", "after", "parsing", "the", "set", "string", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/seqset.go#L126-L129
train
emersion/go-imap
seqset.go
Add
func (s *SeqSet) Add(set string) error { for _, sv := range strings.Split(set, ",") { v, err := parseSeq(sv) if err != nil { return err } s.insert(v) } return nil }
go
func (s *SeqSet) Add(set string) error { for _, sv := range strings.Split(set, ",") { v, err := parseSeq(sv) if err != nil { return err } s.insert(v) } return nil }
[ "func", "(", "s", "*", "SeqSet", ")", "Add", "(", "set", "string", ")", "error", "{", "for", "_", ",", "sv", ":=", "range", "strings", ".", "Split", "(", "set", ",", "\"", "\"", ")", "{", "v", ",", "err", ":=", "parseSeq", "(", "sv", ")", "\n...
// Add inserts new sequence values into the set. The string format is described // by RFC 3501 sequence-set ABNF rule. If an error is encountered, all values // inserted successfully prior to the error remain in the set.
[ "Add", "inserts", "new", "sequence", "values", "into", "the", "set", ".", "The", "string", "format", "is", "described", "by", "RFC", "3501", "sequence", "-", "set", "ABNF", "rule", ".", "If", "an", "error", "is", "encountered", "all", "values", "inserted",...
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/seqset.go#L134-L143
train
emersion/go-imap
seqset.go
AddRange
func (s *SeqSet) AddRange(Start, Stop uint32) { if (Stop < Start && Stop != 0) || Start == 0 { s.insert(Seq{Stop, Start}) } else { s.insert(Seq{Start, Stop}) } }
go
func (s *SeqSet) AddRange(Start, Stop uint32) { if (Stop < Start && Stop != 0) || Start == 0 { s.insert(Seq{Stop, Start}) } else { s.insert(Seq{Start, Stop}) } }
[ "func", "(", "s", "*", "SeqSet", ")", "AddRange", "(", "Start", ",", "Stop", "uint32", ")", "{", "if", "(", "Stop", "<", "Start", "&&", "Stop", "!=", "0", ")", "||", "Start", "==", "0", "{", "s", ".", "insert", "(", "Seq", "{", "Stop", ",", "...
// AddRange inserts a new sequence range into the set.
[ "AddRange", "inserts", "a", "new", "sequence", "range", "into", "the", "set", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/seqset.go#L153-L159
train
emersion/go-imap
seqset.go
AddSet
func (s *SeqSet) AddSet(t *SeqSet) { for _, v := range t.Set { s.insert(v) } }
go
func (s *SeqSet) AddSet(t *SeqSet) { for _, v := range t.Set { s.insert(v) } }
[ "func", "(", "s", "*", "SeqSet", ")", "AddSet", "(", "t", "*", "SeqSet", ")", "{", "for", "_", ",", "v", ":=", "range", "t", ".", "Set", "{", "s", ".", "insert", "(", "v", ")", "\n", "}", "\n", "}" ]
// AddSet inserts all values from t into s.
[ "AddSet", "inserts", "all", "values", "from", "t", "into", "s", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/seqset.go#L162-L166
train
emersion/go-imap
seqset.go
String
func (s SeqSet) String() string { if len(s.Set) == 0 { return "" } b := make([]byte, 0, 64) for _, v := range s.Set { b = append(b, ',') if v.Start == 0 { b = append(b, '*') continue } b = strconv.AppendUint(b, uint64(v.Start), 10) if v.Start != v.Stop { if v.Stop == 0 { b = append(b, ':', '*') continue } b = strconv.AppendUint(append(b, ':'), uint64(v.Stop), 10) } } return string(b[1:]) }
go
func (s SeqSet) String() string { if len(s.Set) == 0 { return "" } b := make([]byte, 0, 64) for _, v := range s.Set { b = append(b, ',') if v.Start == 0 { b = append(b, '*') continue } b = strconv.AppendUint(b, uint64(v.Start), 10) if v.Start != v.Stop { if v.Stop == 0 { b = append(b, ':', '*') continue } b = strconv.AppendUint(append(b, ':'), uint64(v.Stop), 10) } } return string(b[1:]) }
[ "func", "(", "s", "SeqSet", ")", "String", "(", ")", "string", "{", "if", "len", "(", "s", ".", "Set", ")", "==", "0", "{", "return", "\"", "\"", "\n", "}", "\n", "b", ":=", "make", "(", "[", "]", "byte", ",", "0", ",", "64", ")", "\n", "...
// String returns a sorted representation of all contained sequence values.
[ "String", "returns", "a", "sorted", "representation", "of", "all", "contained", "sequence", "values", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/seqset.go#L196-L217
train
emersion/go-imap
seqset.go
insert
func (s *SeqSet) insert(v Seq) { i, _ := s.search(v.Start) merged := false if i > 0 { // try merging with the preceding entry (e.g. "1,4".insert(2), i == 1) s.Set[i-1], merged = s.Set[i-1].Merge(v) } if i == len(s.Set) { // v was either merged with the last entry or needs to be appended if !merged { s.insertAt(i, v) } return } else if merged { i-- } else if s.Set[i], merged = s.Set[i].Merge(v); !merged { s.insertAt(i, v) // insert in the middle (e.g. "1,5".insert(3), i == 1) return } // v was merged with s.Set[i], continue trying to merge until the end for j := i + 1; j < len(s.Set); j++ { if s.Set[i], merged = s.Set[i].Merge(s.Set[j]); !merged { if j > i+1 { // cut out all entries between i and j that were merged s.Set = append(s.Set[:i+1], s.Set[j:]...) } return } } // everything after s.Set[i] was merged s.Set = s.Set[:i+1] }
go
func (s *SeqSet) insert(v Seq) { i, _ := s.search(v.Start) merged := false if i > 0 { // try merging with the preceding entry (e.g. "1,4".insert(2), i == 1) s.Set[i-1], merged = s.Set[i-1].Merge(v) } if i == len(s.Set) { // v was either merged with the last entry or needs to be appended if !merged { s.insertAt(i, v) } return } else if merged { i-- } else if s.Set[i], merged = s.Set[i].Merge(v); !merged { s.insertAt(i, v) // insert in the middle (e.g. "1,5".insert(3), i == 1) return } // v was merged with s.Set[i], continue trying to merge until the end for j := i + 1; j < len(s.Set); j++ { if s.Set[i], merged = s.Set[i].Merge(s.Set[j]); !merged { if j > i+1 { // cut out all entries between i and j that were merged s.Set = append(s.Set[:i+1], s.Set[j:]...) } return } } // everything after s.Set[i] was merged s.Set = s.Set[:i+1] }
[ "func", "(", "s", "*", "SeqSet", ")", "insert", "(", "v", "Seq", ")", "{", "i", ",", "_", ":=", "s", ".", "search", "(", "v", ".", "Start", ")", "\n", "merged", ":=", "false", "\n", "if", "i", ">", "0", "{", "// try merging with the preceding entry...
// insert adds sequence value v to the set.
[ "insert", "adds", "sequence", "value", "v", "to", "the", "set", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/seqset.go#L220-L251
train
emersion/go-imap
seqset.go
insertAt
func (s *SeqSet) insertAt(i int, v Seq) { if n := len(s.Set); i == n { // insert at the end s.Set = append(s.Set, v) return } else if n < cap(s.Set) { // enough space, shift everything at and after i to the right s.Set = s.Set[:n+1] copy(s.Set[i+1:], s.Set[i:]) } else { // allocate new slice and copy everything, n is at least 1 set := make([]Seq, n+1, n*2) copy(set, s.Set[:i]) copy(set[i+1:], s.Set[i:]) s.Set = set } s.Set[i] = v }
go
func (s *SeqSet) insertAt(i int, v Seq) { if n := len(s.Set); i == n { // insert at the end s.Set = append(s.Set, v) return } else if n < cap(s.Set) { // enough space, shift everything at and after i to the right s.Set = s.Set[:n+1] copy(s.Set[i+1:], s.Set[i:]) } else { // allocate new slice and copy everything, n is at least 1 set := make([]Seq, n+1, n*2) copy(set, s.Set[:i]) copy(set[i+1:], s.Set[i:]) s.Set = set } s.Set[i] = v }
[ "func", "(", "s", "*", "SeqSet", ")", "insertAt", "(", "i", "int", ",", "v", "Seq", ")", "{", "if", "n", ":=", "len", "(", "s", ".", "Set", ")", ";", "i", "==", "n", "{", "// insert at the end", "s", ".", "Set", "=", "append", "(", "s", ".", ...
// insertAt inserts a new sequence value v at index i, resizing s.Set as needed.
[ "insertAt", "inserts", "a", "new", "sequence", "value", "v", "at", "index", "i", "resizing", "s", ".", "Set", "as", "needed", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/seqset.go#L254-L271
train
emersion/go-imap
seqset.go
search
func (s SeqSet) search(q uint32) (i int, ok bool) { min, max := 0, len(s.Set)-1 for min < max { if mid := (min + max) >> 1; s.Set[mid].Less(q) { min = mid + 1 } else { max = mid } } if max < 0 || s.Set[min].Less(q) { return len(s.Set), false // q is the new largest value } return min, s.Set[min].Contains(q) }
go
func (s SeqSet) search(q uint32) (i int, ok bool) { min, max := 0, len(s.Set)-1 for min < max { if mid := (min + max) >> 1; s.Set[mid].Less(q) { min = mid + 1 } else { max = mid } } if max < 0 || s.Set[min].Less(q) { return len(s.Set), false // q is the new largest value } return min, s.Set[min].Contains(q) }
[ "func", "(", "s", "SeqSet", ")", "search", "(", "q", "uint32", ")", "(", "i", "int", ",", "ok", "bool", ")", "{", "min", ",", "max", ":=", "0", ",", "len", "(", "s", ".", "Set", ")", "-", "1", "\n", "for", "min", "<", "max", "{", "if", "m...
// search attempts to find the index of the sequence set value that contains q. // If no values contain q, the returned index is the position where q should be // inserted and ok is set to false.
[ "search", "attempts", "to", "find", "the", "index", "of", "the", "sequence", "set", "value", "that", "contains", "q", ".", "If", "no", "values", "contain", "q", "the", "returned", "index", "is", "the", "position", "where", "q", "should", "be", "inserted", ...
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/seqset.go#L276-L289
train
emersion/go-imap
status.go
Err
func (r *StatusResp) Err() error { if r == nil { // No status response, connection closed before we get one return errors.New("imap: connection closed during command execution") } if r.Type == StatusRespNo || r.Type == StatusRespBad { return errors.New(r.Info) } return nil }
go
func (r *StatusResp) Err() error { if r == nil { // No status response, connection closed before we get one return errors.New("imap: connection closed during command execution") } if r.Type == StatusRespNo || r.Type == StatusRespBad { return errors.New(r.Info) } return nil }
[ "func", "(", "r", "*", "StatusResp", ")", "Err", "(", ")", "error", "{", "if", "r", "==", "nil", "{", "// No status response, connection closed before we get one", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "r", ".", "...
// If this status is NO or BAD, returns an error with the status info. // Otherwise, returns nil.
[ "If", "this", "status", "is", "NO", "or", "BAD", "returns", "an", "error", "with", "the", "status", "info", ".", "Otherwise", "returns", "nil", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/status.go#L79-L89
train
emersion/go-imap
utf7/encoder.go
encode
func encode(s []byte) []byte { // len(s) is sufficient for UTF-8 to UTF-16 conversion if there are no // control code points (see table below). b := make([]byte, 0, len(s)+4) for len(s) > 0 { r, size := utf8.DecodeRune(s) if r > utf8.MaxRune { r, size = utf8.RuneError, 1 // Bug fix (issue 3785) } s = s[size:] if r1, r2 := utf16.EncodeRune(r); r1 != repl { b = append(b, byte(r1>>8), byte(r1)) r = r2 } b = append(b, byte(r>>8), byte(r)) } // Encode as base64 n := b64Enc.EncodedLen(len(b)) + 2 b64 := make([]byte, n) b64Enc.Encode(b64[1:], b) // Strip padding n -= 2 - (len(b)+2)%3 b64 = b64[:n] // Add UTF-7 shifts b64[0] = '&' b64[n-1] = '-' return b64 }
go
func encode(s []byte) []byte { // len(s) is sufficient for UTF-8 to UTF-16 conversion if there are no // control code points (see table below). b := make([]byte, 0, len(s)+4) for len(s) > 0 { r, size := utf8.DecodeRune(s) if r > utf8.MaxRune { r, size = utf8.RuneError, 1 // Bug fix (issue 3785) } s = s[size:] if r1, r2 := utf16.EncodeRune(r); r1 != repl { b = append(b, byte(r1>>8), byte(r1)) r = r2 } b = append(b, byte(r>>8), byte(r)) } // Encode as base64 n := b64Enc.EncodedLen(len(b)) + 2 b64 := make([]byte, n) b64Enc.Encode(b64[1:], b) // Strip padding n -= 2 - (len(b)+2)%3 b64 = b64[:n] // Add UTF-7 shifts b64[0] = '&' b64[n-1] = '-' return b64 }
[ "func", "encode", "(", "s", "[", "]", "byte", ")", "[", "]", "byte", "{", "// len(s) is sufficient for UTF-8 to UTF-16 conversion if there are no", "// control code points (see table below).", "b", ":=", "make", "(", "[", "]", "byte", ",", "0", ",", "len", "(", "s...
// Converts string s from UTF-8 to UTF-16-BE, encodes the result as base64, // removes the padding, and adds UTF-7 shifts.
[ "Converts", "string", "s", "from", "UTF", "-", "8", "to", "UTF", "-", "16", "-", "BE", "encodes", "the", "result", "as", "base64", "removes", "the", "padding", "and", "adds", "UTF", "-", "7", "shifts", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/utf7/encoder.go#L61-L91
train
emersion/go-imap
response.go
ReadResp
func ReadResp(r *Reader) (Resp, error) { atom, err := r.ReadAtom() if err != nil { return nil, err } tag, ok := atom.(string) if !ok { return nil, newParseError("response tag is not an atom") } if tag == "+" { if err := r.ReadSp(); err != nil { r.UnreadRune() } resp := &ContinuationReq{} resp.Info, err = r.ReadInfo() if err != nil { return nil, err } return resp, nil } if err := r.ReadSp(); err != nil { return nil, err } // Can be either data or status // Try to parse a status var fields []interface{} if atom, err := r.ReadAtom(); err == nil { fields = append(fields, atom) if err := r.ReadSp(); err == nil { if name, ok := atom.(string); ok { status := StatusRespType(name) switch status { case StatusRespOk, StatusRespNo, StatusRespBad, StatusRespPreauth, StatusRespBye: resp := &StatusResp{ Tag: tag, Type: status, } char, _, err := r.ReadRune() if err != nil { return nil, err } r.UnreadRune() if char == '[' { // Contains code & arguments resp.Code, resp.Arguments, err = r.ReadRespCode() if err != nil { return nil, err } } resp.Info, err = r.ReadInfo() if err != nil { return nil, err } return resp, nil } } } else { r.UnreadRune() } } else { r.UnreadRune() } // Not a status so it's data resp := &DataResp{Tag: tag} var remaining []interface{} remaining, err = r.ReadLine() if err != nil { return nil, err } resp.Fields = append(fields, remaining...) return resp, nil }
go
func ReadResp(r *Reader) (Resp, error) { atom, err := r.ReadAtom() if err != nil { return nil, err } tag, ok := atom.(string) if !ok { return nil, newParseError("response tag is not an atom") } if tag == "+" { if err := r.ReadSp(); err != nil { r.UnreadRune() } resp := &ContinuationReq{} resp.Info, err = r.ReadInfo() if err != nil { return nil, err } return resp, nil } if err := r.ReadSp(); err != nil { return nil, err } // Can be either data or status // Try to parse a status var fields []interface{} if atom, err := r.ReadAtom(); err == nil { fields = append(fields, atom) if err := r.ReadSp(); err == nil { if name, ok := atom.(string); ok { status := StatusRespType(name) switch status { case StatusRespOk, StatusRespNo, StatusRespBad, StatusRespPreauth, StatusRespBye: resp := &StatusResp{ Tag: tag, Type: status, } char, _, err := r.ReadRune() if err != nil { return nil, err } r.UnreadRune() if char == '[' { // Contains code & arguments resp.Code, resp.Arguments, err = r.ReadRespCode() if err != nil { return nil, err } } resp.Info, err = r.ReadInfo() if err != nil { return nil, err } return resp, nil } } } else { r.UnreadRune() } } else { r.UnreadRune() } // Not a status so it's data resp := &DataResp{Tag: tag} var remaining []interface{} remaining, err = r.ReadLine() if err != nil { return nil, err } resp.Fields = append(fields, remaining...) return resp, nil }
[ "func", "ReadResp", "(", "r", "*", "Reader", ")", "(", "Resp", ",", "error", ")", "{", "atom", ",", "err", ":=", "r", ".", "ReadAtom", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "tag", ",", "o...
// ReadResp reads a single response from a Reader.
[ "ReadResp", "reads", "a", "single", "response", "from", "a", "Reader", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/response.go#L14-L98
train
emersion/go-imap
response.go
ParseNamedResp
func ParseNamedResp(resp Resp) (name string, fields []interface{}, ok bool) { data, ok := resp.(*DataResp) if !ok || len(data.Fields) == 0 { return } // Some responses (namely EXISTS and RECENT) are formatted like so: // [num] [name] [...] // Which is fucking stupid. But we handle that here by checking if the // response name is a number and then rearranging it. if len(data.Fields) > 1 { name, ok := data.Fields[1].(string) if ok { if _, err := ParseNumber(data.Fields[0]); err == nil { fields := []interface{}{data.Fields[0]} fields = append(fields, data.Fields[2:]...) return strings.ToUpper(name), fields, true } } } // IMAP commands are formatted like this: // [name] [...] name, ok = data.Fields[0].(string) if !ok { return } return strings.ToUpper(name), data.Fields[1:], true }
go
func ParseNamedResp(resp Resp) (name string, fields []interface{}, ok bool) { data, ok := resp.(*DataResp) if !ok || len(data.Fields) == 0 { return } // Some responses (namely EXISTS and RECENT) are formatted like so: // [num] [name] [...] // Which is fucking stupid. But we handle that here by checking if the // response name is a number and then rearranging it. if len(data.Fields) > 1 { name, ok := data.Fields[1].(string) if ok { if _, err := ParseNumber(data.Fields[0]); err == nil { fields := []interface{}{data.Fields[0]} fields = append(fields, data.Fields[2:]...) return strings.ToUpper(name), fields, true } } } // IMAP commands are formatted like this: // [name] [...] name, ok = data.Fields[0].(string) if !ok { return } return strings.ToUpper(name), data.Fields[1:], true }
[ "func", "ParseNamedResp", "(", "resp", "Resp", ")", "(", "name", "string", ",", "fields", "[", "]", "interface", "{", "}", ",", "ok", "bool", ")", "{", "data", ",", "ok", ":=", "resp", ".", "(", "*", "DataResp", ")", "\n", "if", "!", "ok", "||", ...
// ParseNamedResp attempts to parse a named data response.
[ "ParseNamedResp", "attempts", "to", "parse", "a", "named", "data", "response", "." ]
b7db4a2bc5cc04fb568fb036a438da43ee9a9f78
https://github.com/emersion/go-imap/blob/b7db4a2bc5cc04fb568fb036a438da43ee9a9f78/response.go#L153-L181
train