(cmd *cobra.Command, args []string)
| 26 | ) |
| 27 | |
| 28 | func appNeedsRootlessParentMain(cmd *cobra.Command, args []string) bool { |
| 29 | commands := []string{} |
| 30 | for tcmd := cmd; tcmd != nil; tcmd = tcmd.Parent() { |
| 31 | commands = append(commands, tcmd.Name()) |
| 32 | } |
| 33 | commands = strutil.ReverseStrSlice(commands) |
| 34 | |
| 35 | if !rootlessutil.IsRootlessParent() { |
| 36 | return false |
| 37 | } |
| 38 | if len(args) == 0 && cmd.HasSubCommands() { |
| 39 | return false |
| 40 | } |
| 41 | if len(commands) < 2 { |
| 42 | return true |
| 43 | } |
| 44 | switch commands[1] { |
| 45 | // completion, login, logout, version: false, because it shouldn't require the daemon to be running |
| 46 | // apparmor: false, because it requires the initial mount namespace to access /sys/kernel/security |
| 47 | // cp, compose cp: false, because it requires the initial mount namespace to inspect file owners |
| 48 | case "", "completion", "login", "logout", "apparmor", "cp", "version": |
| 49 | return false |
| 50 | case "container": |
| 51 | if len(commands) < 3 { |
| 52 | return true |
| 53 | } |
| 54 | switch commands[2] { |
| 55 | case "cp": |
| 56 | return false |
| 57 | } |
| 58 | case "compose": |
| 59 | if len(commands) < 3 { |
| 60 | return true |
| 61 | } |
| 62 | switch commands[2] { |
| 63 | case "cp": |
| 64 | return false |
| 65 | } |
| 66 | } |
| 67 | return true |
| 68 | } |
| 69 | |
| 70 | func addApparmorCommand(rootCmd *cobra.Command) { |
| 71 | rootCmd.AddCommand(apparmor.Command()) |
searching dependent graphs…