id int32 0 167k | 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
127,200 | grpc/grpc-go | examples/route_guide/client/client.go | runRouteChat | func runRouteChat(client pb.RouteGuideClient) {
notes := []*pb.RouteNote{
{Location: &pb.Point{Latitude: 0, Longitude: 1}, Message: "First message"},
{Location: &pb.Point{Latitude: 0, Longitude: 2}, Message: "Second message"},
{Location: &pb.Point{Latitude: 0, Longitude: 3}, Message: "Third message"},
{Locatio... | go | func runRouteChat(client pb.RouteGuideClient) {
notes := []*pb.RouteNote{
{Location: &pb.Point{Latitude: 0, Longitude: 1}, Message: "First message"},
{Location: &pb.Point{Latitude: 0, Longitude: 2}, Message: "Second message"},
{Location: &pb.Point{Latitude: 0, Longitude: 3}, Message: "Third message"},
{Locatio... | [
"func",
"runRouteChat",
"(",
"client",
"pb",
".",
"RouteGuideClient",
")",
"{",
"notes",
":=",
"[",
"]",
"*",
"pb",
".",
"RouteNote",
"{",
"{",
"Location",
":",
"&",
"pb",
".",
"Point",
"{",
"Latitude",
":",
"0",
",",
"Longitude",
":",
"1",
"}",
",... | // runRouteChat receives a sequence of route notes, while sending notes for various locations. | [
"runRouteChat",
"receives",
"a",
"sequence",
"of",
"route",
"notes",
"while",
"sending",
"notes",
"for",
"various",
"locations",
"."
] | 028242f87445bf2cc2807399d403cbbada8c0e85 | https://github.com/grpc/grpc-go/blob/028242f87445bf2cc2807399d403cbbada8c0e85/examples/route_guide/client/client.go#L108-L145 |
127,201 | grpc/grpc-go | benchmark/worker/benchmark_server.go | getStats | func (bs *benchmarkServer) getStats(reset bool) *testpb.ServerStats {
bs.mu.RLock()
defer bs.mu.RUnlock()
wallTimeElapsed := time.Since(bs.lastResetTime).Seconds()
rusageLatest := syscall.GetRusage()
uTimeElapsed, sTimeElapsed := syscall.CPUTimeDiff(bs.rusageLastReset, rusageLatest)
if reset {
bs.lastResetTime... | go | func (bs *benchmarkServer) getStats(reset bool) *testpb.ServerStats {
bs.mu.RLock()
defer bs.mu.RUnlock()
wallTimeElapsed := time.Since(bs.lastResetTime).Seconds()
rusageLatest := syscall.GetRusage()
uTimeElapsed, sTimeElapsed := syscall.CPUTimeDiff(bs.rusageLastReset, rusageLatest)
if reset {
bs.lastResetTime... | [
"func",
"(",
"bs",
"*",
"benchmarkServer",
")",
"getStats",
"(",
"reset",
"bool",
")",
"*",
"testpb",
".",
"ServerStats",
"{",
"bs",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"bs",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"wallTimeElapsed",... | // getStats returns the stats for benchmark server.
// It resets lastResetTime if argument reset is true. | [
"getStats",
"returns",
"the",
"stats",
"for",
"benchmark",
"server",
".",
"It",
"resets",
"lastResetTime",
"if",
"argument",
"reset",
"is",
"true",
"."
] | 028242f87445bf2cc2807399d403cbbada8c0e85 | https://github.com/grpc/grpc-go/blob/028242f87445bf2cc2807399d403cbbada8c0e85/benchmark/worker/benchmark_server.go#L168-L184 |
127,202 | grpc/grpc-go | internal/transport/controlbuf.go | dequeue | func (l *outStreamList) dequeue() *outStream {
b := l.head.next
if b == l.tail {
return nil
}
b.deleteSelf()
return b
} | go | func (l *outStreamList) dequeue() *outStream {
b := l.head.next
if b == l.tail {
return nil
}
b.deleteSelf()
return b
} | [
"func",
"(",
"l",
"*",
"outStreamList",
")",
"dequeue",
"(",
")",
"*",
"outStream",
"{",
"b",
":=",
"l",
".",
"head",
".",
"next",
"\n",
"if",
"b",
"==",
"l",
".",
"tail",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"b",
".",
"deleteSelf",
"(",
")",... | // remove from the beginning of the list. | [
"remove",
"from",
"the",
"beginning",
"of",
"the",
"list",
"."
] | 028242f87445bf2cc2807399d403cbbada8c0e85 | https://github.com/grpc/grpc-go/blob/028242f87445bf2cc2807399d403cbbada8c0e85/internal/transport/controlbuf.go#L219-L226 |
127,203 | grpc/grpc-go | internal/transport/controlbuf.go | execute | func (c *controlBuffer) execute(f func(it interface{}) bool, it interface{}) (bool, error) {
c.mu.Lock()
if c.err != nil {
c.mu.Unlock()
return false, c.err
}
if !f(it) { // f wasn't successful
c.mu.Unlock()
return false, nil
}
c.mu.Unlock()
return true, nil
} | go | func (c *controlBuffer) execute(f func(it interface{}) bool, it interface{}) (bool, error) {
c.mu.Lock()
if c.err != nil {
c.mu.Unlock()
return false, c.err
}
if !f(it) { // f wasn't successful
c.mu.Unlock()
return false, nil
}
c.mu.Unlock()
return true, nil
} | [
"func",
"(",
"c",
"*",
"controlBuffer",
")",
"execute",
"(",
"f",
"func",
"(",
"it",
"interface",
"{",
"}",
")",
"bool",
",",
"it",
"interface",
"{",
"}",
")",
"(",
"bool",
",",
"error",
")",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
... | // Note argument f should never be nil. | [
"Note",
"argument",
"f",
"should",
"never",
"be",
"nil",
"."
] | 028242f87445bf2cc2807399d403cbbada8c0e85 | https://github.com/grpc/grpc-go/blob/028242f87445bf2cc2807399d403cbbada8c0e85/internal/transport/controlbuf.go#L285-L297 |
127,204 | grpc/grpc-go | resolver_conn_wrapper.go | NewAddress | func (ccr *ccResolverWrapper) NewAddress(addrs []resolver.Address) {
if ccr.isDone() {
return
}
grpclog.Infof("ccResolverWrapper: sending new addresses to cc: %v", addrs)
if channelz.IsOn() {
ccr.addChannelzTraceEvent(resolver.State{Addresses: addrs, ServiceConfig: ccr.curState.ServiceConfig})
}
ccr.curState.... | go | func (ccr *ccResolverWrapper) NewAddress(addrs []resolver.Address) {
if ccr.isDone() {
return
}
grpclog.Infof("ccResolverWrapper: sending new addresses to cc: %v", addrs)
if channelz.IsOn() {
ccr.addChannelzTraceEvent(resolver.State{Addresses: addrs, ServiceConfig: ccr.curState.ServiceConfig})
}
ccr.curState.... | [
"func",
"(",
"ccr",
"*",
"ccResolverWrapper",
")",
"NewAddress",
"(",
"addrs",
"[",
"]",
"resolver",
".",
"Address",
")",
"{",
"if",
"ccr",
".",
"isDone",
"(",
")",
"{",
"return",
"\n",
"}",
"\n",
"grpclog",
".",
"Infof",
"(",
"\"",
"\"",
",",
"add... | // NewAddress is called by the resolver implementation to send addresses to gRPC. | [
"NewAddress",
"is",
"called",
"by",
"the",
"resolver",
"implementation",
"to",
"send",
"addresses",
"to",
"gRPC",
"."
] | 028242f87445bf2cc2807399d403cbbada8c0e85 | https://github.com/grpc/grpc-go/blob/028242f87445bf2cc2807399d403cbbada8c0e85/resolver_conn_wrapper.go#L122-L132 |
127,205 | grpc/grpc-go | resolver_conn_wrapper.go | NewServiceConfig | func (ccr *ccResolverWrapper) NewServiceConfig(sc string) {
if ccr.isDone() {
return
}
grpclog.Infof("ccResolverWrapper: got new service config: %v", sc)
if channelz.IsOn() {
ccr.addChannelzTraceEvent(resolver.State{Addresses: ccr.curState.Addresses, ServiceConfig: sc})
}
ccr.curState.ServiceConfig = sc
ccr.... | go | func (ccr *ccResolverWrapper) NewServiceConfig(sc string) {
if ccr.isDone() {
return
}
grpclog.Infof("ccResolverWrapper: got new service config: %v", sc)
if channelz.IsOn() {
ccr.addChannelzTraceEvent(resolver.State{Addresses: ccr.curState.Addresses, ServiceConfig: sc})
}
ccr.curState.ServiceConfig = sc
ccr.... | [
"func",
"(",
"ccr",
"*",
"ccResolverWrapper",
")",
"NewServiceConfig",
"(",
"sc",
"string",
")",
"{",
"if",
"ccr",
".",
"isDone",
"(",
")",
"{",
"return",
"\n",
"}",
"\n",
"grpclog",
".",
"Infof",
"(",
"\"",
"\"",
",",
"sc",
")",
"\n",
"if",
"chann... | // NewServiceConfig is called by the resolver implementation to send service
// configs to gRPC. | [
"NewServiceConfig",
"is",
"called",
"by",
"the",
"resolver",
"implementation",
"to",
"send",
"service",
"configs",
"to",
"gRPC",
"."
] | 028242f87445bf2cc2807399d403cbbada8c0e85 | https://github.com/grpc/grpc-go/blob/028242f87445bf2cc2807399d403cbbada8c0e85/resolver_conn_wrapper.go#L136-L146 |
127,206 | grpc/grpc-go | grpclog/loggerv2.go | NewLoggerV2WithVerbosity | func NewLoggerV2WithVerbosity(infoW, warningW, errorW io.Writer, v int) LoggerV2 {
var m []*log.Logger
m = append(m, log.New(infoW, severityName[infoLog]+": ", log.LstdFlags))
m = append(m, log.New(io.MultiWriter(infoW, warningW), severityName[warningLog]+": ", log.LstdFlags))
ew := io.MultiWriter(infoW, warningW, ... | go | func NewLoggerV2WithVerbosity(infoW, warningW, errorW io.Writer, v int) LoggerV2 {
var m []*log.Logger
m = append(m, log.New(infoW, severityName[infoLog]+": ", log.LstdFlags))
m = append(m, log.New(io.MultiWriter(infoW, warningW), severityName[warningLog]+": ", log.LstdFlags))
ew := io.MultiWriter(infoW, warningW, ... | [
"func",
"NewLoggerV2WithVerbosity",
"(",
"infoW",
",",
"warningW",
",",
"errorW",
"io",
".",
"Writer",
",",
"v",
"int",
")",
"LoggerV2",
"{",
"var",
"m",
"[",
"]",
"*",
"log",
".",
"Logger",
"\n",
"m",
"=",
"append",
"(",
"m",
",",
"log",
".",
"New... | // NewLoggerV2WithVerbosity creates a loggerV2 with the provided writers and
// verbosity level. | [
"NewLoggerV2WithVerbosity",
"creates",
"a",
"loggerV2",
"with",
"the",
"provided",
"writers",
"and",
"verbosity",
"level",
"."
] | 028242f87445bf2cc2807399d403cbbada8c0e85 | https://github.com/grpc/grpc-go/blob/028242f87445bf2cc2807399d403cbbada8c0e85/grpclog/loggerv2.go#L107-L115 |
127,207 | grpc/grpc-go | grpclog/loggerv2.go | newLoggerV2 | func newLoggerV2() LoggerV2 {
errorW := ioutil.Discard
warningW := ioutil.Discard
infoW := ioutil.Discard
logLevel := os.Getenv("GRPC_GO_LOG_SEVERITY_LEVEL")
switch logLevel {
case "", "ERROR", "error": // If env is unset, set level to ERROR.
errorW = os.Stderr
case "WARNING", "warning":
warningW = os.Stder... | go | func newLoggerV2() LoggerV2 {
errorW := ioutil.Discard
warningW := ioutil.Discard
infoW := ioutil.Discard
logLevel := os.Getenv("GRPC_GO_LOG_SEVERITY_LEVEL")
switch logLevel {
case "", "ERROR", "error": // If env is unset, set level to ERROR.
errorW = os.Stderr
case "WARNING", "warning":
warningW = os.Stder... | [
"func",
"newLoggerV2",
"(",
")",
"LoggerV2",
"{",
"errorW",
":=",
"ioutil",
".",
"Discard",
"\n",
"warningW",
":=",
"ioutil",
".",
"Discard",
"\n",
"infoW",
":=",
"ioutil",
".",
"Discard",
"\n\n",
"logLevel",
":=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
... | // newLoggerV2 creates a loggerV2 to be used as default logger.
// All logs are written to stderr. | [
"newLoggerV2",
"creates",
"a",
"loggerV2",
"to",
"be",
"used",
"as",
"default",
"logger",
".",
"All",
"logs",
"are",
"written",
"to",
"stderr",
"."
] | 028242f87445bf2cc2807399d403cbbada8c0e85 | https://github.com/grpc/grpc-go/blob/028242f87445bf2cc2807399d403cbbada8c0e85/grpclog/loggerv2.go#L119-L140 |
127,208 | grpc/grpc-go | internal/binarylog/env_config.go | fillMethodLoggerWithConfigString | func (l *logger) fillMethodLoggerWithConfigString(config string) error {
// "" is invalid.
if config == "" {
return errors.New("empty string is not a valid method binary logging config")
}
// "-service/method", blacklist, no * or {} allowed.
if config[0] == '-' {
s, m, suffix, err := parseMethodConfigAndSuffi... | go | func (l *logger) fillMethodLoggerWithConfigString(config string) error {
// "" is invalid.
if config == "" {
return errors.New("empty string is not a valid method binary logging config")
}
// "-service/method", blacklist, no * or {} allowed.
if config[0] == '-' {
s, m, suffix, err := parseMethodConfigAndSuffi... | [
"func",
"(",
"l",
"*",
"logger",
")",
"fillMethodLoggerWithConfigString",
"(",
"config",
"string",
")",
"error",
"{",
"// \"\" is invalid.",
"if",
"config",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"... | // fillMethodLoggerWithConfigString parses config, creates methodLogger and adds
// it to the right map in the logger. | [
"fillMethodLoggerWithConfigString",
"parses",
"config",
"creates",
"methodLogger",
"and",
"adds",
"it",
"to",
"the",
"right",
"map",
"in",
"the",
"logger",
"."
] | 028242f87445bf2cc2807399d403cbbada8c0e85 | https://github.com/grpc/grpc-go/blob/028242f87445bf2cc2807399d403cbbada8c0e85/internal/binarylog/env_config.go#L64-L118 |
127,209 | grpc/grpc-go | benchmark/stats/histogram.go | NewHistogram | func NewHistogram(opts HistogramOptions) *Histogram {
if opts.NumBuckets == 0 {
opts.NumBuckets = 32
}
if opts.BaseBucketSize == 0.0 {
opts.BaseBucketSize = 1.0
}
h := Histogram{
Buckets: make([]HistogramBucket, opts.NumBuckets),
Min: math.MaxInt64,
Max: math.MinInt64,
opts: ... | go | func NewHistogram(opts HistogramOptions) *Histogram {
if opts.NumBuckets == 0 {
opts.NumBuckets = 32
}
if opts.BaseBucketSize == 0.0 {
opts.BaseBucketSize = 1.0
}
h := Histogram{
Buckets: make([]HistogramBucket, opts.NumBuckets),
Min: math.MaxInt64,
Max: math.MinInt64,
opts: ... | [
"func",
"NewHistogram",
"(",
"opts",
"HistogramOptions",
")",
"*",
"Histogram",
"{",
"if",
"opts",
".",
"NumBuckets",
"==",
"0",
"{",
"opts",
".",
"NumBuckets",
"=",
"32",
"\n",
"}",
"\n",
"if",
"opts",
".",
"BaseBucketSize",
"==",
"0.0",
"{",
"opts",
... | // NewHistogram returns a pointer to a new Histogram object that was created
// with the provided options. | [
"NewHistogram",
"returns",
"a",
"pointer",
"to",
"a",
"new",
"Histogram",
"object",
"that",
"was",
"created",
"with",
"the",
"provided",
"options",
"."
] | 028242f87445bf2cc2807399d403cbbada8c0e85 | https://github.com/grpc/grpc-go/blob/028242f87445bf2cc2807399d403cbbada8c0e85/benchmark/stats/histogram.go#L79-L103 |
127,210 | grpc/grpc-go | benchmark/stats/histogram.go | PrintWithUnit | func (h *Histogram) PrintWithUnit(w io.Writer, unit float64) {
avg := float64(h.Sum) / float64(h.Count)
fmt.Fprintf(w, "Count: %d Min: %5.1f Max: %5.1f Avg: %.2f\n", h.Count, float64(h.Min)/unit, float64(h.Max)/unit, avg/unit)
fmt.Fprintf(w, "%s\n", strings.Repeat("-", 60))
if h.Count <= 0 {
return
}
maxBuc... | go | func (h *Histogram) PrintWithUnit(w io.Writer, unit float64) {
avg := float64(h.Sum) / float64(h.Count)
fmt.Fprintf(w, "Count: %d Min: %5.1f Max: %5.1f Avg: %.2f\n", h.Count, float64(h.Min)/unit, float64(h.Max)/unit, avg/unit)
fmt.Fprintf(w, "%s\n", strings.Repeat("-", 60))
if h.Count <= 0 {
return
}
maxBuc... | [
"func",
"(",
"h",
"*",
"Histogram",
")",
"PrintWithUnit",
"(",
"w",
"io",
".",
"Writer",
",",
"unit",
"float64",
")",
"{",
"avg",
":=",
"float64",
"(",
"h",
".",
"Sum",
")",
"/",
"float64",
"(",
"h",
".",
"Count",
")",
"\n",
"fmt",
".",
"Fprintf"... | // PrintWithUnit writes textual output of the histogram values .
// Data in histogram is divided by a Unit before print. | [
"PrintWithUnit",
"writes",
"textual",
"output",
"of",
"the",
"histogram",
"values",
".",
"Data",
"in",
"histogram",
"is",
"divided",
"by",
"a",
"Unit",
"before",
"print",
"."
] | 028242f87445bf2cc2807399d403cbbada8c0e85 | https://github.com/grpc/grpc-go/blob/028242f87445bf2cc2807399d403cbbada8c0e85/benchmark/stats/histogram.go#L112-L144 |
127,211 | grpc/grpc-go | benchmark/stats/histogram.go | String | func (h *Histogram) String() string {
var b bytes.Buffer
h.Print(&b)
return b.String()
} | go | func (h *Histogram) String() string {
var b bytes.Buffer
h.Print(&b)
return b.String()
} | [
"func",
"(",
"h",
"*",
"Histogram",
")",
"String",
"(",
")",
"string",
"{",
"var",
"b",
"bytes",
".",
"Buffer",
"\n",
"h",
".",
"Print",
"(",
"&",
"b",
")",
"\n",
"return",
"b",
".",
"String",
"(",
")",
"\n",
"}"
] | // String returns the textual output of the histogram values as string. | [
"String",
"returns",
"the",
"textual",
"output",
"of",
"the",
"histogram",
"values",
"as",
"string",
"."
] | 028242f87445bf2cc2807399d403cbbada8c0e85 | https://github.com/grpc/grpc-go/blob/028242f87445bf2cc2807399d403cbbada8c0e85/benchmark/stats/histogram.go#L147-L151 |
127,212 | grpc/grpc-go | benchmark/stats/histogram.go | Clear | func (h *Histogram) Clear() {
h.Count = 0
h.Sum = 0
h.SumOfSquares = 0
h.Min = math.MaxInt64
h.Max = math.MinInt64
for i := range h.Buckets {
h.Buckets[i].Count = 0
}
} | go | func (h *Histogram) Clear() {
h.Count = 0
h.Sum = 0
h.SumOfSquares = 0
h.Min = math.MaxInt64
h.Max = math.MinInt64
for i := range h.Buckets {
h.Buckets[i].Count = 0
}
} | [
"func",
"(",
"h",
"*",
"Histogram",
")",
"Clear",
"(",
")",
"{",
"h",
".",
"Count",
"=",
"0",
"\n",
"h",
".",
"Sum",
"=",
"0",
"\n",
"h",
".",
"SumOfSquares",
"=",
"0",
"\n",
"h",
".",
"Min",
"=",
"math",
".",
"MaxInt64",
"\n",
"h",
".",
"M... | // Clear resets all the content of histogram. | [
"Clear",
"resets",
"all",
"the",
"content",
"of",
"histogram",
"."
] | 028242f87445bf2cc2807399d403cbbada8c0e85 | https://github.com/grpc/grpc-go/blob/028242f87445bf2cc2807399d403cbbada8c0e85/benchmark/stats/histogram.go#L154-L163 |
127,213 | grpc/grpc-go | benchmark/stats/histogram.go | Add | func (h *Histogram) Add(value int64) error {
bucket, err := h.findBucket(value)
if err != nil {
return err
}
h.Buckets[bucket].Count++
h.Count++
h.Sum += value
h.SumOfSquares += value * value
if value < h.Min {
h.Min = value
}
if value > h.Max {
h.Max = value
}
return nil
} | go | func (h *Histogram) Add(value int64) error {
bucket, err := h.findBucket(value)
if err != nil {
return err
}
h.Buckets[bucket].Count++
h.Count++
h.Sum += value
h.SumOfSquares += value * value
if value < h.Min {
h.Min = value
}
if value > h.Max {
h.Max = value
}
return nil
} | [
"func",
"(",
"h",
"*",
"Histogram",
")",
"Add",
"(",
"value",
"int64",
")",
"error",
"{",
"bucket",
",",
"err",
":=",
"h",
".",
"findBucket",
"(",
"value",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"h",
".",
"B... | // Add adds a value to the histogram. | [
"Add",
"adds",
"a",
"value",
"to",
"the",
"histogram",
"."
] | 028242f87445bf2cc2807399d403cbbada8c0e85 | https://github.com/grpc/grpc-go/blob/028242f87445bf2cc2807399d403cbbada8c0e85/benchmark/stats/histogram.go#L171-L187 |
127,214 | grpc/grpc-go | benchmark/stats/histogram.go | Merge | func (h *Histogram) Merge(h2 *Histogram) {
if h.opts != h2.opts {
log.Fatalf("failed to merge histograms, created by inequivalent options")
}
h.Count += h2.Count
h.Sum += h2.Sum
h.SumOfSquares += h2.SumOfSquares
if h2.Min < h.Min {
h.Min = h2.Min
}
if h2.Max > h.Max {
h.Max = h2.Max
}
for i, b := range ... | go | func (h *Histogram) Merge(h2 *Histogram) {
if h.opts != h2.opts {
log.Fatalf("failed to merge histograms, created by inequivalent options")
}
h.Count += h2.Count
h.Sum += h2.Sum
h.SumOfSquares += h2.SumOfSquares
if h2.Min < h.Min {
h.Min = h2.Min
}
if h2.Max > h.Max {
h.Max = h2.Max
}
for i, b := range ... | [
"func",
"(",
"h",
"*",
"Histogram",
")",
"Merge",
"(",
"h2",
"*",
"Histogram",
")",
"{",
"if",
"h",
".",
"opts",
"!=",
"h2",
".",
"opts",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"h",
".",
"Count",
"+=",
"h2",
".",
... | // Merge takes another histogram h2, and merges its content into h.
// The two histograms must be created by equivalent HistogramOptions. | [
"Merge",
"takes",
"another",
"histogram",
"h2",
"and",
"merges",
"its",
"content",
"into",
"h",
".",
"The",
"two",
"histograms",
"must",
"be",
"created",
"by",
"equivalent",
"HistogramOptions",
"."
] | 028242f87445bf2cc2807399d403cbbada8c0e85 | https://github.com/grpc/grpc-go/blob/028242f87445bf2cc2807399d403cbbada8c0e85/benchmark/stats/histogram.go#L206-L222 |
127,215 | grpc/grpc-go | resolver/manual/manual.go | Build | func (r *Resolver) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOption) (resolver.Resolver, error) {
r.cc = cc
if r.bootstrapState != nil {
r.UpdateState(*r.bootstrapState)
}
return r, nil
} | go | func (r *Resolver) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOption) (resolver.Resolver, error) {
r.cc = cc
if r.bootstrapState != nil {
r.UpdateState(*r.bootstrapState)
}
return r, nil
} | [
"func",
"(",
"r",
"*",
"Resolver",
")",
"Build",
"(",
"target",
"resolver",
".",
"Target",
",",
"cc",
"resolver",
".",
"ClientConn",
",",
"opts",
"resolver",
".",
"BuildOption",
")",
"(",
"resolver",
".",
"Resolver",
",",
"error",
")",
"{",
"r",
".",
... | // Build returns itself for Resolver, because it's both a builder and a resolver. | [
"Build",
"returns",
"itself",
"for",
"Resolver",
"because",
"it",
"s",
"both",
"a",
"builder",
"and",
"a",
"resolver",
"."
] | 028242f87445bf2cc2807399d403cbbada8c0e85 | https://github.com/grpc/grpc-go/blob/028242f87445bf2cc2807399d403cbbada8c0e85/resolver/manual/manual.go#L54-L60 |
127,216 | grpc/grpc-go | resolver/manual/manual.go | GenerateAndRegisterManualResolver | func GenerateAndRegisterManualResolver() (*Resolver, func()) {
scheme := strconv.FormatInt(time.Now().UnixNano(), 36)
r := NewBuilderWithScheme(scheme)
resolver.Register(r)
return r, func() { resolver.UnregisterForTesting(scheme) }
} | go | func GenerateAndRegisterManualResolver() (*Resolver, func()) {
scheme := strconv.FormatInt(time.Now().UnixNano(), 36)
r := NewBuilderWithScheme(scheme)
resolver.Register(r)
return r, func() { resolver.UnregisterForTesting(scheme) }
} | [
"func",
"GenerateAndRegisterManualResolver",
"(",
")",
"(",
"*",
"Resolver",
",",
"func",
"(",
")",
")",
"{",
"scheme",
":=",
"strconv",
".",
"FormatInt",
"(",
"time",
".",
"Now",
"(",
")",
".",
"UnixNano",
"(",
")",
",",
"36",
")",
"\n",
"r",
":=",
... | // GenerateAndRegisterManualResolver generates a random scheme and a Resolver
// with it. It also registers this Resolver.
// It returns the Resolver and a cleanup function to unregister it. | [
"GenerateAndRegisterManualResolver",
"generates",
"a",
"random",
"scheme",
"and",
"a",
"Resolver",
"with",
"it",
".",
"It",
"also",
"registers",
"this",
"Resolver",
".",
"It",
"returns",
"the",
"Resolver",
"and",
"a",
"cleanup",
"function",
"to",
"unregister",
"... | 028242f87445bf2cc2807399d403cbbada8c0e85 | https://github.com/grpc/grpc-go/blob/028242f87445bf2cc2807399d403cbbada8c0e85/resolver/manual/manual.go#L81-L86 |
127,217 | github/hub | github/project.go | rawHost | func rawHost(host string) string {
u, err := url.Parse(host)
utils.Check(err)
if u.IsAbs() {
return u.Host
} else {
return u.Path
}
} | go | func rawHost(host string) string {
u, err := url.Parse(host)
utils.Check(err)
if u.IsAbs() {
return u.Host
} else {
return u.Path
}
} | [
"func",
"rawHost",
"(",
"host",
"string",
")",
"string",
"{",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"host",
")",
"\n",
"utils",
".",
"Check",
"(",
"err",
")",
"\n\n",
"if",
"u",
".",
"IsAbs",
"(",
")",
"{",
"return",
"u",
".",
"Host"... | // Remove the scheme from host when the host url is absolute. | [
"Remove",
"the",
"scheme",
"from",
"host",
"when",
"the",
"host",
"url",
"is",
"absolute",
"."
] | 16ccde1a74ef89455ccacb7f42aded9677d54943 | https://github.com/github/hub/blob/16ccde1a74ef89455ccacb7f42aded9677d54943/github/project.go#L87-L96 |
127,218 | github/hub | ui/format.go | Expand | func Expand(format string, values map[string]string, colorize bool) string {
f := &expander{values: values, colorize: colorize}
return f.Expand(format)
} | go | func Expand(format string, values map[string]string, colorize bool) string {
f := &expander{values: values, colorize: colorize}
return f.Expand(format)
} | [
"func",
"Expand",
"(",
"format",
"string",
",",
"values",
"map",
"[",
"string",
"]",
"string",
",",
"colorize",
"bool",
")",
"string",
"{",
"f",
":=",
"&",
"expander",
"{",
"values",
":",
"values",
",",
"colorize",
":",
"colorize",
"}",
"\n",
"return",... | // Expand expands a format string using `git log` message syntax. | [
"Expand",
"expands",
"a",
"format",
"string",
"using",
"git",
"log",
"message",
"syntax",
"."
] | 16ccde1a74ef89455ccacb7f42aded9677d54943 | https://github.com/github/hub/blob/16ccde1a74ef89455ccacb7f42aded9677d54943/ui/format.go#L10-L13 |
127,219 | github/hub | github/http.go | proxyFromEnvironment | func proxyFromEnvironment(req *http.Request) (*url.URL, error) {
proxy := os.Getenv("http_proxy")
if proxy == "" {
proxy = os.Getenv("HTTP_PROXY")
}
if proxy == "" {
return nil, nil
}
proxyURL, err := url.Parse(proxy)
if err != nil || !strings.HasPrefix(proxyURL.Scheme, "http") {
if proxyURL, err := url.P... | go | func proxyFromEnvironment(req *http.Request) (*url.URL, error) {
proxy := os.Getenv("http_proxy")
if proxy == "" {
proxy = os.Getenv("HTTP_PROXY")
}
if proxy == "" {
return nil, nil
}
proxyURL, err := url.Parse(proxy)
if err != nil || !strings.HasPrefix(proxyURL.Scheme, "http") {
if proxyURL, err := url.P... | [
"func",
"proxyFromEnvironment",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"url",
".",
"URL",
",",
"error",
")",
"{",
"proxy",
":=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"\n",
"if",
"proxy",
"==",
"\"",
"\"",
"{",
"proxy",
"=",... | // An implementation of http.ProxyFromEnvironment that isn't broken | [
"An",
"implementation",
"of",
"http",
".",
"ProxyFromEnvironment",
"that",
"isn",
"t",
"broken"
] | 16ccde1a74ef89455ccacb7f42aded9677d54943 | https://github.com/github/hub/blob/16ccde1a74ef89455ccacb7f42aded9677d54943/github/http.go#L201-L222 |
127,220 | spf13/cobra | command.go | SetFlagErrorFunc | func (c *Command) SetFlagErrorFunc(f func(*Command, error) error) {
c.flagErrorFunc = f
} | go | func (c *Command) SetFlagErrorFunc(f func(*Command, error) error) {
c.flagErrorFunc = f
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"SetFlagErrorFunc",
"(",
"f",
"func",
"(",
"*",
"Command",
",",
"error",
")",
"error",
")",
"{",
"c",
".",
"flagErrorFunc",
"=",
"f",
"\n",
"}"
] | // SetFlagErrorFunc sets a function to generate an error when flag parsing
// fails. | [
"SetFlagErrorFunc",
"sets",
"a",
"function",
"to",
"generate",
"an",
"error",
"when",
"flag",
"parsing",
"fails",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L224-L226 |
127,221 | spf13/cobra | command.go | SetGlobalNormalizationFunc | func (c *Command) SetGlobalNormalizationFunc(n func(f *flag.FlagSet, name string) flag.NormalizedName) {
c.Flags().SetNormalizeFunc(n)
c.PersistentFlags().SetNormalizeFunc(n)
c.globNormFunc = n
for _, command := range c.commands {
command.SetGlobalNormalizationFunc(n)
}
} | go | func (c *Command) SetGlobalNormalizationFunc(n func(f *flag.FlagSet, name string) flag.NormalizedName) {
c.Flags().SetNormalizeFunc(n)
c.PersistentFlags().SetNormalizeFunc(n)
c.globNormFunc = n
for _, command := range c.commands {
command.SetGlobalNormalizationFunc(n)
}
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"SetGlobalNormalizationFunc",
"(",
"n",
"func",
"(",
"f",
"*",
"flag",
".",
"FlagSet",
",",
"name",
"string",
")",
"flag",
".",
"NormalizedName",
")",
"{",
"c",
".",
"Flags",
"(",
")",
".",
"SetNormalizeFunc",
"("... | // SetGlobalNormalizationFunc sets a normalization function to all flag sets and also to child commands.
// The user should not have a cyclic dependency on commands. | [
"SetGlobalNormalizationFunc",
"sets",
"a",
"normalization",
"function",
"to",
"all",
"flag",
"sets",
"and",
"also",
"to",
"child",
"commands",
".",
"The",
"user",
"should",
"not",
"have",
"a",
"cyclic",
"dependency",
"on",
"commands",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L250-L258 |
127,222 | spf13/cobra | command.go | UsageFunc | func (c *Command) UsageFunc() (f func(*Command) error) {
if c.usageFunc != nil {
return c.usageFunc
}
if c.HasParent() {
return c.Parent().UsageFunc()
}
return func(c *Command) error {
c.mergePersistentFlags()
err := tmpl(c.OutOrStderr(), c.UsageTemplate(), c)
if err != nil {
c.Println(err)
}
retu... | go | func (c *Command) UsageFunc() (f func(*Command) error) {
if c.usageFunc != nil {
return c.usageFunc
}
if c.HasParent() {
return c.Parent().UsageFunc()
}
return func(c *Command) error {
c.mergePersistentFlags()
err := tmpl(c.OutOrStderr(), c.UsageTemplate(), c)
if err != nil {
c.Println(err)
}
retu... | [
"func",
"(",
"c",
"*",
"Command",
")",
"UsageFunc",
"(",
")",
"(",
"f",
"func",
"(",
"*",
"Command",
")",
"error",
")",
"{",
"if",
"c",
".",
"usageFunc",
"!=",
"nil",
"{",
"return",
"c",
".",
"usageFunc",
"\n",
"}",
"\n",
"if",
"c",
".",
"HasPa... | // UsageFunc returns either the function set by SetUsageFunc for this command
// or a parent, or it returns a default usage function. | [
"UsageFunc",
"returns",
"either",
"the",
"function",
"set",
"by",
"SetUsageFunc",
"for",
"this",
"command",
"or",
"a",
"parent",
"or",
"it",
"returns",
"a",
"default",
"usage",
"function",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L282-L297 |
127,223 | spf13/cobra | command.go | HelpFunc | func (c *Command) HelpFunc() func(*Command, []string) {
if c.helpFunc != nil {
return c.helpFunc
}
if c.HasParent() {
return c.Parent().HelpFunc()
}
return func(c *Command, a []string) {
c.mergePersistentFlags()
err := tmpl(c.OutOrStdout(), c.HelpTemplate(), c)
if err != nil {
c.Println(err)
}
}
} | go | func (c *Command) HelpFunc() func(*Command, []string) {
if c.helpFunc != nil {
return c.helpFunc
}
if c.HasParent() {
return c.Parent().HelpFunc()
}
return func(c *Command, a []string) {
c.mergePersistentFlags()
err := tmpl(c.OutOrStdout(), c.HelpTemplate(), c)
if err != nil {
c.Println(err)
}
}
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"HelpFunc",
"(",
")",
"func",
"(",
"*",
"Command",
",",
"[",
"]",
"string",
")",
"{",
"if",
"c",
".",
"helpFunc",
"!=",
"nil",
"{",
"return",
"c",
".",
"helpFunc",
"\n",
"}",
"\n",
"if",
"c",
".",
"HasPare... | // HelpFunc returns either the function set by SetHelpFunc for this command
// or a parent, or it returns a function with default help behavior. | [
"HelpFunc",
"returns",
"either",
"the",
"function",
"set",
"by",
"SetHelpFunc",
"for",
"this",
"command",
"or",
"a",
"parent",
"or",
"it",
"returns",
"a",
"function",
"with",
"default",
"help",
"behavior",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L308-L322 |
127,224 | spf13/cobra | command.go | UsageString | func (c *Command) UsageString() string {
tmpOutput := c.output
bb := new(bytes.Buffer)
c.SetOutput(bb)
c.Usage()
c.output = tmpOutput
return bb.String()
} | go | func (c *Command) UsageString() string {
tmpOutput := c.output
bb := new(bytes.Buffer)
c.SetOutput(bb)
c.Usage()
c.output = tmpOutput
return bb.String()
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"UsageString",
"(",
")",
"string",
"{",
"tmpOutput",
":=",
"c",
".",
"output",
"\n",
"bb",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"c",
".",
"SetOutput",
"(",
"bb",
")",
"\n",
"c",
".",
"Usage",... | // UsageString return usage string. | [
"UsageString",
"return",
"usage",
"string",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L333-L340 |
127,225 | spf13/cobra | command.go | FlagErrorFunc | func (c *Command) FlagErrorFunc() (f func(*Command, error) error) {
if c.flagErrorFunc != nil {
return c.flagErrorFunc
}
if c.HasParent() {
return c.parent.FlagErrorFunc()
}
return func(c *Command, err error) error {
return err
}
} | go | func (c *Command) FlagErrorFunc() (f func(*Command, error) error) {
if c.flagErrorFunc != nil {
return c.flagErrorFunc
}
if c.HasParent() {
return c.parent.FlagErrorFunc()
}
return func(c *Command, err error) error {
return err
}
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"FlagErrorFunc",
"(",
")",
"(",
"f",
"func",
"(",
"*",
"Command",
",",
"error",
")",
"error",
")",
"{",
"if",
"c",
".",
"flagErrorFunc",
"!=",
"nil",
"{",
"return",
"c",
".",
"flagErrorFunc",
"\n",
"}",
"\n\n"... | // FlagErrorFunc returns either the function set by SetFlagErrorFunc for this
// command or a parent, or it returns a function which returns the original
// error. | [
"FlagErrorFunc",
"returns",
"either",
"the",
"function",
"set",
"by",
"SetFlagErrorFunc",
"for",
"this",
"command",
"or",
"a",
"parent",
"or",
"it",
"returns",
"a",
"function",
"which",
"returns",
"the",
"original",
"error",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L345-L356 |
127,226 | spf13/cobra | command.go | UsagePadding | func (c *Command) UsagePadding() int {
if c.parent == nil || minUsagePadding > c.parent.commandsMaxUseLen {
return minUsagePadding
}
return c.parent.commandsMaxUseLen
} | go | func (c *Command) UsagePadding() int {
if c.parent == nil || minUsagePadding > c.parent.commandsMaxUseLen {
return minUsagePadding
}
return c.parent.commandsMaxUseLen
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"UsagePadding",
"(",
")",
"int",
"{",
"if",
"c",
".",
"parent",
"==",
"nil",
"||",
"minUsagePadding",
">",
"c",
".",
"parent",
".",
"commandsMaxUseLen",
"{",
"return",
"minUsagePadding",
"\n",
"}",
"\n",
"return",
... | // UsagePadding return padding for the usage. | [
"UsagePadding",
"return",
"padding",
"for",
"the",
"usage",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L361-L366 |
127,227 | spf13/cobra | command.go | CommandPathPadding | func (c *Command) CommandPathPadding() int {
if c.parent == nil || minCommandPathPadding > c.parent.commandsMaxCommandPathLen {
return minCommandPathPadding
}
return c.parent.commandsMaxCommandPathLen
} | go | func (c *Command) CommandPathPadding() int {
if c.parent == nil || minCommandPathPadding > c.parent.commandsMaxCommandPathLen {
return minCommandPathPadding
}
return c.parent.commandsMaxCommandPathLen
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"CommandPathPadding",
"(",
")",
"int",
"{",
"if",
"c",
".",
"parent",
"==",
"nil",
"||",
"minCommandPathPadding",
">",
"c",
".",
"parent",
".",
"commandsMaxCommandPathLen",
"{",
"return",
"minCommandPathPadding",
"\n",
... | // CommandPathPadding return padding for the command path. | [
"CommandPathPadding",
"return",
"padding",
"for",
"the",
"command",
"path",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L371-L376 |
127,228 | spf13/cobra | command.go | NamePadding | func (c *Command) NamePadding() int {
if c.parent == nil || minNamePadding > c.parent.commandsMaxNameLen {
return minNamePadding
}
return c.parent.commandsMaxNameLen
} | go | func (c *Command) NamePadding() int {
if c.parent == nil || minNamePadding > c.parent.commandsMaxNameLen {
return minNamePadding
}
return c.parent.commandsMaxNameLen
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"NamePadding",
"(",
")",
"int",
"{",
"if",
"c",
".",
"parent",
"==",
"nil",
"||",
"minNamePadding",
">",
"c",
".",
"parent",
".",
"commandsMaxNameLen",
"{",
"return",
"minNamePadding",
"\n",
"}",
"\n",
"return",
"... | // NamePadding returns padding for the name. | [
"NamePadding",
"returns",
"padding",
"for",
"the",
"name",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L381-L386 |
127,229 | spf13/cobra | command.go | UsageTemplate | func (c *Command) UsageTemplate() string {
if c.usageTemplate != "" {
return c.usageTemplate
}
if c.HasParent() {
return c.parent.UsageTemplate()
}
return `Usage:{{if .Runnable}}
{{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
{{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}}
Aliases:
{{.N... | go | func (c *Command) UsageTemplate() string {
if c.usageTemplate != "" {
return c.usageTemplate
}
if c.HasParent() {
return c.parent.UsageTemplate()
}
return `Usage:{{if .Runnable}}
{{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
{{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}}
Aliases:
{{.N... | [
"func",
"(",
"c",
"*",
"Command",
")",
"UsageTemplate",
"(",
")",
"string",
"{",
"if",
"c",
".",
"usageTemplate",
"!=",
"\"",
"\"",
"{",
"return",
"c",
".",
"usageTemplate",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"HasParent",
"(",
")",
"{",
"return",
"... | // UsageTemplate returns usage template for the command. | [
"UsageTemplate",
"returns",
"usage",
"template",
"for",
"the",
"command",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L389-L421 |
127,230 | spf13/cobra | command.go | HelpTemplate | func (c *Command) HelpTemplate() string {
if c.helpTemplate != "" {
return c.helpTemplate
}
if c.HasParent() {
return c.parent.HelpTemplate()
}
return `{{with (or .Long .Short)}}{{. | trimTrailingWhitespaces}}
{{end}}{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}`
} | go | func (c *Command) HelpTemplate() string {
if c.helpTemplate != "" {
return c.helpTemplate
}
if c.HasParent() {
return c.parent.HelpTemplate()
}
return `{{with (or .Long .Short)}}{{. | trimTrailingWhitespaces}}
{{end}}{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}`
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"HelpTemplate",
"(",
")",
"string",
"{",
"if",
"c",
".",
"helpTemplate",
"!=",
"\"",
"\"",
"{",
"return",
"c",
".",
"helpTemplate",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"HasParent",
"(",
")",
"{",
"return",
"c",... | // HelpTemplate return help template for the command. | [
"HelpTemplate",
"return",
"help",
"template",
"for",
"the",
"command",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L424-L435 |
127,231 | spf13/cobra | command.go | VersionTemplate | func (c *Command) VersionTemplate() string {
if c.versionTemplate != "" {
return c.versionTemplate
}
if c.HasParent() {
return c.parent.VersionTemplate()
}
return `{{with .Name}}{{printf "%s " .}}{{end}}{{printf "version %s" .Version}}
`
} | go | func (c *Command) VersionTemplate() string {
if c.versionTemplate != "" {
return c.versionTemplate
}
if c.HasParent() {
return c.parent.VersionTemplate()
}
return `{{with .Name}}{{printf "%s " .}}{{end}}{{printf "version %s" .Version}}
`
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"VersionTemplate",
"(",
")",
"string",
"{",
"if",
"c",
".",
"versionTemplate",
"!=",
"\"",
"\"",
"{",
"return",
"c",
".",
"versionTemplate",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"HasParent",
"(",
")",
"{",
"return... | // VersionTemplate return version template for the command. | [
"VersionTemplate",
"return",
"version",
"template",
"for",
"the",
"command",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L438-L448 |
127,232 | spf13/cobra | command.go | Find | func (c *Command) Find(args []string) (*Command, []string, error) {
var innerfind func(*Command, []string) (*Command, []string)
innerfind = func(c *Command, innerArgs []string) (*Command, []string) {
argsWOflags := stripFlags(innerArgs, c)
if len(argsWOflags) == 0 {
return c, innerArgs
}
nextSubCmd := arg... | go | func (c *Command) Find(args []string) (*Command, []string, error) {
var innerfind func(*Command, []string) (*Command, []string)
innerfind = func(c *Command, innerArgs []string) (*Command, []string) {
argsWOflags := stripFlags(innerArgs, c)
if len(argsWOflags) == 0 {
return c, innerArgs
}
nextSubCmd := arg... | [
"func",
"(",
"c",
"*",
"Command",
")",
"Find",
"(",
"args",
"[",
"]",
"string",
")",
"(",
"*",
"Command",
",",
"[",
"]",
"string",
",",
"error",
")",
"{",
"var",
"innerfind",
"func",
"(",
"*",
"Command",
",",
"[",
"]",
"string",
")",
"(",
"*",
... | // Find the target command given the args and command tree
// Meant to be run on the highest node. Only searches down. | [
"Find",
"the",
"target",
"command",
"given",
"the",
"args",
"and",
"command",
"tree",
"Meant",
"to",
"be",
"run",
"on",
"the",
"highest",
"node",
".",
"Only",
"searches",
"down",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L529-L551 |
127,233 | spf13/cobra | command.go | Traverse | func (c *Command) Traverse(args []string) (*Command, []string, error) {
flags := []string{}
inFlag := false
for i, arg := range args {
switch {
// A long flag with a space separated value
case strings.HasPrefix(arg, "--") && !strings.Contains(arg, "="):
// TODO: this isn't quite right, we should really che... | go | func (c *Command) Traverse(args []string) (*Command, []string, error) {
flags := []string{}
inFlag := false
for i, arg := range args {
switch {
// A long flag with a space separated value
case strings.HasPrefix(arg, "--") && !strings.Contains(arg, "="):
// TODO: this isn't quite right, we should really che... | [
"func",
"(",
"c",
"*",
"Command",
")",
"Traverse",
"(",
"args",
"[",
"]",
"string",
")",
"(",
"*",
"Command",
",",
"[",
"]",
"string",
",",
"error",
")",
"{",
"flags",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"inFlag",
":=",
"false",
"\n\n",
"... | // Traverse the command tree to find the command, and parse args for
// each parent. | [
"Traverse",
"the",
"command",
"tree",
"to",
"find",
"the",
"command",
"and",
"parse",
"args",
"for",
"each",
"parent",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L591-L630 |
127,234 | spf13/cobra | command.go | SuggestionsFor | func (c *Command) SuggestionsFor(typedName string) []string {
suggestions := []string{}
for _, cmd := range c.commands {
if cmd.IsAvailableCommand() {
levenshteinDistance := ld(typedName, cmd.Name(), true)
suggestByLevenshtein := levenshteinDistance <= c.SuggestionsMinimumDistance
suggestByPrefix := string... | go | func (c *Command) SuggestionsFor(typedName string) []string {
suggestions := []string{}
for _, cmd := range c.commands {
if cmd.IsAvailableCommand() {
levenshteinDistance := ld(typedName, cmd.Name(), true)
suggestByLevenshtein := levenshteinDistance <= c.SuggestionsMinimumDistance
suggestByPrefix := string... | [
"func",
"(",
"c",
"*",
"Command",
")",
"SuggestionsFor",
"(",
"typedName",
"string",
")",
"[",
"]",
"string",
"{",
"suggestions",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"cmd",
":=",
"range",
"c",
".",
"commands",
"{",
"if",
"cmd... | // SuggestionsFor provides suggestions for the typedName. | [
"SuggestionsFor",
"provides",
"suggestions",
"for",
"the",
"typedName",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L633-L651 |
127,235 | spf13/cobra | command.go | VisitParents | func (c *Command) VisitParents(fn func(*Command)) {
if c.HasParent() {
fn(c.Parent())
c.Parent().VisitParents(fn)
}
} | go | func (c *Command) VisitParents(fn func(*Command)) {
if c.HasParent() {
fn(c.Parent())
c.Parent().VisitParents(fn)
}
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"VisitParents",
"(",
"fn",
"func",
"(",
"*",
"Command",
")",
")",
"{",
"if",
"c",
".",
"HasParent",
"(",
")",
"{",
"fn",
"(",
"c",
".",
"Parent",
"(",
")",
")",
"\n",
"c",
".",
"Parent",
"(",
")",
".",
... | // VisitParents visits all parents of the command and invokes fn on each parent. | [
"VisitParents",
"visits",
"all",
"parents",
"of",
"the",
"command",
"and",
"invokes",
"fn",
"on",
"each",
"parent",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L654-L659 |
127,236 | spf13/cobra | command.go | Root | func (c *Command) Root() *Command {
if c.HasParent() {
return c.Parent().Root()
}
return c
} | go | func (c *Command) Root() *Command {
if c.HasParent() {
return c.Parent().Root()
}
return c
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"Root",
"(",
")",
"*",
"Command",
"{",
"if",
"c",
".",
"HasParent",
"(",
")",
"{",
"return",
"c",
".",
"Parent",
"(",
")",
".",
"Root",
"(",
")",
"\n",
"}",
"\n",
"return",
"c",
"\n",
"}"
] | // Root finds root command. | [
"Root",
"finds",
"root",
"command",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L662-L667 |
127,237 | spf13/cobra | command.go | ExecuteC | func (c *Command) ExecuteC() (cmd *Command, err error) {
// Regardless of what command execute is called on, run on Root only
if c.HasParent() {
return c.Root().ExecuteC()
}
// windows hook
if preExecHookFn != nil {
preExecHookFn(c)
}
// initialize help as the last point possible to allow for user
// over... | go | func (c *Command) ExecuteC() (cmd *Command, err error) {
// Regardless of what command execute is called on, run on Root only
if c.HasParent() {
return c.Root().ExecuteC()
}
// windows hook
if preExecHookFn != nil {
preExecHookFn(c)
}
// initialize help as the last point possible to allow for user
// over... | [
"func",
"(",
"c",
"*",
"Command",
")",
"ExecuteC",
"(",
")",
"(",
"cmd",
"*",
"Command",
",",
"err",
"error",
")",
"{",
"// Regardless of what command execute is called on, run on Root only",
"if",
"c",
".",
"HasParent",
"(",
")",
"{",
"return",
"c",
".",
"R... | // ExecuteC executes the command. | [
"ExecuteC",
"executes",
"the",
"command",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L805-L872 |
127,238 | spf13/cobra | command.go | InitDefaultHelpFlag | func (c *Command) InitDefaultHelpFlag() {
c.mergePersistentFlags()
if c.Flags().Lookup("help") == nil {
usage := "help for "
if c.Name() == "" {
usage += "this command"
} else {
usage += c.Name()
}
c.Flags().BoolP("help", "h", false, usage)
}
} | go | func (c *Command) InitDefaultHelpFlag() {
c.mergePersistentFlags()
if c.Flags().Lookup("help") == nil {
usage := "help for "
if c.Name() == "" {
usage += "this command"
} else {
usage += c.Name()
}
c.Flags().BoolP("help", "h", false, usage)
}
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"InitDefaultHelpFlag",
"(",
")",
"{",
"c",
".",
"mergePersistentFlags",
"(",
")",
"\n",
"if",
"c",
".",
"Flags",
"(",
")",
".",
"Lookup",
"(",
"\"",
"\"",
")",
"==",
"nil",
"{",
"usage",
":=",
"\"",
"\"",
"\... | // InitDefaultHelpFlag adds default help flag to c.
// It is called automatically by executing the c or by calling help and usage.
// If c already has help flag, it will do nothing. | [
"InitDefaultHelpFlag",
"adds",
"default",
"help",
"flag",
"to",
"c",
".",
"It",
"is",
"called",
"automatically",
"by",
"executing",
"the",
"c",
"or",
"by",
"calling",
"help",
"and",
"usage",
".",
"If",
"c",
"already",
"has",
"help",
"flag",
"it",
"will",
... | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L903-L914 |
127,239 | spf13/cobra | command.go | InitDefaultVersionFlag | func (c *Command) InitDefaultVersionFlag() {
if c.Version == "" {
return
}
c.mergePersistentFlags()
if c.Flags().Lookup("version") == nil {
usage := "version for "
if c.Name() == "" {
usage += "this command"
} else {
usage += c.Name()
}
c.Flags().Bool("version", false, usage)
}
} | go | func (c *Command) InitDefaultVersionFlag() {
if c.Version == "" {
return
}
c.mergePersistentFlags()
if c.Flags().Lookup("version") == nil {
usage := "version for "
if c.Name() == "" {
usage += "this command"
} else {
usage += c.Name()
}
c.Flags().Bool("version", false, usage)
}
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"InitDefaultVersionFlag",
"(",
")",
"{",
"if",
"c",
".",
"Version",
"==",
"\"",
"\"",
"{",
"return",
"\n",
"}",
"\n\n",
"c",
".",
"mergePersistentFlags",
"(",
")",
"\n",
"if",
"c",
".",
"Flags",
"(",
")",
".",... | // InitDefaultVersionFlag adds default version flag to c.
// It is called automatically by executing the c.
// If c already has a version flag, it will do nothing.
// If c.Version is empty, it will do nothing. | [
"InitDefaultVersionFlag",
"adds",
"default",
"version",
"flag",
"to",
"c",
".",
"It",
"is",
"called",
"automatically",
"by",
"executing",
"the",
"c",
".",
"If",
"c",
"already",
"has",
"a",
"version",
"flag",
"it",
"will",
"do",
"nothing",
".",
"If",
"c",
... | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L920-L935 |
127,240 | spf13/cobra | command.go | InitDefaultHelpCmd | func (c *Command) InitDefaultHelpCmd() {
if !c.HasSubCommands() {
return
}
if c.helpCommand == nil {
c.helpCommand = &Command{
Use: "help [command]",
Short: "Help about any command",
Long: `Help provides help for any command in the application.
Simply type ` + c.Name() + ` help [path to command] for ... | go | func (c *Command) InitDefaultHelpCmd() {
if !c.HasSubCommands() {
return
}
if c.helpCommand == nil {
c.helpCommand = &Command{
Use: "help [command]",
Short: "Help about any command",
Long: `Help provides help for any command in the application.
Simply type ` + c.Name() + ` help [path to command] for ... | [
"func",
"(",
"c",
"*",
"Command",
")",
"InitDefaultHelpCmd",
"(",
")",
"{",
"if",
"!",
"c",
".",
"HasSubCommands",
"(",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"helpCommand",
"==",
"nil",
"{",
"c",
".",
"helpCommand",
"=",
"&",
"Comm... | // InitDefaultHelpCmd adds default help command to c.
// It is called automatically by executing the c or by calling help and usage.
// If c already has help command or c has no subcommands, it will do nothing. | [
"InitDefaultHelpCmd",
"adds",
"default",
"help",
"command",
"to",
"c",
".",
"It",
"is",
"called",
"automatically",
"by",
"executing",
"the",
"c",
"or",
"by",
"calling",
"help",
"and",
"usage",
".",
"If",
"c",
"already",
"has",
"help",
"command",
"or",
"c",... | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L940-L966 |
127,241 | spf13/cobra | command.go | ResetCommands | func (c *Command) ResetCommands() {
c.parent = nil
c.commands = nil
c.helpCommand = nil
c.parentsPflags = nil
} | go | func (c *Command) ResetCommands() {
c.parent = nil
c.commands = nil
c.helpCommand = nil
c.parentsPflags = nil
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"ResetCommands",
"(",
")",
"{",
"c",
".",
"parent",
"=",
"nil",
"\n",
"c",
".",
"commands",
"=",
"nil",
"\n",
"c",
".",
"helpCommand",
"=",
"nil",
"\n",
"c",
".",
"parentsPflags",
"=",
"nil",
"\n",
"}"
] | // ResetCommands delete parent, subcommand and help command from c. | [
"ResetCommands",
"delete",
"parent",
"subcommand",
"and",
"help",
"command",
"from",
"c",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L969-L974 |
127,242 | spf13/cobra | command.go | Commands | func (c *Command) Commands() []*Command {
// do not sort commands if it already sorted or sorting was disabled
if EnableCommandSorting && !c.commandsAreSorted {
sort.Sort(commandSorterByName(c.commands))
c.commandsAreSorted = true
}
return c.commands
} | go | func (c *Command) Commands() []*Command {
// do not sort commands if it already sorted or sorting was disabled
if EnableCommandSorting && !c.commandsAreSorted {
sort.Sort(commandSorterByName(c.commands))
c.commandsAreSorted = true
}
return c.commands
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"Commands",
"(",
")",
"[",
"]",
"*",
"Command",
"{",
"// do not sort commands if it already sorted or sorting was disabled",
"if",
"EnableCommandSorting",
"&&",
"!",
"c",
".",
"commandsAreSorted",
"{",
"sort",
".",
"Sort",
"(... | // Commands returns a sorted slice of child commands. | [
"Commands",
"returns",
"a",
"sorted",
"slice",
"of",
"child",
"commands",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L984-L991 |
127,243 | spf13/cobra | command.go | AddCommand | func (c *Command) AddCommand(cmds ...*Command) {
for i, x := range cmds {
if cmds[i] == c {
panic("Command can't be a child of itself")
}
cmds[i].parent = c
// update max lengths
usageLen := len(x.Use)
if usageLen > c.commandsMaxUseLen {
c.commandsMaxUseLen = usageLen
}
commandPathLen := len(x.Co... | go | func (c *Command) AddCommand(cmds ...*Command) {
for i, x := range cmds {
if cmds[i] == c {
panic("Command can't be a child of itself")
}
cmds[i].parent = c
// update max lengths
usageLen := len(x.Use)
if usageLen > c.commandsMaxUseLen {
c.commandsMaxUseLen = usageLen
}
commandPathLen := len(x.Co... | [
"func",
"(",
"c",
"*",
"Command",
")",
"AddCommand",
"(",
"cmds",
"...",
"*",
"Command",
")",
"{",
"for",
"i",
",",
"x",
":=",
"range",
"cmds",
"{",
"if",
"cmds",
"[",
"i",
"]",
"==",
"c",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
... | // AddCommand adds one or more commands to this parent command. | [
"AddCommand",
"adds",
"one",
"or",
"more",
"commands",
"to",
"this",
"parent",
"command",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L994-L1020 |
127,244 | spf13/cobra | command.go | RemoveCommand | func (c *Command) RemoveCommand(cmds ...*Command) {
commands := []*Command{}
main:
for _, command := range c.commands {
for _, cmd := range cmds {
if command == cmd {
command.parent = nil
continue main
}
}
commands = append(commands, command)
}
c.commands = commands
// recompute all lengths
c.... | go | func (c *Command) RemoveCommand(cmds ...*Command) {
commands := []*Command{}
main:
for _, command := range c.commands {
for _, cmd := range cmds {
if command == cmd {
command.parent = nil
continue main
}
}
commands = append(commands, command)
}
c.commands = commands
// recompute all lengths
c.... | [
"func",
"(",
"c",
"*",
"Command",
")",
"RemoveCommand",
"(",
"cmds",
"...",
"*",
"Command",
")",
"{",
"commands",
":=",
"[",
"]",
"*",
"Command",
"{",
"}",
"\n",
"main",
":",
"for",
"_",
",",
"command",
":=",
"range",
"c",
".",
"commands",
"{",
"... | // RemoveCommand removes one or more commands from a parent command. | [
"RemoveCommand",
"removes",
"one",
"or",
"more",
"commands",
"from",
"a",
"parent",
"command",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L1023-L1054 |
127,245 | spf13/cobra | command.go | Printf | func (c *Command) Printf(format string, i ...interface{}) {
c.Print(fmt.Sprintf(format, i...))
} | go | func (c *Command) Printf(format string, i ...interface{}) {
c.Print(fmt.Sprintf(format, i...))
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"Printf",
"(",
"format",
"string",
",",
"i",
"...",
"interface",
"{",
"}",
")",
"{",
"c",
".",
"Print",
"(",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"i",
"...",
")",
")",
"\n",
"}"
] | // Printf is a convenience method to Printf to the defined output, fallback to Stderr if not set. | [
"Printf",
"is",
"a",
"convenience",
"method",
"to",
"Printf",
"to",
"the",
"defined",
"output",
"fallback",
"to",
"Stderr",
"if",
"not",
"set",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L1067-L1069 |
127,246 | spf13/cobra | command.go | CommandPath | func (c *Command) CommandPath() string {
if c.HasParent() {
return c.Parent().CommandPath() + " " + c.Name()
}
return c.Name()
} | go | func (c *Command) CommandPath() string {
if c.HasParent() {
return c.Parent().CommandPath() + " " + c.Name()
}
return c.Name()
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"CommandPath",
"(",
")",
"string",
"{",
"if",
"c",
".",
"HasParent",
"(",
")",
"{",
"return",
"c",
".",
"Parent",
"(",
")",
".",
"CommandPath",
"(",
")",
"+",
"\"",
"\"",
"+",
"c",
".",
"Name",
"(",
")",
... | // CommandPath returns the full path to this command. | [
"CommandPath",
"returns",
"the",
"full",
"path",
"to",
"this",
"command",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L1072-L1077 |
127,247 | spf13/cobra | command.go | DebugFlags | func (c *Command) DebugFlags() {
c.Println("DebugFlags called on", c.Name())
var debugflags func(*Command)
debugflags = func(x *Command) {
if x.HasFlags() || x.HasPersistentFlags() {
c.Println(x.Name())
}
if x.HasFlags() {
x.flags.VisitAll(func(f *flag.Flag) {
if x.HasPersistentFlags() && x.persiste... | go | func (c *Command) DebugFlags() {
c.Println("DebugFlags called on", c.Name())
var debugflags func(*Command)
debugflags = func(x *Command) {
if x.HasFlags() || x.HasPersistentFlags() {
c.Println(x.Name())
}
if x.HasFlags() {
x.flags.VisitAll(func(f *flag.Flag) {
if x.HasPersistentFlags() && x.persiste... | [
"func",
"(",
"c",
"*",
"Command",
")",
"DebugFlags",
"(",
")",
"{",
"c",
".",
"Println",
"(",
"\"",
"\"",
",",
"c",
".",
"Name",
"(",
")",
")",
"\n",
"var",
"debugflags",
"func",
"(",
"*",
"Command",
")",
"\n\n",
"debugflags",
"=",
"func",
"(",
... | // DebugFlags used to determine which flags have been assigned to which commands
// and which persist. | [
"DebugFlags",
"used",
"to",
"determine",
"which",
"flags",
"have",
"been",
"assigned",
"to",
"which",
"commands",
"and",
"which",
"persist",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L1098-L1135 |
127,248 | spf13/cobra | command.go | HasAlias | func (c *Command) HasAlias(s string) bool {
for _, a := range c.Aliases {
if a == s {
return true
}
}
return false
} | go | func (c *Command) HasAlias(s string) bool {
for _, a := range c.Aliases {
if a == s {
return true
}
}
return false
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"HasAlias",
"(",
"s",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"a",
":=",
"range",
"c",
".",
"Aliases",
"{",
"if",
"a",
"==",
"s",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
... | // HasAlias determines if a given string is an alias of the command. | [
"HasAlias",
"determines",
"if",
"a",
"given",
"string",
"is",
"an",
"alias",
"of",
"the",
"command",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L1148-L1155 |
127,249 | spf13/cobra | command.go | CalledAs | func (c *Command) CalledAs() string {
if c.commandCalledAs.called {
return c.commandCalledAs.name
}
return ""
} | go | func (c *Command) CalledAs() string {
if c.commandCalledAs.called {
return c.commandCalledAs.name
}
return ""
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"CalledAs",
"(",
")",
"string",
"{",
"if",
"c",
".",
"commandCalledAs",
".",
"called",
"{",
"return",
"c",
".",
"commandCalledAs",
".",
"name",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // CalledAs returns the command name or alias that was used to invoke
// this command or an empty string if the command has not been called. | [
"CalledAs",
"returns",
"the",
"command",
"name",
"or",
"alias",
"that",
"was",
"used",
"to",
"invoke",
"this",
"command",
"or",
"an",
"empty",
"string",
"if",
"the",
"command",
"has",
"not",
"been",
"called",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L1159-L1164 |
127,250 | spf13/cobra | command.go | hasNameOrAliasPrefix | func (c *Command) hasNameOrAliasPrefix(prefix string) bool {
if strings.HasPrefix(c.Name(), prefix) {
c.commandCalledAs.name = c.Name()
return true
}
for _, alias := range c.Aliases {
if strings.HasPrefix(alias, prefix) {
c.commandCalledAs.name = alias
return true
}
}
return false
} | go | func (c *Command) hasNameOrAliasPrefix(prefix string) bool {
if strings.HasPrefix(c.Name(), prefix) {
c.commandCalledAs.name = c.Name()
return true
}
for _, alias := range c.Aliases {
if strings.HasPrefix(alias, prefix) {
c.commandCalledAs.name = alias
return true
}
}
return false
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"hasNameOrAliasPrefix",
"(",
"prefix",
"string",
")",
"bool",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"c",
".",
"Name",
"(",
")",
",",
"prefix",
")",
"{",
"c",
".",
"commandCalledAs",
".",
"name",
"=",
"c",... | // hasNameOrAliasPrefix returns true if the Name or any of aliases start
// with prefix | [
"hasNameOrAliasPrefix",
"returns",
"true",
"if",
"the",
"Name",
"or",
"any",
"of",
"aliases",
"start",
"with",
"prefix"
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L1168-L1180 |
127,251 | spf13/cobra | command.go | NameAndAliases | func (c *Command) NameAndAliases() string {
return strings.Join(append([]string{c.Name()}, c.Aliases...), ", ")
} | go | func (c *Command) NameAndAliases() string {
return strings.Join(append([]string{c.Name()}, c.Aliases...), ", ")
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"NameAndAliases",
"(",
")",
"string",
"{",
"return",
"strings",
".",
"Join",
"(",
"append",
"(",
"[",
"]",
"string",
"{",
"c",
".",
"Name",
"(",
")",
"}",
",",
"c",
".",
"Aliases",
"...",
")",
",",
"\"",
"... | // NameAndAliases returns a list of the command name and all aliases | [
"NameAndAliases",
"returns",
"a",
"list",
"of",
"the",
"command",
"name",
"and",
"all",
"aliases"
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L1183-L1185 |
127,252 | spf13/cobra | command.go | Runnable | func (c *Command) Runnable() bool {
return c.Run != nil || c.RunE != nil
} | go | func (c *Command) Runnable() bool {
return c.Run != nil || c.RunE != nil
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"Runnable",
"(",
")",
"bool",
"{",
"return",
"c",
".",
"Run",
"!=",
"nil",
"||",
"c",
".",
"RunE",
"!=",
"nil",
"\n",
"}"
] | // Runnable determines if the command is itself runnable. | [
"Runnable",
"determines",
"if",
"the",
"command",
"is",
"itself",
"runnable",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L1193-L1195 |
127,253 | spf13/cobra | command.go | GlobalNormalizationFunc | func (c *Command) GlobalNormalizationFunc() func(f *flag.FlagSet, name string) flag.NormalizedName {
return c.globNormFunc
} | go | func (c *Command) GlobalNormalizationFunc() func(f *flag.FlagSet, name string) flag.NormalizedName {
return c.globNormFunc
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"GlobalNormalizationFunc",
"(",
")",
"func",
"(",
"f",
"*",
"flag",
".",
"FlagSet",
",",
"name",
"string",
")",
"flag",
".",
"NormalizedName",
"{",
"return",
"c",
".",
"globNormFunc",
"\n",
"}"
] | // GlobalNormalizationFunc returns the global normalization function or nil if it doesn't exist. | [
"GlobalNormalizationFunc",
"returns",
"the",
"global",
"normalization",
"function",
"or",
"nil",
"if",
"it",
"doesn",
"t",
"exist",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L1279-L1281 |
127,254 | spf13/cobra | command.go | LocalNonPersistentFlags | func (c *Command) LocalNonPersistentFlags() *flag.FlagSet {
persistentFlags := c.PersistentFlags()
out := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
c.LocalFlags().VisitAll(func(f *flag.Flag) {
if persistentFlags.Lookup(f.Name) == nil {
out.AddFlag(f)
}
})
return out
} | go | func (c *Command) LocalNonPersistentFlags() *flag.FlagSet {
persistentFlags := c.PersistentFlags()
out := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
c.LocalFlags().VisitAll(func(f *flag.Flag) {
if persistentFlags.Lookup(f.Name) == nil {
out.AddFlag(f)
}
})
return out
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"LocalNonPersistentFlags",
"(",
")",
"*",
"flag",
".",
"FlagSet",
"{",
"persistentFlags",
":=",
"c",
".",
"PersistentFlags",
"(",
")",
"\n\n",
"out",
":=",
"flag",
".",
"NewFlagSet",
"(",
"c",
".",
"Name",
"(",
")... | // LocalNonPersistentFlags are flags specific to this command which will NOT persist to subcommands. | [
"LocalNonPersistentFlags",
"are",
"flags",
"specific",
"to",
"this",
"command",
"which",
"will",
"NOT",
"persist",
"to",
"subcommands",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L1298-L1308 |
127,255 | spf13/cobra | command.go | LocalFlags | func (c *Command) LocalFlags() *flag.FlagSet {
c.mergePersistentFlags()
if c.lflags == nil {
c.lflags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)
if c.flagErrorBuf == nil {
c.flagErrorBuf = new(bytes.Buffer)
}
c.lflags.SetOutput(c.flagErrorBuf)
}
c.lflags.SortFlags = c.Flags().SortFlags
if c.glob... | go | func (c *Command) LocalFlags() *flag.FlagSet {
c.mergePersistentFlags()
if c.lflags == nil {
c.lflags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)
if c.flagErrorBuf == nil {
c.flagErrorBuf = new(bytes.Buffer)
}
c.lflags.SetOutput(c.flagErrorBuf)
}
c.lflags.SortFlags = c.Flags().SortFlags
if c.glob... | [
"func",
"(",
"c",
"*",
"Command",
")",
"LocalFlags",
"(",
")",
"*",
"flag",
".",
"FlagSet",
"{",
"c",
".",
"mergePersistentFlags",
"(",
")",
"\n\n",
"if",
"c",
".",
"lflags",
"==",
"nil",
"{",
"c",
".",
"lflags",
"=",
"flag",
".",
"NewFlagSet",
"("... | // LocalFlags returns the local FlagSet specifically set in the current command. | [
"LocalFlags",
"returns",
"the",
"local",
"FlagSet",
"specifically",
"set",
"in",
"the",
"current",
"command",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L1311-L1334 |
127,256 | spf13/cobra | command.go | InheritedFlags | func (c *Command) InheritedFlags() *flag.FlagSet {
c.mergePersistentFlags()
if c.iflags == nil {
c.iflags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)
if c.flagErrorBuf == nil {
c.flagErrorBuf = new(bytes.Buffer)
}
c.iflags.SetOutput(c.flagErrorBuf)
}
local := c.LocalFlags()
if c.globNormFunc != ... | go | func (c *Command) InheritedFlags() *flag.FlagSet {
c.mergePersistentFlags()
if c.iflags == nil {
c.iflags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)
if c.flagErrorBuf == nil {
c.flagErrorBuf = new(bytes.Buffer)
}
c.iflags.SetOutput(c.flagErrorBuf)
}
local := c.LocalFlags()
if c.globNormFunc != ... | [
"func",
"(",
"c",
"*",
"Command",
")",
"InheritedFlags",
"(",
")",
"*",
"flag",
".",
"FlagSet",
"{",
"c",
".",
"mergePersistentFlags",
"(",
")",
"\n\n",
"if",
"c",
".",
"iflags",
"==",
"nil",
"{",
"c",
".",
"iflags",
"=",
"flag",
".",
"NewFlagSet",
... | // InheritedFlags returns all flags which were inherited from parent commands. | [
"InheritedFlags",
"returns",
"all",
"flags",
"which",
"were",
"inherited",
"from",
"parent",
"commands",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L1337-L1359 |
127,257 | spf13/cobra | command.go | PersistentFlags | func (c *Command) PersistentFlags() *flag.FlagSet {
if c.pflags == nil {
c.pflags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)
if c.flagErrorBuf == nil {
c.flagErrorBuf = new(bytes.Buffer)
}
c.pflags.SetOutput(c.flagErrorBuf)
}
return c.pflags
} | go | func (c *Command) PersistentFlags() *flag.FlagSet {
if c.pflags == nil {
c.pflags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)
if c.flagErrorBuf == nil {
c.flagErrorBuf = new(bytes.Buffer)
}
c.pflags.SetOutput(c.flagErrorBuf)
}
return c.pflags
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"PersistentFlags",
"(",
")",
"*",
"flag",
".",
"FlagSet",
"{",
"if",
"c",
".",
"pflags",
"==",
"nil",
"{",
"c",
".",
"pflags",
"=",
"flag",
".",
"NewFlagSet",
"(",
"c",
".",
"Name",
"(",
")",
",",
"flag",
... | // PersistentFlags returns the persistent FlagSet specifically set in the current command. | [
"PersistentFlags",
"returns",
"the",
"persistent",
"FlagSet",
"specifically",
"set",
"in",
"the",
"current",
"command",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L1367-L1376 |
127,258 | spf13/cobra | command.go | ResetFlags | func (c *Command) ResetFlags() {
c.flagErrorBuf = new(bytes.Buffer)
c.flagErrorBuf.Reset()
c.flags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)
c.flags.SetOutput(c.flagErrorBuf)
c.pflags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)
c.pflags.SetOutput(c.flagErrorBuf)
c.lflags = nil
c.iflags = nil
c.p... | go | func (c *Command) ResetFlags() {
c.flagErrorBuf = new(bytes.Buffer)
c.flagErrorBuf.Reset()
c.flags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)
c.flags.SetOutput(c.flagErrorBuf)
c.pflags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)
c.pflags.SetOutput(c.flagErrorBuf)
c.lflags = nil
c.iflags = nil
c.p... | [
"func",
"(",
"c",
"*",
"Command",
")",
"ResetFlags",
"(",
")",
"{",
"c",
".",
"flagErrorBuf",
"=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"c",
".",
"flagErrorBuf",
".",
"Reset",
"(",
")",
"\n",
"c",
".",
"flags",
"=",
"flag",
".",
"NewFla... | // ResetFlags deletes all flags from command. | [
"ResetFlags",
"deletes",
"all",
"flags",
"from",
"command",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L1379-L1390 |
127,259 | spf13/cobra | command.go | Flag | func (c *Command) Flag(name string) (flag *flag.Flag) {
flag = c.Flags().Lookup(name)
if flag == nil {
flag = c.persistentFlag(name)
}
return
} | go | func (c *Command) Flag(name string) (flag *flag.Flag) {
flag = c.Flags().Lookup(name)
if flag == nil {
flag = c.persistentFlag(name)
}
return
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"Flag",
"(",
"name",
"string",
")",
"(",
"flag",
"*",
"flag",
".",
"Flag",
")",
"{",
"flag",
"=",
"c",
".",
"Flags",
"(",
")",
".",
"Lookup",
"(",
"name",
")",
"\n\n",
"if",
"flag",
"==",
"nil",
"{",
"fl... | // Flag climbs up the command tree looking for matching flag. | [
"Flag",
"climbs",
"up",
"the",
"command",
"tree",
"looking",
"for",
"matching",
"flag",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L1436-L1444 |
127,260 | spf13/cobra | command.go | persistentFlag | func (c *Command) persistentFlag(name string) (flag *flag.Flag) {
if c.HasPersistentFlags() {
flag = c.PersistentFlags().Lookup(name)
}
if flag == nil {
c.updateParentsPflags()
flag = c.parentsPflags.Lookup(name)
}
return
} | go | func (c *Command) persistentFlag(name string) (flag *flag.Flag) {
if c.HasPersistentFlags() {
flag = c.PersistentFlags().Lookup(name)
}
if flag == nil {
c.updateParentsPflags()
flag = c.parentsPflags.Lookup(name)
}
return
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"persistentFlag",
"(",
"name",
"string",
")",
"(",
"flag",
"*",
"flag",
".",
"Flag",
")",
"{",
"if",
"c",
".",
"HasPersistentFlags",
"(",
")",
"{",
"flag",
"=",
"c",
".",
"PersistentFlags",
"(",
")",
".",
"Loo... | // Recursively find matching persistent flag. | [
"Recursively",
"find",
"matching",
"persistent",
"flag",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L1447-L1457 |
127,261 | spf13/cobra | command.go | ParseFlags | func (c *Command) ParseFlags(args []string) error {
if c.DisableFlagParsing {
return nil
}
if c.flagErrorBuf == nil {
c.flagErrorBuf = new(bytes.Buffer)
}
beforeErrorBufLen := c.flagErrorBuf.Len()
c.mergePersistentFlags()
//do it here after merging all flags and just before parse
c.Flags().ParseErrorsWhit... | go | func (c *Command) ParseFlags(args []string) error {
if c.DisableFlagParsing {
return nil
}
if c.flagErrorBuf == nil {
c.flagErrorBuf = new(bytes.Buffer)
}
beforeErrorBufLen := c.flagErrorBuf.Len()
c.mergePersistentFlags()
//do it here after merging all flags and just before parse
c.Flags().ParseErrorsWhit... | [
"func",
"(",
"c",
"*",
"Command",
")",
"ParseFlags",
"(",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"if",
"c",
".",
"DisableFlagParsing",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"flagErrorBuf",
"==",
"nil",
"{",
"c",
".",
"fla... | // ParseFlags parses persistent flag tree and local flags. | [
"ParseFlags",
"parses",
"persistent",
"flag",
"tree",
"and",
"local",
"flags",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L1460-L1481 |
127,262 | spf13/cobra | command.go | updateParentsPflags | func (c *Command) updateParentsPflags() {
if c.parentsPflags == nil {
c.parentsPflags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)
c.parentsPflags.SetOutput(c.flagErrorBuf)
c.parentsPflags.SortFlags = false
}
if c.globNormFunc != nil {
c.parentsPflags.SetNormalizeFunc(c.globNormFunc)
}
c.Root().Pers... | go | func (c *Command) updateParentsPflags() {
if c.parentsPflags == nil {
c.parentsPflags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)
c.parentsPflags.SetOutput(c.flagErrorBuf)
c.parentsPflags.SortFlags = false
}
if c.globNormFunc != nil {
c.parentsPflags.SetNormalizeFunc(c.globNormFunc)
}
c.Root().Pers... | [
"func",
"(",
"c",
"*",
"Command",
")",
"updateParentsPflags",
"(",
")",
"{",
"if",
"c",
".",
"parentsPflags",
"==",
"nil",
"{",
"c",
".",
"parentsPflags",
"=",
"flag",
".",
"NewFlagSet",
"(",
"c",
".",
"Name",
"(",
")",
",",
"flag",
".",
"ContinueOnE... | // updateParentsPflags updates c.parentsPflags by adding
// new persistent flags of all parents.
// If c.parentsPflags == nil, it makes new. | [
"updateParentsPflags",
"updates",
"c",
".",
"parentsPflags",
"by",
"adding",
"new",
"persistent",
"flags",
"of",
"all",
"parents",
".",
"If",
"c",
".",
"parentsPflags",
"==",
"nil",
"it",
"makes",
"new",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/command.go#L1499-L1515 |
127,263 | spf13/cobra | doc/man_docs.go | GenManTree | func GenManTree(cmd *cobra.Command, header *GenManHeader, dir string) error {
return GenManTreeFromOpts(cmd, GenManTreeOptions{
Header: header,
Path: dir,
CommandSeparator: "-",
})
} | go | func GenManTree(cmd *cobra.Command, header *GenManHeader, dir string) error {
return GenManTreeFromOpts(cmd, GenManTreeOptions{
Header: header,
Path: dir,
CommandSeparator: "-",
})
} | [
"func",
"GenManTree",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"header",
"*",
"GenManHeader",
",",
"dir",
"string",
")",
"error",
"{",
"return",
"GenManTreeFromOpts",
"(",
"cmd",
",",
"GenManTreeOptions",
"{",
"Header",
":",
"header",
",",
"Path",
":... | // GenManTree will generate a man page for this command and all descendants
// in the directory given. The header may be nil. This function may not work
// correctly if your command names have `-` in them. If you have `cmd` with two
// subcmds, `sub` and `sub-third`, and `sub` has a subcommand called `third`
// it is u... | [
"GenManTree",
"will",
"generate",
"a",
"man",
"page",
"for",
"this",
"command",
"and",
"all",
"descendants",
"in",
"the",
"directory",
"given",
".",
"The",
"header",
"may",
"be",
"nil",
".",
"This",
"function",
"may",
"not",
"work",
"correctly",
"if",
"you... | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/doc/man_docs.go#L37-L43 |
127,264 | spf13/cobra | doc/man_docs.go | GenManTreeFromOpts | func GenManTreeFromOpts(cmd *cobra.Command, opts GenManTreeOptions) error {
header := opts.Header
if header == nil {
header = &GenManHeader{}
}
for _, c := range cmd.Commands() {
if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {
continue
}
if err := GenManTreeFromOpts(c, opts); err != nil ... | go | func GenManTreeFromOpts(cmd *cobra.Command, opts GenManTreeOptions) error {
header := opts.Header
if header == nil {
header = &GenManHeader{}
}
for _, c := range cmd.Commands() {
if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {
continue
}
if err := GenManTreeFromOpts(c, opts); err != nil ... | [
"func",
"GenManTreeFromOpts",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"opts",
"GenManTreeOptions",
")",
"error",
"{",
"header",
":=",
"opts",
".",
"Header",
"\n",
"if",
"header",
"==",
"nil",
"{",
"header",
"=",
"&",
"GenManHeader",
"{",
"}",
"\n"... | // GenManTreeFromOpts generates a man page for the command and all descendants.
// The pages are written to the opts.Path directory. | [
"GenManTreeFromOpts",
"generates",
"a",
"man",
"page",
"for",
"the",
"command",
"and",
"all",
"descendants",
".",
"The",
"pages",
"are",
"written",
"to",
"the",
"opts",
".",
"Path",
"directory",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/doc/man_docs.go#L47-L79 |
127,265 | spf13/cobra | doc/man_docs.go | GenMan | func GenMan(cmd *cobra.Command, header *GenManHeader, w io.Writer) error {
if header == nil {
header = &GenManHeader{}
}
if err := fillHeader(header, cmd.CommandPath()); err != nil {
return err
}
b := genMan(cmd, header)
_, err := w.Write(md2man.Render(b))
return err
} | go | func GenMan(cmd *cobra.Command, header *GenManHeader, w io.Writer) error {
if header == nil {
header = &GenManHeader{}
}
if err := fillHeader(header, cmd.CommandPath()); err != nil {
return err
}
b := genMan(cmd, header)
_, err := w.Write(md2man.Render(b))
return err
} | [
"func",
"GenMan",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"header",
"*",
"GenManHeader",
",",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"if",
"header",
"==",
"nil",
"{",
"header",
"=",
"&",
"GenManHeader",
"{",
"}",
"\n",
"}",
"\n",
"if",... | // GenMan will generate a man page for the given command and write it to
// w. The header argument may be nil, however obviously w may not. | [
"GenMan",
"will",
"generate",
"a",
"man",
"page",
"for",
"the",
"given",
"command",
"and",
"write",
"it",
"to",
"w",
".",
"The",
"header",
"argument",
"may",
"be",
"nil",
"however",
"obviously",
"w",
"may",
"not",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/doc/man_docs.go#L104-L115 |
127,266 | spf13/cobra | doc/util.go | hasSeeAlso | func hasSeeAlso(cmd *cobra.Command) bool {
if cmd.HasParent() {
return true
}
for _, c := range cmd.Commands() {
if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {
continue
}
return true
}
return false
} | go | func hasSeeAlso(cmd *cobra.Command) bool {
if cmd.HasParent() {
return true
}
for _, c := range cmd.Commands() {
if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {
continue
}
return true
}
return false
} | [
"func",
"hasSeeAlso",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
")",
"bool",
"{",
"if",
"cmd",
".",
"HasParent",
"(",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"cmd",
".",
"Commands",
"(",
")",
"{",
"if",
... | // Test to see if we have a reason to print See Also information in docs
// Basically this is a test for a parent commend or a subcommand which is
// both not deprecated and not the autogenerated help command. | [
"Test",
"to",
"see",
"if",
"we",
"have",
"a",
"reason",
"to",
"print",
"See",
"Also",
"information",
"in",
"docs",
"Basically",
"this",
"is",
"a",
"test",
"for",
"a",
"parent",
"commend",
"or",
"a",
"subcommand",
"which",
"is",
"both",
"not",
"deprecated... | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/doc/util.go#L25-L36 |
127,267 | spf13/cobra | cobra/cmd/helpers.go | isEmpty | func isEmpty(path string) bool {
fi, err := os.Stat(path)
if err != nil {
er(err)
}
if !fi.IsDir() {
return fi.Size() == 0
}
f, err := os.Open(path)
if err != nil {
er(err)
}
defer f.Close()
names, err := f.Readdirnames(-1)
if err != nil && err != io.EOF {
er(err)
}
for _, name := range names {... | go | func isEmpty(path string) bool {
fi, err := os.Stat(path)
if err != nil {
er(err)
}
if !fi.IsDir() {
return fi.Size() == 0
}
f, err := os.Open(path)
if err != nil {
er(err)
}
defer f.Close()
names, err := f.Readdirnames(-1)
if err != nil && err != io.EOF {
er(err)
}
for _, name := range names {... | [
"func",
"isEmpty",
"(",
"path",
"string",
")",
"bool",
"{",
"fi",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"er",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"fi",
".",
"IsDir",
"(",
")",
... | // isEmpty checks if a given path is empty.
// Hidden files in path are ignored. | [
"isEmpty",
"checks",
"if",
"a",
"given",
"path",
"is",
"empty",
".",
"Hidden",
"files",
"in",
"path",
"are",
"ignored",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/cobra/cmd/helpers.go#L69-L96 |
127,268 | spf13/cobra | cobra/cmd/helpers.go | commentifyString | func commentifyString(in string) string {
var newlines []string
lines := strings.Split(in, "\n")
for _, line := range lines {
if strings.HasPrefix(line, "//") {
newlines = append(newlines, line)
} else {
if line == "" {
newlines = append(newlines, "//")
} else {
newlines = append(newlines, "// "... | go | func commentifyString(in string) string {
var newlines []string
lines := strings.Split(in, "\n")
for _, line := range lines {
if strings.HasPrefix(line, "//") {
newlines = append(newlines, line)
} else {
if line == "" {
newlines = append(newlines, "//")
} else {
newlines = append(newlines, "// "... | [
"func",
"commentifyString",
"(",
"in",
"string",
")",
"string",
"{",
"var",
"newlines",
"[",
"]",
"string",
"\n",
"lines",
":=",
"strings",
".",
"Split",
"(",
"in",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"for",
"_",
",",
"line",
":=",
"range",
"lines",
... | // commentfyString comments every line of in. | [
"commentfyString",
"comments",
"every",
"line",
"of",
"in",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/cobra/cmd/helpers.go#L153-L168 |
127,269 | spf13/cobra | bash_completions.go | GenBashCompletion | func (c *Command) GenBashCompletion(w io.Writer) error {
buf := new(bytes.Buffer)
writePreamble(buf, c.Name())
if len(c.BashCompletionFunction) > 0 {
buf.WriteString(c.BashCompletionFunction + "\n")
}
gen(buf, c)
writePostscript(buf, c.Name())
_, err := buf.WriteTo(w)
return err
} | go | func (c *Command) GenBashCompletion(w io.Writer) error {
buf := new(bytes.Buffer)
writePreamble(buf, c.Name())
if len(c.BashCompletionFunction) > 0 {
buf.WriteString(c.BashCompletionFunction + "\n")
}
gen(buf, c)
writePostscript(buf, c.Name())
_, err := buf.WriteTo(w)
return err
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"GenBashCompletion",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"buf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"writePreamble",
"(",
"buf",
",",
"c",
".",
"Name",
"(",
")",
")",
"\n",
"if... | // GenBashCompletion generates bash completion file and writes to the passed writer. | [
"GenBashCompletion",
"generates",
"bash",
"completion",
"file",
"and",
"writes",
"to",
"the",
"passed",
"writer",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/bash_completions.go#L521-L532 |
127,270 | spf13/cobra | bash_completions.go | GenBashCompletionFile | func (c *Command) GenBashCompletionFile(filename string) error {
outFile, err := os.Create(filename)
if err != nil {
return err
}
defer outFile.Close()
return c.GenBashCompletion(outFile)
} | go | func (c *Command) GenBashCompletionFile(filename string) error {
outFile, err := os.Create(filename)
if err != nil {
return err
}
defer outFile.Close()
return c.GenBashCompletion(outFile)
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"GenBashCompletionFile",
"(",
"filename",
"string",
")",
"error",
"{",
"outFile",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n... | // GenBashCompletionFile generates bash completion file. | [
"GenBashCompletionFile",
"generates",
"bash",
"completion",
"file",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/bash_completions.go#L539-L547 |
127,271 | spf13/cobra | bash_completions.go | MarkPersistentFlagRequired | func (c *Command) MarkPersistentFlagRequired(name string) error {
return MarkFlagRequired(c.PersistentFlags(), name)
} | go | func (c *Command) MarkPersistentFlagRequired(name string) error {
return MarkFlagRequired(c.PersistentFlags(), name)
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"MarkPersistentFlagRequired",
"(",
"name",
"string",
")",
"error",
"{",
"return",
"MarkFlagRequired",
"(",
"c",
".",
"PersistentFlags",
"(",
")",
",",
"name",
")",
"\n",
"}"
] | // MarkPersistentFlagRequired adds the BashCompOneRequiredFlag annotation to the named persistent flag if it exists,
// and causes your command to report an error if invoked without the flag. | [
"MarkPersistentFlagRequired",
"adds",
"the",
"BashCompOneRequiredFlag",
"annotation",
"to",
"the",
"named",
"persistent",
"flag",
"if",
"it",
"exists",
"and",
"causes",
"your",
"command",
"to",
"report",
"an",
"error",
"if",
"invoked",
"without",
"the",
"flag",
".... | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/bash_completions.go#L557-L559 |
127,272 | spf13/cobra | bash_completions.go | MarkFlagFilename | func (c *Command) MarkFlagFilename(name string, extensions ...string) error {
return MarkFlagFilename(c.Flags(), name, extensions...)
} | go | func (c *Command) MarkFlagFilename(name string, extensions ...string) error {
return MarkFlagFilename(c.Flags(), name, extensions...)
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"MarkFlagFilename",
"(",
"name",
"string",
",",
"extensions",
"...",
"string",
")",
"error",
"{",
"return",
"MarkFlagFilename",
"(",
"c",
".",
"Flags",
"(",
")",
",",
"name",
",",
"extensions",
"...",
")",
"\n",
"... | // MarkFlagFilename adds the BashCompFilenameExt annotation to the named flag, if it exists.
// Generated bash autocompletion will select filenames for the flag, limiting to named extensions if provided. | [
"MarkFlagFilename",
"adds",
"the",
"BashCompFilenameExt",
"annotation",
"to",
"the",
"named",
"flag",
"if",
"it",
"exists",
".",
"Generated",
"bash",
"autocompletion",
"will",
"select",
"filenames",
"for",
"the",
"flag",
"limiting",
"to",
"named",
"extensions",
"i... | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/bash_completions.go#L569-L571 |
127,273 | spf13/cobra | bash_completions.go | MarkFlagCustom | func (c *Command) MarkFlagCustom(name string, f string) error {
return MarkFlagCustom(c.Flags(), name, f)
} | go | func (c *Command) MarkFlagCustom(name string, f string) error {
return MarkFlagCustom(c.Flags(), name, f)
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"MarkFlagCustom",
"(",
"name",
"string",
",",
"f",
"string",
")",
"error",
"{",
"return",
"MarkFlagCustom",
"(",
"c",
".",
"Flags",
"(",
")",
",",
"name",
",",
"f",
")",
"\n",
"}"
] | // MarkFlagCustom adds the BashCompCustom annotation to the named flag, if it exists.
// Generated bash autocompletion will call the bash function f for the flag. | [
"MarkFlagCustom",
"adds",
"the",
"BashCompCustom",
"annotation",
"to",
"the",
"named",
"flag",
"if",
"it",
"exists",
".",
"Generated",
"bash",
"autocompletion",
"will",
"call",
"the",
"bash",
"function",
"f",
"for",
"the",
"flag",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/bash_completions.go#L575-L577 |
127,274 | spf13/cobra | bash_completions.go | MarkPersistentFlagFilename | func (c *Command) MarkPersistentFlagFilename(name string, extensions ...string) error {
return MarkFlagFilename(c.PersistentFlags(), name, extensions...)
} | go | func (c *Command) MarkPersistentFlagFilename(name string, extensions ...string) error {
return MarkFlagFilename(c.PersistentFlags(), name, extensions...)
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"MarkPersistentFlagFilename",
"(",
"name",
"string",
",",
"extensions",
"...",
"string",
")",
"error",
"{",
"return",
"MarkFlagFilename",
"(",
"c",
".",
"PersistentFlags",
"(",
")",
",",
"name",
",",
"extensions",
"..."... | // MarkPersistentFlagFilename adds the BashCompFilenameExt annotation to the named persistent flag, if it exists.
// Generated bash autocompletion will select filenames for the flag, limiting to named extensions if provided. | [
"MarkPersistentFlagFilename",
"adds",
"the",
"BashCompFilenameExt",
"annotation",
"to",
"the",
"named",
"persistent",
"flag",
"if",
"it",
"exists",
".",
"Generated",
"bash",
"autocompletion",
"will",
"select",
"filenames",
"for",
"the",
"flag",
"limiting",
"to",
"na... | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/bash_completions.go#L581-L583 |
127,275 | spf13/cobra | bash_completions.go | MarkFlagFilename | func MarkFlagFilename(flags *pflag.FlagSet, name string, extensions ...string) error {
return flags.SetAnnotation(name, BashCompFilenameExt, extensions)
} | go | func MarkFlagFilename(flags *pflag.FlagSet, name string, extensions ...string) error {
return flags.SetAnnotation(name, BashCompFilenameExt, extensions)
} | [
"func",
"MarkFlagFilename",
"(",
"flags",
"*",
"pflag",
".",
"FlagSet",
",",
"name",
"string",
",",
"extensions",
"...",
"string",
")",
"error",
"{",
"return",
"flags",
".",
"SetAnnotation",
"(",
"name",
",",
"BashCompFilenameExt",
",",
"extensions",
")",
"\... | // MarkFlagFilename adds the BashCompFilenameExt annotation to the named flag in the flag set, if it exists.
// Generated bash autocompletion will select filenames for the flag, limiting to named extensions if provided. | [
"MarkFlagFilename",
"adds",
"the",
"BashCompFilenameExt",
"annotation",
"to",
"the",
"named",
"flag",
"in",
"the",
"flag",
"set",
"if",
"it",
"exists",
".",
"Generated",
"bash",
"autocompletion",
"will",
"select",
"filenames",
"for",
"the",
"flag",
"limiting",
"... | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/bash_completions.go#L587-L589 |
127,276 | spf13/cobra | bash_completions.go | MarkFlagCustom | func MarkFlagCustom(flags *pflag.FlagSet, name string, f string) error {
return flags.SetAnnotation(name, BashCompCustom, []string{f})
} | go | func MarkFlagCustom(flags *pflag.FlagSet, name string, f string) error {
return flags.SetAnnotation(name, BashCompCustom, []string{f})
} | [
"func",
"MarkFlagCustom",
"(",
"flags",
"*",
"pflag",
".",
"FlagSet",
",",
"name",
"string",
",",
"f",
"string",
")",
"error",
"{",
"return",
"flags",
".",
"SetAnnotation",
"(",
"name",
",",
"BashCompCustom",
",",
"[",
"]",
"string",
"{",
"f",
"}",
")"... | // MarkFlagCustom adds the BashCompCustom annotation to the named flag in the flag set, if it exists.
// Generated bash autocompletion will call the bash function f for the flag. | [
"MarkFlagCustom",
"adds",
"the",
"BashCompCustom",
"annotation",
"to",
"the",
"named",
"flag",
"in",
"the",
"flag",
"set",
"if",
"it",
"exists",
".",
"Generated",
"bash",
"autocompletion",
"will",
"call",
"the",
"bash",
"function",
"f",
"for",
"the",
"flag",
... | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/bash_completions.go#L593-L595 |
127,277 | spf13/cobra | args.go | NoArgs | func NoArgs(cmd *Command, args []string) error {
if len(args) > 0 {
return fmt.Errorf("unknown command %q for %q", args[0], cmd.CommandPath())
}
return nil
} | go | func NoArgs(cmd *Command, args []string) error {
if len(args) > 0 {
return fmt.Errorf("unknown command %q for %q", args[0], cmd.CommandPath())
}
return nil
} | [
"func",
"NoArgs",
"(",
"cmd",
"*",
"Command",
",",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"if",
"len",
"(",
"args",
")",
">",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"args",
"[",
"0",
"]",
",",
"cmd",
".",
"Com... | // NoArgs returns an error if any args are included. | [
"NoArgs",
"returns",
"an",
"error",
"if",
"any",
"args",
"are",
"included",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/args.go#L27-L32 |
127,278 | spf13/cobra | args.go | OnlyValidArgs | func OnlyValidArgs(cmd *Command, args []string) error {
if len(cmd.ValidArgs) > 0 {
for _, v := range args {
if !stringInSlice(v, cmd.ValidArgs) {
return fmt.Errorf("invalid argument %q for %q%s", v, cmd.CommandPath(), cmd.findSuggestions(args[0]))
}
}
}
return nil
} | go | func OnlyValidArgs(cmd *Command, args []string) error {
if len(cmd.ValidArgs) > 0 {
for _, v := range args {
if !stringInSlice(v, cmd.ValidArgs) {
return fmt.Errorf("invalid argument %q for %q%s", v, cmd.CommandPath(), cmd.findSuggestions(args[0]))
}
}
}
return nil
} | [
"func",
"OnlyValidArgs",
"(",
"cmd",
"*",
"Command",
",",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"if",
"len",
"(",
"cmd",
".",
"ValidArgs",
")",
">",
"0",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"args",
"{",
"if",
"!",
"stringInSlice",
... | // OnlyValidArgs returns an error if any args are not in the list of ValidArgs. | [
"OnlyValidArgs",
"returns",
"an",
"error",
"if",
"any",
"args",
"are",
"not",
"in",
"the",
"list",
"of",
"ValidArgs",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/args.go#L35-L44 |
127,279 | spf13/cobra | args.go | MinimumNArgs | func MinimumNArgs(n int) PositionalArgs {
return func(cmd *Command, args []string) error {
if len(args) < n {
return fmt.Errorf("requires at least %d arg(s), only received %d", n, len(args))
}
return nil
}
} | go | func MinimumNArgs(n int) PositionalArgs {
return func(cmd *Command, args []string) error {
if len(args) < n {
return fmt.Errorf("requires at least %d arg(s), only received %d", n, len(args))
}
return nil
}
} | [
"func",
"MinimumNArgs",
"(",
"n",
"int",
")",
"PositionalArgs",
"{",
"return",
"func",
"(",
"cmd",
"*",
"Command",
",",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"if",
"len",
"(",
"args",
")",
"<",
"n",
"{",
"return",
"fmt",
".",
"Errorf",
"("... | // MinimumNArgs returns an error if there is not at least N args. | [
"MinimumNArgs",
"returns",
"an",
"error",
"if",
"there",
"is",
"not",
"at",
"least",
"N",
"args",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/args.go#L52-L59 |
127,280 | spf13/cobra | args.go | ExactValidArgs | func ExactValidArgs(n int) PositionalArgs {
return func(cmd *Command, args []string) error {
if err := ExactArgs(n)(cmd, args); err != nil {
return err
}
return OnlyValidArgs(cmd, args)
}
} | go | func ExactValidArgs(n int) PositionalArgs {
return func(cmd *Command, args []string) error {
if err := ExactArgs(n)(cmd, args); err != nil {
return err
}
return OnlyValidArgs(cmd, args)
}
} | [
"func",
"ExactValidArgs",
"(",
"n",
"int",
")",
"PositionalArgs",
"{",
"return",
"func",
"(",
"cmd",
"*",
"Command",
",",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"if",
"err",
":=",
"ExactArgs",
"(",
"n",
")",
"(",
"cmd",
",",
"args",
")",
";... | // ExactValidArgs returns an error if
// there are not exactly N positional args OR
// there are any positional args that are not in the `ValidArgs` field of `Command` | [
"ExactValidArgs",
"returns",
"an",
"error",
"if",
"there",
"are",
"not",
"exactly",
"N",
"positional",
"args",
"OR",
"there",
"are",
"any",
"positional",
"args",
"that",
"are",
"not",
"in",
"the",
"ValidArgs",
"field",
"of",
"Command"
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/args.go#L84-L91 |
127,281 | spf13/cobra | args.go | RangeArgs | func RangeArgs(min int, max int) PositionalArgs {
return func(cmd *Command, args []string) error {
if len(args) < min || len(args) > max {
return fmt.Errorf("accepts between %d and %d arg(s), received %d", min, max, len(args))
}
return nil
}
} | go | func RangeArgs(min int, max int) PositionalArgs {
return func(cmd *Command, args []string) error {
if len(args) < min || len(args) > max {
return fmt.Errorf("accepts between %d and %d arg(s), received %d", min, max, len(args))
}
return nil
}
} | [
"func",
"RangeArgs",
"(",
"min",
"int",
",",
"max",
"int",
")",
"PositionalArgs",
"{",
"return",
"func",
"(",
"cmd",
"*",
"Command",
",",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"if",
"len",
"(",
"args",
")",
"<",
"min",
"||",
"len",
"(",
... | // RangeArgs returns an error if the number of args is not within the expected range. | [
"RangeArgs",
"returns",
"an",
"error",
"if",
"the",
"number",
"of",
"args",
"is",
"not",
"within",
"the",
"expected",
"range",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/args.go#L94-L101 |
127,282 | spf13/cobra | cobra/cmd/project.go | NewProject | func NewProject(projectName string) *Project {
if projectName == "" {
er("can't create project with blank name")
}
p := new(Project)
p.name = projectName
// 1. Find already created protect.
p.absPath = findPackage(projectName)
// 2. If there are no created project with this path, and user is in GOPATH,
// ... | go | func NewProject(projectName string) *Project {
if projectName == "" {
er("can't create project with blank name")
}
p := new(Project)
p.name = projectName
// 1. Find already created protect.
p.absPath = findPackage(projectName)
// 2. If there are no created project with this path, and user is in GOPATH,
// ... | [
"func",
"NewProject",
"(",
"projectName",
"string",
")",
"*",
"Project",
"{",
"if",
"projectName",
"==",
"\"",
"\"",
"{",
"er",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"p",
":=",
"new",
"(",
"Project",
")",
"\n",
"p",
".",
"name",
"=",
"projectNam... | // NewProject returns Project with specified project name. | [
"NewProject",
"returns",
"Project",
"with",
"specified",
"project",
"name",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/cobra/cmd/project.go#L20-L53 |
127,283 | spf13/cobra | cobra/cmd/project.go | findPackage | func findPackage(packageName string) string {
if packageName == "" {
return ""
}
for _, srcPath := range srcPaths {
packagePath := filepath.Join(srcPath, packageName)
if exists(packagePath) {
return packagePath
}
}
return ""
} | go | func findPackage(packageName string) string {
if packageName == "" {
return ""
}
for _, srcPath := range srcPaths {
packagePath := filepath.Join(srcPath, packageName)
if exists(packagePath) {
return packagePath
}
}
return ""
} | [
"func",
"findPackage",
"(",
"packageName",
"string",
")",
"string",
"{",
"if",
"packageName",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"srcPath",
":=",
"range",
"srcPaths",
"{",
"packagePath",
":=",
"filepath",
"."... | // findPackage returns full path to existing go package in GOPATHs. | [
"findPackage",
"returns",
"full",
"path",
"to",
"existing",
"go",
"package",
"in",
"GOPATHs",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/cobra/cmd/project.go#L56-L69 |
127,284 | spf13/cobra | cobra/cmd/project.go | NewProjectFromPath | func NewProjectFromPath(absPath string) *Project {
if absPath == "" {
er("can't create project: absPath can't be blank")
}
if !filepath.IsAbs(absPath) {
er("can't create project: absPath is not absolute")
}
// If absPath is symlink, use its destination.
fi, err := os.Lstat(absPath)
if err != nil {
er("can... | go | func NewProjectFromPath(absPath string) *Project {
if absPath == "" {
er("can't create project: absPath can't be blank")
}
if !filepath.IsAbs(absPath) {
er("can't create project: absPath is not absolute")
}
// If absPath is symlink, use its destination.
fi, err := os.Lstat(absPath)
if err != nil {
er("can... | [
"func",
"NewProjectFromPath",
"(",
"absPath",
"string",
")",
"*",
"Project",
"{",
"if",
"absPath",
"==",
"\"",
"\"",
"{",
"er",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"filepath",
".",
"IsAbs",
"(",
"absPath",
")",
"{",
"er",
"(",
"\"",
... | // NewProjectFromPath returns Project with specified absolute path to
// package. | [
"NewProjectFromPath",
"returns",
"Project",
"with",
"specified",
"absolute",
"path",
"to",
"package",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/cobra/cmd/project.go#L73-L98 |
127,285 | spf13/cobra | cobra/cmd/project.go | trimSrcPath | func trimSrcPath(absPath, srcPath string) string {
relPath, err := filepath.Rel(srcPath, absPath)
if err != nil {
er(err)
}
return relPath
} | go | func trimSrcPath(absPath, srcPath string) string {
relPath, err := filepath.Rel(srcPath, absPath)
if err != nil {
er(err)
}
return relPath
} | [
"func",
"trimSrcPath",
"(",
"absPath",
",",
"srcPath",
"string",
")",
"string",
"{",
"relPath",
",",
"err",
":=",
"filepath",
".",
"Rel",
"(",
"srcPath",
",",
"absPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"er",
"(",
"err",
")",
"\n",
"}",
"\... | // trimSrcPath trims at the beginning of absPath the srcPath. | [
"trimSrcPath",
"trims",
"at",
"the",
"beginning",
"of",
"absPath",
"the",
"srcPath",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/cobra/cmd/project.go#L101-L107 |
127,286 | spf13/cobra | cobra/cmd/project.go | License | func (p *Project) License() License {
if p.license.Text == "" && p.license.Name != "None" {
p.license = getLicense()
}
return p.license
} | go | func (p *Project) License() License {
if p.license.Text == "" && p.license.Name != "None" {
p.license = getLicense()
}
return p.license
} | [
"func",
"(",
"p",
"*",
"Project",
")",
"License",
"(",
")",
"License",
"{",
"if",
"p",
".",
"license",
".",
"Text",
"==",
"\"",
"\"",
"&&",
"p",
".",
"license",
".",
"Name",
"!=",
"\"",
"\"",
"{",
"p",
".",
"license",
"=",
"getLicense",
"(",
")... | // License returns the License object of project. | [
"License",
"returns",
"the",
"License",
"object",
"of",
"project",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/cobra/cmd/project.go#L110-L115 |
127,287 | spf13/cobra | cobra/cmd/project.go | CmdPath | func (p *Project) CmdPath() string {
if p.absPath == "" {
return ""
}
if p.cmdPath == "" {
p.cmdPath = filepath.Join(p.absPath, findCmdDir(p.absPath))
}
return p.cmdPath
} | go | func (p *Project) CmdPath() string {
if p.absPath == "" {
return ""
}
if p.cmdPath == "" {
p.cmdPath = filepath.Join(p.absPath, findCmdDir(p.absPath))
}
return p.cmdPath
} | [
"func",
"(",
"p",
"*",
"Project",
")",
"CmdPath",
"(",
")",
"string",
"{",
"if",
"p",
".",
"absPath",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"p",
".",
"cmdPath",
"==",
"\"",
"\"",
"{",
"p",
".",
"cmdPath",
"=",
"f... | // CmdPath returns absolute path to directory, where all commands are located. | [
"CmdPath",
"returns",
"absolute",
"path",
"to",
"directory",
"where",
"all",
"commands",
"are",
"located",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/cobra/cmd/project.go#L123-L131 |
127,288 | spf13/cobra | cobra/cmd/project.go | findCmdDir | func findCmdDir(absPath string) string {
if !exists(absPath) || isEmpty(absPath) {
return "cmd"
}
if isCmdDir(absPath) {
return filepath.Base(absPath)
}
files, _ := filepath.Glob(filepath.Join(absPath, "c*"))
for _, file := range files {
if isCmdDir(file) {
return filepath.Base(file)
}
}
return "c... | go | func findCmdDir(absPath string) string {
if !exists(absPath) || isEmpty(absPath) {
return "cmd"
}
if isCmdDir(absPath) {
return filepath.Base(absPath)
}
files, _ := filepath.Glob(filepath.Join(absPath, "c*"))
for _, file := range files {
if isCmdDir(file) {
return filepath.Base(file)
}
}
return "c... | [
"func",
"findCmdDir",
"(",
"absPath",
"string",
")",
"string",
"{",
"if",
"!",
"exists",
"(",
"absPath",
")",
"||",
"isEmpty",
"(",
"absPath",
")",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"if",
"isCmdDir",
"(",
"absPath",
")",
"{",
"return",
"f... | // findCmdDir checks if base of absPath is cmd dir and returns it or
// looks for existing cmd dir in absPath. | [
"findCmdDir",
"checks",
"if",
"base",
"of",
"absPath",
"is",
"cmd",
"dir",
"and",
"returns",
"it",
"or",
"looks",
"for",
"existing",
"cmd",
"dir",
"in",
"absPath",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/cobra/cmd/project.go#L135-L152 |
127,289 | spf13/cobra | cobra/cmd/project.go | isCmdDir | func isCmdDir(name string) bool {
name = filepath.Base(name)
for _, cmdDir := range []string{"cmd", "cmds", "command", "commands"} {
if name == cmdDir {
return true
}
}
return false
} | go | func isCmdDir(name string) bool {
name = filepath.Base(name)
for _, cmdDir := range []string{"cmd", "cmds", "command", "commands"} {
if name == cmdDir {
return true
}
}
return false
} | [
"func",
"isCmdDir",
"(",
"name",
"string",
")",
"bool",
"{",
"name",
"=",
"filepath",
".",
"Base",
"(",
"name",
")",
"\n",
"for",
"_",
",",
"cmdDir",
":=",
"range",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"... | // isCmdDir checks if base of name is one of cmdDir. | [
"isCmdDir",
"checks",
"if",
"base",
"of",
"name",
"is",
"one",
"of",
"cmdDir",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/cobra/cmd/project.go#L155-L163 |
127,290 | spf13/cobra | cobra/cmd/licenses.go | findLicense | func findLicense(name string) License {
found := matchLicense(name)
if found == "" {
er("unknown license: " + name)
}
return Licenses[found]
} | go | func findLicense(name string) License {
found := matchLicense(name)
if found == "" {
er("unknown license: " + name)
}
return Licenses[found]
} | [
"func",
"findLicense",
"(",
"name",
"string",
")",
"License",
"{",
"found",
":=",
"matchLicense",
"(",
"name",
")",
"\n",
"if",
"found",
"==",
"\"",
"\"",
"{",
"er",
"(",
"\"",
"\"",
"+",
"name",
")",
"\n",
"}",
"\n",
"return",
"Licenses",
"[",
"fo... | // findLicense looks for License object of built-in licenses.
// If it didn't find license, then the app will be terminated and
// error will be printed. | [
"findLicense",
"looks",
"for",
"License",
"object",
"of",
"built",
"-",
"in",
"licenses",
".",
"If",
"it",
"didn",
"t",
"find",
"license",
"then",
"the",
"app",
"will",
"be",
"terminated",
"and",
"error",
"will",
"be",
"printed",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/cobra/cmd/licenses.go#L92-L98 |
127,291 | spf13/cobra | cobra/cmd/licenses.go | matchLicense | func matchLicense(name string) string {
if name == "" {
return ""
}
for key, lic := range Licenses {
for _, match := range lic.PossibleMatches {
if strings.EqualFold(name, match) {
return key
}
}
}
return ""
} | go | func matchLicense(name string) string {
if name == "" {
return ""
}
for key, lic := range Licenses {
for _, match := range lic.PossibleMatches {
if strings.EqualFold(name, match) {
return key
}
}
}
return ""
} | [
"func",
"matchLicense",
"(",
"name",
"string",
")",
"string",
"{",
"if",
"name",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"for",
"key",
",",
"lic",
":=",
"range",
"Licenses",
"{",
"for",
"_",
",",
"match",
":=",
"range",
"lic... | // matchLicense compares the given a license name
// to PossibleMatches of all built-in licenses.
// It returns blank string, if name is blank string or it didn't find
// then appropriate match to name. | [
"matchLicense",
"compares",
"the",
"given",
"a",
"license",
"name",
"to",
"PossibleMatches",
"of",
"all",
"built",
"-",
"in",
"licenses",
".",
"It",
"returns",
"blank",
"string",
"if",
"name",
"is",
"blank",
"string",
"or",
"it",
"didn",
"t",
"find",
"then... | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/cobra/cmd/licenses.go#L104-L118 |
127,292 | spf13/cobra | doc/yaml_docs.go | GenYamlTree | func GenYamlTree(cmd *cobra.Command, dir string) error {
identity := func(s string) string { return s }
emptyStr := func(s string) string { return "" }
return GenYamlTreeCustom(cmd, dir, emptyStr, identity)
} | go | func GenYamlTree(cmd *cobra.Command, dir string) error {
identity := func(s string) string { return s }
emptyStr := func(s string) string { return "" }
return GenYamlTreeCustom(cmd, dir, emptyStr, identity)
} | [
"func",
"GenYamlTree",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"dir",
"string",
")",
"error",
"{",
"identity",
":=",
"func",
"(",
"s",
"string",
")",
"string",
"{",
"return",
"s",
"}",
"\n",
"emptyStr",
":=",
"func",
"(",
"s",
"string",
")",
... | // GenYamlTree creates yaml structured ref files for this command and all descendants
// in the directory given. This function may not work
// correctly if your command names have `-` in them. If you have `cmd` with two
// subcmds, `sub` and `sub-third`, and `sub` has a subcommand called `third`
// it is undefined whic... | [
"GenYamlTree",
"creates",
"yaml",
"structured",
"ref",
"files",
"for",
"this",
"command",
"and",
"all",
"descendants",
"in",
"the",
"directory",
"given",
".",
"This",
"function",
"may",
"not",
"work",
"correctly",
"if",
"your",
"command",
"names",
"have",
"-",... | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/doc/yaml_docs.go#L51-L55 |
127,293 | spf13/cobra | doc/yaml_docs.go | GenYaml | func GenYaml(cmd *cobra.Command, w io.Writer) error {
return GenYamlCustom(cmd, w, func(s string) string { return s })
} | go | func GenYaml(cmd *cobra.Command, w io.Writer) error {
return GenYamlCustom(cmd, w, func(s string) string { return s })
} | [
"func",
"GenYaml",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"return",
"GenYamlCustom",
"(",
"cmd",
",",
"w",
",",
"func",
"(",
"s",
"string",
")",
"string",
"{",
"return",
"s",
"}",
")",
"\n",
"}... | // GenYaml creates yaml output. | [
"GenYaml",
"creates",
"yaml",
"output",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/doc/yaml_docs.go#L86-L88 |
127,294 | spf13/cobra | doc/yaml_docs.go | GenYamlCustom | func GenYamlCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) string) error {
cmd.InitDefaultHelpCmd()
cmd.InitDefaultHelpFlag()
yamlDoc := cmdDoc{}
yamlDoc.Name = cmd.CommandPath()
yamlDoc.Synopsis = forceMultiLine(cmd.Short)
yamlDoc.Description = forceMultiLine(cmd.Long)
if len(cmd.Example) >... | go | func GenYamlCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) string) error {
cmd.InitDefaultHelpCmd()
cmd.InitDefaultHelpFlag()
yamlDoc := cmdDoc{}
yamlDoc.Name = cmd.CommandPath()
yamlDoc.Synopsis = forceMultiLine(cmd.Short)
yamlDoc.Description = forceMultiLine(cmd.Long)
if len(cmd.Example) >... | [
"func",
"GenYamlCustom",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"w",
"io",
".",
"Writer",
",",
"linkHandler",
"func",
"(",
"string",
")",
"string",
")",
"error",
"{",
"cmd",
".",
"InitDefaultHelpCmd",
"(",
")",
"\n",
"cmd",
".",
"InitDefaultHelpF... | // GenYamlCustom creates custom yaml output. | [
"GenYamlCustom",
"creates",
"custom",
"yaml",
"output",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/doc/yaml_docs.go#L91-L141 |
127,295 | spf13/cobra | doc/md_docs.go | GenMarkdown | func GenMarkdown(cmd *cobra.Command, w io.Writer) error {
return GenMarkdownCustom(cmd, w, func(s string) string { return s })
} | go | func GenMarkdown(cmd *cobra.Command, w io.Writer) error {
return GenMarkdownCustom(cmd, w, func(s string) string { return s })
} | [
"func",
"GenMarkdown",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"return",
"GenMarkdownCustom",
"(",
"cmd",
",",
"w",
",",
"func",
"(",
"s",
"string",
")",
"string",
"{",
"return",
"s",
"}",
")",
"\... | // GenMarkdown creates markdown output. | [
"GenMarkdown",
"creates",
"markdown",
"output",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/doc/md_docs.go#L49-L51 |
127,296 | spf13/cobra | doc/md_docs.go | GenMarkdownCustom | func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) string) error {
cmd.InitDefaultHelpCmd()
cmd.InitDefaultHelpFlag()
buf := new(bytes.Buffer)
name := cmd.CommandPath()
short := cmd.Short
long := cmd.Long
if len(long) == 0 {
long = short
}
buf.WriteString("## " + name + "\n\n... | go | func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) string) error {
cmd.InitDefaultHelpCmd()
cmd.InitDefaultHelpFlag()
buf := new(bytes.Buffer)
name := cmd.CommandPath()
short := cmd.Short
long := cmd.Long
if len(long) == 0 {
long = short
}
buf.WriteString("## " + name + "\n\n... | [
"func",
"GenMarkdownCustom",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"w",
"io",
".",
"Writer",
",",
"linkHandler",
"func",
"(",
"string",
")",
"string",
")",
"error",
"{",
"cmd",
".",
"InitDefaultHelpCmd",
"(",
")",
"\n",
"cmd",
".",
"InitDefaultH... | // GenMarkdownCustom creates custom markdown output. | [
"GenMarkdownCustom",
"creates",
"custom",
"markdown",
"output",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/doc/md_docs.go#L54-L118 |
127,297 | spf13/cobra | zsh_completions.go | GenZshCompletionFile | func (c *Command) GenZshCompletionFile(filename string) error {
outFile, err := os.Create(filename)
if err != nil {
return err
}
defer outFile.Close()
return c.GenZshCompletion(outFile)
} | go | func (c *Command) GenZshCompletionFile(filename string) error {
outFile, err := os.Create(filename)
if err != nil {
return err
}
defer outFile.Close()
return c.GenZshCompletion(outFile)
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"GenZshCompletionFile",
"(",
"filename",
"string",
")",
"error",
"{",
"outFile",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n"... | // GenZshCompletionFile generates zsh completion file. | [
"GenZshCompletionFile",
"generates",
"zsh",
"completion",
"file",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/zsh_completions.go#L12-L20 |
127,298 | spf13/cobra | zsh_completions.go | GenZshCompletion | func (c *Command) GenZshCompletion(w io.Writer) error {
buf := new(bytes.Buffer)
writeHeader(buf, c)
maxDepth := maxDepth(c)
writeLevelMapping(buf, maxDepth)
writeLevelCases(buf, maxDepth, c)
_, err := buf.WriteTo(w)
return err
} | go | func (c *Command) GenZshCompletion(w io.Writer) error {
buf := new(bytes.Buffer)
writeHeader(buf, c)
maxDepth := maxDepth(c)
writeLevelMapping(buf, maxDepth)
writeLevelCases(buf, maxDepth, c)
_, err := buf.WriteTo(w)
return err
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"GenZshCompletion",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"buf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n\n",
"writeHeader",
"(",
"buf",
",",
"c",
")",
"\n",
"maxDepth",
":=",
"maxDepth",
... | // GenZshCompletion generates a zsh completion file and writes to the passed writer. | [
"GenZshCompletion",
"generates",
"a",
"zsh",
"completion",
"file",
"and",
"writes",
"to",
"the",
"passed",
"writer",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/zsh_completions.go#L23-L33 |
127,299 | spf13/cobra | doc/rest_docs.go | GenReST | func GenReST(cmd *cobra.Command, w io.Writer) error {
return GenReSTCustom(cmd, w, defaultLinkHandler)
} | go | func GenReST(cmd *cobra.Command, w io.Writer) error {
return GenReSTCustom(cmd, w, defaultLinkHandler)
} | [
"func",
"GenReST",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"return",
"GenReSTCustom",
"(",
"cmd",
",",
"w",
",",
"defaultLinkHandler",
")",
"\n",
"}"
] | // GenReST creates reStructured Text output. | [
"GenReST",
"creates",
"reStructured",
"Text",
"output",
"."
] | 67fc4837d267bc9bfd6e47f77783fcc3dffc68de | https://github.com/spf13/cobra/blob/67fc4837d267bc9bfd6e47f77783fcc3dffc68de/doc/rest_docs.go#L56-L58 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.