MCPcopy Index your code
hub / github.com/peak/s5cmd / contextValue

Function contextValue

command/context.go:33–62  ·  view source on GitHub ↗

contextValue traverses context and its ancestor contexts to find the flag value and returns string slice.

(c *cli.Context, flagname string)

Source from the content-addressed store, hash-verified

31// contextValue traverses context and its ancestor contexts to find
32// the flag value and returns string slice.
33func contextValue(c *cli.Context, flagname string) []string {
34 for _, c := range c.Lineage() {
35 if !c.IsSet(flagname) {
36 continue
37 }
38
39 val := c.Value(flagname)
40 switch val.(type) {
41 case cli.StringSlice:
42 return c.StringSlice(flagname)
43 case cli.Int64Slice, cli.IntSlice:
44 values := c.Int64Slice(flagname)
45 var result []string
46 for _, v := range values {
47 result = append(result, strconv.FormatInt(v, 10))
48 }
49 return result
50 case string:
51 return []string{c.String(flagname)}
52 case bool:
53 return []string{strconv.FormatBool(c.Bool(flagname))}
54 case int, int64:
55 return []string{strconv.FormatInt(c.Int64(flagname), 10)}
56 default:
57 return []string{fmt.Sprintf("%v", val)}
58 }
59 }
60
61 return nil
62}
63
64// generateCommand generates command string from given context, app command, default flags and urls.
65func generateCommand(c *cli.Context, cmd string, defaultFlags map[string]interface{}, urls ...*url.URL) (string, error) {

Callers 2

commandFromContextFunction · 0.85
generateCommandFunction · 0.85

Calls 2

IsSetMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected