contextValue traverses context and its ancestor contexts to find the flag value and returns string slice.
(c *cli.Context, flagname string)
| 31 | // contextValue traverses context and its ancestor contexts to find |
| 32 | // the flag value and returns string slice. |
| 33 | func 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. |
| 65 | func generateCommand(c *cli.Context, cmd string, defaultFlags map[string]interface{}, urls ...*url.URL) (string, error) { |
no test coverage detected