// Bash-completion command that prints a list of available services as all
// arguments
351179
func (c *ServicedCli) printServicesAll(ctx *cli.Context) {
	args := ctx.Args()
	svcs := c.services()

	// If arg is a service don't add to the list
	for _, s := range svcs {
		for _, a := range args {
			if s == a {
				goto next
			}
		}
		fmt.Println(s)
	next:
	}
	return
}
1318312
func (o *PruneDeploymentsOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []string) error {
	if len(args) > 0 {
		return kcmdutil.UsageErrorf(cmd, "no arguments are allowed to this command")
	}

	o.Namespace = metav1.NamespaceAll
	if cmd.Flags().Lookup("namespace").Changed {
		var err error
		o.Namespace, _, err = f.ToRawKubeConfigLoader().Namespace()
		if err != nil {
			return err
		}
	}

	clientConfig, err := f.ToRESTConfig()
	if err != nil {
		return err
	}
	o.KubeClient, err = corev1client.NewForConfig(clientConfig)
	if err != nil {
		return err
	}
	o.AppsClient, err = appsv1client.NewForConfig(clientConfig)
	if err != nil {
		return err
	}

	return nil
}
453762
func (c *ServicedCli) initService() {

	c.app.Commands = append(c.app.Commands, cli.Command{
		Name:        "service",
		Usage:       "Administers services",
		Description: "",
		Subcommands: []cli.Command{
			{
				Name:         "list",
				Usage:        "Lists all services",
				Description:  "serviced service list [SERVICEID]",
				BashComplete: c.printServicesFirst,
				Action:       c.cmdServiceList,
				Flags: []cli.Flag{
					cli.BoolFlag{
						Name:  "verbose, v",
						Usage: "Show JSON format",
					},
					cli.BoolFlag{
						Name:  "ascii, a",
						Usage: "use ascii characters for service tree (env SERVICED_TREE_ASCII=1 will default to ascii)",
					},
					cli.StringFlag{
						Name:  "format",
						Value: "",
						Usage: "format the output using the given go template",
					},
					cli.StringFlag{
						Name:  "show-fields",
						Value: "Name,ServiceID,Inst,ImageID,Pool,DState,Launch,DepID",
						Usage: "Comma-delimited list describing which fields to display",
					},
					cli.BoolFlag{
						Name:  "no-prefix-match, np",
						Usage: "Make SERVICEID matches on name strict 'ends with' matches",
					},
				},
			}, {
				Name:        "status",
				Usage:       "Displays the status of deployed services",
				Description: "serviced service status { SERVICEID | SERVICENAME | [POOL/]...PARENTNAME.../SERVICENAME }",
				Action:      c.cmdServiceStatus,
				Flags: []cli.Flag{
					cli.BoolFlag{
						Name:  "ascii, a",
						Usage: "use ascii characters for service tree (env SERVICED_TREE_ASCII=1 will default to ascii)",
					},
					cli.StringFlag{
						Name:  "show-fields",
						Value: "Name,ServiceID,Status,HC Fail,Healthcheck,Healthcheck Status,Uptime,RAM,Cur/Max/Avg,Hostname,InSync,DockerID",
						Usage: "Comma-delimited list describing which fields to display",
					},
					cli.BoolFlag{
						Name:  "no-prefix-match, np",
						Usage: "Make SERVICEID matches on name strict 'ends with' matches",
					},
				},
			}, {
				Name:        "add",
				Usage:       "Adds a new service",
				Description: "serviced service add NAME IMAGEID COMMAND",
				Action:      c.cmdServiceAdd,
				Flags: []cli.Flag{
					cli.GenericFlag{
						Name:  "p",
						Value: &api.PortMap{},
						Usage: "Expose a port for this service (e.g. -p tcp:3306:mysql)",
					},
					cli.GenericFlag{
						Name:  "q",
						Value: &api.PortMap{},
						Usage: "Map a remote service port (e.g. -q tcp:3306:mysql)",
					},
					cli.StringFlag{
						Name:  "parent-id",
						Value: "",
						Usage: "Parent service ID for which this service relates",
					},
				},
			}, {
				Name:        "clone",
				Usage:       "Clones a new service",
				Description: "serviced service clone { SERVICEID | SERVICENAME | [DEPLOYMENTID/]...PARENTNAME.../SERVICENAME }",
				Action:      c.cmdServiceClone,
				Flags: []cli.Flag{
					cli.StringFlag{
						Name:  "suffix",
						Value: "",
						Usage: "name to append to service name, volumes, endpoints",
					},
					cli.BoolFlag{
						Name:  "no-prefix-match, np",
						Usage: "Make SERVICEID matches on name strict 'ends with' matches",
					},
				},
			}, {
				Name:         "remove",
				ShortName:    "rm",
				Usage:        "Removes an existing service",
				Description:  "serviced service remove SERVICEID",
				BashComplete: c.printServicesAll,
				Action:       c.cmdServiceRemove,
				Flags: []cli.Flag{
					cli.BoolFlag{
						Name:  "no-prefix-match, np",
						Usage: "Make SERVICEID matches on name strict 'ends with' matches",
					},
				},
			}, {
				Name:         "edit",
				Usage:        "Edits an existing service in a text editor",
				Description:  "serviced service edit SERVICEID",
				BashComplete: c.printServicesFirst,
				Action:       c.cmdServiceEdit,
				Flags: []cli.Flag{
					cli.StringFlag{
						Name:  "editor, e",
						Value: os.Getenv("EDITOR"),
						Usage: "Editor used to update the service definition",
					},
					cli.BoolFlag{
						Name:  "no-prefix-match, np",
						Usage: "Make SERVICEID matches on name strict 'ends with' matches",
					},
				},
			}, {
				Name:         "assign-ip",
				Usage:        "Assigns an IP address to a service's endpoints requiring an explicit IP address",
				Description:  "serviced service assign-ip SERVICEID [IPADDRESS]",
				BashComplete: c.printServicesFirst,
				Action:       c.cmdServiceAssignIP,
				Flags: []cli.Flag{
					cli.BoolFlag{
						Name:  "no-prefix-match, np",
						Usage: "Make SERVICEID matches on name strict 'ends with' matches",
					},
				},
			}, {
				Name:         "start",
				Usage:        "Starts one or more services",
				Description:  "serviced service start SERVICEID ...",
				BashComplete: c.printServicesFirst,
				Action:       c.cmdServiceStart,
				Flags: []cli.Flag{
					cli.BoolTFlag{
						Name:  "auto-launch",
						Usage: "Recursively schedules child services",
					},
					cli.BoolFlag{
						Name:  "sync, s",
						Usage: "Schedules services synchronously",
					},
					cli.BoolFlag{
						Name:  "no-prefix-match, np",
						Usage: "Make SERVICEID matches on name strict 'ends with' matches",
					},
				},
			}, {
				Name:         "restart",
				Usage:        "Restarts one or more services",
				Description:  "serviced service restart { SERVICEID | INSTANCEID } ...",
				BashComplete: c.printServicesFirst,
				Action:       c.cmdServiceRestart,
				Flags: []cli.Flag{
					cli.BoolTFlag{
						Name:  "auto-launch",
						Usage: "Recursively schedules child services",
					},
					cli.BoolFlag{
						Name:  "sync, s",
						Usage: "Schedules services synchronously",
					},
					cli.BoolFlag{
						Name:  "rebalance",
						Usage: "Stops all instances before restarting them, instead of performing a rolling restart",
					},
					cli.BoolFlag{
						Name:  "no-prefix-match, np",
						Usage: "Make SERVICEID matches on name strict 'ends with' matches",
					},
				},
			}, {
				Name:         "stop",
				Usage:        "Stops one or more services",
				Description:  "serviced service stop SERVICEID ...",
				BashComplete: c.printServicesFirst,
				Action:       c.cmdServiceStop,
				Flags: []cli.Flag{
					cli.BoolTFlag{
						Name:  "auto-launch",
						Usage: "Recursively schedules child services",
					},
					cli.BoolFlag{
						Name:  "sync, s",
						Usage: "Schedules services synchronously",
					},
					cli.BoolFlag{
						Name:  "no-prefix-match, np",
						Usage: "Make SERVICEID matches on name strict 'ends with' matches",
					},
				},
			}, {
				Name:         "pause",
				Usage:        "Pauses one or more services",
				Description:  "serviced service pause SERVICEID ...",
				BashComplete: c.printServicesFirst,
				Action:       c.cmdServicePause,
				Flags: []cli.Flag{
					cli.BoolTFlag{
						Name:  "auto-launch",
						Usage: "Recursively schedules child services",
					},
					cli.BoolFlag{
						Name:  "sync, s",
						Usage: "Schedules services synchronously",
					},
					cli.BoolFlag{
						Name:  "no-prefix-match, np",
						Usage: "Make SERVICEID matches on name strict 'ends with' matches",
					},
				},
			}, {
				Name:         "shell",
				Usage:        "Starts a service instance",
				Description:  "serviced service shell SERVICEID [COMMAND]",
				BashComplete: c.printServicesFirst,
				Before:       c.cmdServiceShell,
				Flags: []cli.Flag{
					cli.StringFlag{
						Name:  "saveas, s",
						Value: "",
						Usage: "saves the service instance with the given name",
					},
					cli.BoolFlag{
						Name:  "interactive, i",
						Usage: "runs the service instance as a tty",
					},
					cli.StringSliceFlag{
						Name:  "mount",
						Value: &cli.StringSlice{},
						Usage: "bind mount: HOST_PATH[,CONTAINER_PATH]",
					},
					cli.BoolFlag{
						Name:  "no-prefix-match, np",
						Usage: "Make SERVICEID matches on name strict 'ends with' matches",
					},
				},
			}, {
				Name:         "run",
				Usage:        "Runs a service command in a service instance",
				Description:  "serviced service run SERVICEID COMMAND [ARGS]",
				BashComplete: c.printServiceRun,
				Before:       c.cmdServiceRun,
				Flags: []cli.Flag{
					cli.BoolFlag{
						Name:  "interactive, i",
						Usage: "runs the service instance as a tty",
					},
					cli.BoolFlag{
						Name:  "logtostderr",
						Usage: "enable/disable detailed serviced run logging (false by default)",
					},
					cli.BoolTFlag{
						Name:  "logstash",
						Usage: "enable/disable log stash (true by default)",
					},
					cli.StringFlag{
						Name:  "logstash-settle-time",
						Value: "5s",
						Usage: "time duration to wait for logstash to flush log messages before closing",
					},
					cli.StringSliceFlag{
						Name:  "mount",
						Value: &cli.StringSlice{},
						Usage: "bind mount: HOST_PATH[,CONTAINER_PATH]",
					},
					cli.StringFlag{
						Name:  "user",
						Value: "",
						Usage: "container username used to run command",
					},
					cli.BoolFlag{
						Name:  "no-prefix-match, np",
						Usage: "Make SERVICEID matches on name strict 'ends with' matches",
					},
				},
			}, {
				Name:         "attach",
				Usage:        "Run an arbitrary command in a running service container",
				Description:  "serviced service attach { SERVICEID | SERVICENAME | DEPLOYMENTID/...PARENTNAME.../SERVICENAME/INSTANCE } [COMMAND]",
				BashComplete: c.printServicesFirst,
				Before:       c.cmdServiceAttach,
				Flags: []cli.Flag{
					cli.BoolFlag{
						Name:  "no-prefix-match, np",
						Usage: "Make SERVICEID matches on name strict 'ends with' matches",
					},
				},
			}, {
				Name:         "action",
				Usage:        "Run a predefined action in a running service container",
				Description:  "serviced service action { SERVICEID | SERVICENAME | DEPLOYMENTID/...PARENTNAME.../SERVICENAME/INSTANCE } ACTION",
				BashComplete: c.printServicesFirst,
				Before:       c.cmdServiceAction,
				Flags: []cli.Flag{
					cli.BoolFlag{
						Name:  "no-prefix-match, np",
						Usage: "Make SERVICEID matches on name strict 'ends with' matches",
					},
				},
			}, {
				Name:         "logs",
				Usage:        "Output the logs of a running service container - calls docker logs",
				Description:  "serviced service logs { SERVICEID | SERVICENAME | DEPLOYMENTID/...PARENTNAME.../SERVICENAME/INSTANCE }",
				BashComplete: c.printServicesFirst,
				Before:       c.cmdServiceLogs,
				Flags: []cli.Flag{
					cli.BoolFlag{
						Name:  "no-prefix-match, np",
						Usage: "Make SERVICEID matches on name strict 'ends with' matches",
					},
				},
			}, {
				Name:         "list-snapshots",
				Usage:        "Lists the snapshots for a service",
				Description:  "serviced service list-snapshots SERVICEID",
				BashComplete: c.printServicesFirst,
				Action:       c.cmdServiceListSnapshots,
				Flags: []cli.Flag{
					cli.BoolFlag{
						Name:  "show-tags, t",
						Usage: "shows the tags associated with each snapshot",
					},
					cli.BoolFlag{
						Name:  "no-prefix-match, np",
						Usage: "Make SERVICEID matches on name strict 'ends with' matches",
					},
				},
			}, {
				Name:         "snapshot",
				Usage:        "Takes a snapshot of the service",
				Description:  "serviced service snapshot SERVICEID",
				BashComplete: c.printServicesFirst,
				Action:       c.cmdServiceSnapshot,
				Flags: []cli.Flag{
					cli.StringFlag{
						Name:  "description, d",
						Value: "",
						Usage: "a description of the snapshot",
					},
					cli.StringFlag{
						Name:  "tag, t",
						Value: "",
						Usage: "a unique tag for the snapshot",
					},
					cli.BoolFlag{
						Name:  "no-prefix-match, np",
						Usage: "Make SERVICEID matches on name strict 'ends with' matches",
					},
				},
			}, {
				Name:         "endpoints",
				Usage:        "List the endpoints defined for the service",
				Description:  "serviced service endpoints SERVICEID",
				BashComplete: c.printServicesFirst,
				Action:       c.cmdServiceEndpoints,
				Flags: []cli.Flag{
					cli.BoolFlag{
						Name:  "imports, i",
						Usage: "include only imported endpoints",
					},
					cli.BoolFlag{
						Name:  "all, a",
						Usage: "include all endpoints (imports and exports)",
					},
					cli.BoolFlag{
						Name:  "verify, v",
						Usage: "verify endpoints",
					},
					cli.BoolFlag{
						Name:  "no-prefix-match, np",
						Usage: "Make SERVICEID matches on name strict 'ends with' matches",
					},
				},
			}, {
				Name:        "public-endpoints",
				Usage:       "Manage public endpoints for a service",
				Description: "serviced service public-endpoints",
				Subcommands: []cli.Command{
					{
						Name:        "list",
						Usage:       "Lists public endpoints for a service",
						Description: "serviced service public-endpoints list [SERVICEID] [ENDPOINTNAME]",
						Action:      c.cmdPublicEndpointsListAll,
						Flags: []cli.Flag{
							cli.BoolFlag{
								Name:  "ascii, a",
								Usage: "use ascii characters for service tree (env SERVICED_TREE_ASCII=1 will default to ascii)",
							},
							cli.BoolFlag{
								Name:  "ports",
								Usage: "Show port public endpoints",
							},
							cli.BoolFlag{
								Name:  "vhosts",
								Usage: "Show vhost public endpoints",
							},
							cli.StringFlag{
								Name:  "show-fields",
								Value: "Service,ServiceID,Endpoint,Type,Protocol,Name,Enabled",
								Usage: "Comma-delimited list describing which fields to display",
							},
							cli.BoolFlag{
								Name:  "verbose, v",
								Usage: "Show JSON format",
							},
							cli.BoolFlag{
								Name:  "no-prefix-match, np",
								Usage: "Make SERVICEID matches on name strict 'ends with' matches",
							},
						},
					},
					{
						Name:        "port",
						Usage:       "Manages port public endpoints for a service",
						Description: "serviced service public-endpoints port",
						Subcommands: []cli.Command{
							{
								Name:        "list",
								Usage:       "List port public endpoints for a service",
								Description: "serviced service public-endpoints port list [SERVICEID] [ENDPOINTNAME]",
								Action:      c.cmdPublicEndpointsPortList,
								Flags: []cli.Flag{
									cli.BoolFlag{
										Name:  "ascii, a",
										Usage: "use ascii characters for service tree (env SERVICED_TREE_ASCII=1 will default to ascii)",
									},
									cli.StringFlag{
										Name:  "show-fields",
										Value: "Service,ServiceID,Endpoint,Type,Protocol,Name,Enabled",
										Usage: "Comma-delimited list describing which fields to display",
									},
									cli.BoolFlag{
										Name:  "verbose, v",
										Usage: "Show JSON format",
									},
									cli.BoolFlag{
										Name:  "no-prefix-match, np",
										Usage: "Make SERVICEID matches on name strict 'ends with' matches",
									},
								},
							},
							{
								Name:        "add",
								Usage:       "Add a port public endpoint to a service",
								Description: "serviced service public-endpoints port add <SERVICEID> <ENDPOINTNAME> <PORTADDR> <PROTOCOL> <ENABLED>",
								Action:      c.cmdPublicEndpointsPortAdd,
								Flags: []cli.Flag{
									cli.BoolFlag{
										Name:  "restart, r",
										Usage: "Restart the service after adding the port if the service is currently running",
									},
									cli.BoolFlag{
										Name:  "no-prefix-match, np",
										Usage: "Make SERVICEID matches on name strict 'ends with' matches",
									},
								},
							},
							{
								Name:        "remove",
								ShortName:   "rm",
								Usage:       "Remove a port public endpoint from a service",
								Description: "serviced service public-endpoints port remove <SERVICEID> <ENDPOINTNAME> <PORTADDR>",
								Action:      c.cmdPublicEndpointsPortRemove,
								Flags: []cli.Flag{
									cli.BoolFlag{
										Name:  "no-prefix-match, np",
										Usage: "Make SERVICEID matches on name strict 'ends with' matches",
									},
								},
							},
							{
								Name:        "enable",
								Usage:       "Enable/Disable a port public endpoint for a service",
								Description: "serviced service public-endpoints port enable <SERVICEID> <ENDPOINTNAME> <PORTADDR> true|false",
								Action:      c.cmdPublicEndpointsPortEnable,
								Flags: []cli.Flag{
									cli.BoolFlag{
										Name:  "no-prefix-match, np",
										Usage: "Make SERVICEID matches on name strict 'ends with' matches",
									},
								},
							},
						},
					},
					{
						Name:        "vhost",
						Usage:       "Manages vhost public endpoints for a service",
						Description: "serviced service public-endpoints vhost",
						Subcommands: []cli.Command{
							{
								Name:        "list",
								Usage:       "List vhost public endpoints for a service",
								Description: "serviced service public-endpoints vhost list [SERVICEID] [ENDPOINTNAME]",
								Action:      c.cmdPublicEndpointsVHostList,
								Flags: []cli.Flag{
									cli.BoolFlag{
										Name:  "ascii, a",
										Usage: "use ascii characters for service tree (env SERVICED_TREE_ASCII=1 will default to ascii)",
									},
									cli.StringFlag{
										Name:  "show-fields",
										Value: "Service,ServiceID,Endpoint,Type,Protocol,Name,Enabled",
										Usage: "Comma-delimited list describing which fields to display",
									},
									cli.BoolFlag{
										Name:  "verbose, v",
										Usage: "Show JSON format",
									},
									cli.BoolFlag{
										Name:  "no-prefix-match, np",
										Usage: "Make SERVICEID matches on name strict 'ends with' matches",
									},
								},
							},
							{
								Name:        "add",
								Usage:       "Add a vhost public endpoint to a service",
								Description: "serviced service public-endpoints vhost add <SERVICEID> <ENDPOINTNAME> <VHOST> <ENABLED>",
								Action:      c.cmdPublicEndpointsVHostAdd,
								Flags: []cli.Flag{
									cli.BoolFlag{
										Name:  "no-prefix-match, np",
										Usage: "Make SERVICEID matches on name strict 'ends with' matches",
									},
								},
							},
							{
								Name:        "remove",
								ShortName:   "rm",
								Usage:       "Remove a vhost public endpoint from a service",
								Description: "serviced service public-endpoints vhost remove <SERVICEID> <ENDPOINTNAME> <VHOST>",
								Action:      c.cmdPublicEndpointsVHostRemove,
								Flags: []cli.Flag{
									cli.BoolFlag{
										Name:  "no-prefix-match, np",
										Usage: "Make SERVICEID matches on name strict 'ends with' matches",
									},
								},
							},
							{
								Name:        "enable",
								Usage:       "Enable/Disable a vhost public endpoint for a service",
								Description: "serviced service public-endpoints vhost enable <SERVICEID> <ENDPOINTNAME> <VHOST> true|false",
								Action:      c.cmdPublicEndpointsVHostEnable,
								Flags: []cli.Flag{
									cli.BoolFlag{
										Name:  "no-prefix-match, np",
										Usage: "Make SERVICEID matches on name strict 'ends with' matches",
									},
								},
							},
						},
					},
				},
			},
			{
				Name:         "clear-emergency",
				Usage:        "Clears the 'emergency shutdown' state for a service and all child services",
				Description:  "serviced service clear-emergency { SERVICEID | SERVICENAME | DEPLOYMENTID/...PARENTNAME.../SERVICENAME }",
				BashComplete: c.printServicesFirst,
				Action:       c.cmdServiceClearEmergency,
				Flags: []cli.Flag{
					cli.BoolFlag{
						Name:  "no-prefix-match, np",
						Usage: "Make SERVICEID matches on name strict 'ends with' matches",
					},
				},
			},
			{
				Name:         "remove-ip",
				Usage:        "Remove the IP assignment of a service's endpoints",
				Description:  "serviced service remove-ip <SERVICEID> <ENDPOINTNAME>",
				BashComplete: c.printServicesFirst,
				Action:       c.cmdServiceRemoveIP,
				Flags: []cli.Flag{
					cli.BoolFlag{
						Name:  "no-prefix-match, np",
						Usage: "Make SERVICEID matches on name strict 'ends with' matches",
					},
				},
			},
			{
				Name:         "set-ip",
				Usage:        "Setting an IP address to a service's endpoints requiring an explicit IP address. If ip is not provided it does an automatic assignment",
				Description:  "serviced service set-ip <SERVICEID> <ENDPOINTNAME> [ADDRESS] [--port=PORT] [--proto=PROTOCOL]",
				BashComplete: c.printServicesFirst,
				Action:       c.cmdServiceSetIP,
				Flags: []cli.Flag{
					cli.IntFlag{
						Name:  "port",
						Usage: "determine the port your service will use",
					},
					cli.StringFlag{
						Name:  "proto",
						Usage: "determine the port protocol your service will use",
					},
					cli.BoolFlag{
						Name:  "no-prefix-match, np",
						Usage: "Make SERVICEID matches on name strict 'ends with' matches",
					},
				},
			},
			{
				Name:        "tune",
				Usage:       "Adjust instance count, RAM commitment, or RAM threshold for a service",
				Description: "serviced service tune SERVICEID",
				Action:      c.cmdServiceTune,
				Flags: []cli.Flag{
					cli.IntFlag{
						Name:  "instances",
						Usage: "Instance count for this service",
					},
					cli.StringFlag{
						Name:  "ramCommitment",
						Usage: "RAM Commitment for this service",
					},
					cli.StringFlag{
						Name:  "ramThreshold",
						Usage: "RAM Threshold for this service",
					},
					cli.BoolFlag{
						Name:  "no-prefix-match, np",
						Usage: "Make SERVICEID matches on name strict 'ends with' matches",
					},
				},
			},
			{
				Name:        "config",
				Usage:       "Manage config files for services",
				Description: "serviced service config",
				Subcommands: []cli.Command{
					{
						Name:        "list",
						Usage:       "List all config files for a given service, or the contents of one named file",
						Description: "serviced service config list SERVICEID [FILENAME]",
						Action:      c.cmdServiceConfigList,
						Flags: []cli.Flag{
							cli.BoolFlag{
								Name:  "no-prefix-match, np",
								Usage: "Make SERVICEID matches on name strict 'ends with' matches",
							},
						},
					},
					{
						Name:        "edit",
						Usage:       "Edit one config file for a given service",
						Description: "serviced service config edit SERVICEID FILENAME",
						Action:      c.cmdServiceConfigEdit,
						Flags: []cli.Flag{
							cli.StringFlag{
								Name:  "editor, e",
								Value: os.Getenv("EDITOR"),
								Usage: "Editor used to update the config file",
							},
							cli.BoolFlag{
								Name:  "no-prefix-match, np",
								Usage: "Make SERVICEID matches on name strict 'ends with' matches",
							},
						},
					},
				},
			},
			{
				Name:        "variable",
				Usage:       "Manage service config variables",
				Description: "serviced service variable",
				Subcommands: []cli.Command{
					{
						Name:        "list",
						Usage:       "List one or all config variables and their values for a given service",
						Description: "serviced service variable list SERVICEID",
						Action:      c.cmdServiceVariableList,
                                                Flags: []cli.Flag{
                                                        cli.BoolFlag{
                                                                Name:  "no-prefix-match, np",
                                                                Usage: "Make SERVICEID matches on name strict 'ends with' matches",
                                                        },
                                                },
					},
					{
						Name:        "get",
						Usage:       "Find the value of a config variable for a service",
						Description: "serviced service variable get SERVICEID VARIABLE",
						Action:      c.cmdServiceVariableGet,
                                                Flags: []cli.Flag{
                                                        cli.BoolFlag{
                                                                Name:  "no-prefix-match, np",
                                                                Usage: "Make SERVICEID matches on name strict 'ends with' matches",
                                                        },
                                                },
					},
					{
						Name:        "set",
						Usage:       "Add or update one variable's value for a given service",
						Description: "serviced service variable set SERVICEID VARIABLE VALUE",
						Action:      c.cmdServiceVariableSet,
                                                Flags: []cli.Flag{
                                                        cli.BoolFlag{
                                                                Name:  "no-prefix-match, np",
                                                                Usage: "Make SERVICEID matches on name strict 'ends with' matches",
                                                        },
                                                },
					},
					{
						Name:        "unset",
						Usage:       "Remove a variable from a given service",
						Description: "serviced service variable unset SERVICEID VARIABLE",
						Action:      c.cmdServiceVariableUnset,
                                                Flags: []cli.Flag{
                                                        cli.BoolFlag{
                                                                Name:  "no-prefix-match, np",
                                                                Usage: "Make SERVICEID matches on name strict 'ends with' matches",
                                                        },
                                                },
					},
				},
			},
		},
	})
}
764078
func (o *CreateBasicAuthSecretOptions) Complete(f kcmdutil.Factory, args []string) error {
	if len(args) != 1 {
		return errors.New("must have exactly one argument: secret name")
	}
	o.SecretName = args[0]

	if o.PromptForPassword {
		if len(o.Password) > 0 {
			return errors.New("must provide either --prompt or --password flag")
		}
		if !kterm.IsTerminal(o.In) {
			return errors.New("provided reader is not a terminal")
		}

		o.Password = term.PromptForPasswordString(o.In, o.Out, "Password: ")
		if len(o.Password) == 0 {
			return errors.New("password must be provided")
		}
	}

	namespace, _, err := f.ToRawKubeConfigLoader().Namespace()
	if err != nil {
		return err
	}
	config, err := f.ToRESTConfig()
	if err != nil {
		return err
	}
	clientset, err := corev1client.NewForConfig(config)
	if err != nil {
		return err
	}
	o.SecretsInterface = clientset.Secrets(namespace)

	o.Printer, err = o.PrintFlags.ToPrinter()
	if err != nil {
		return err
	}

	return nil
}
42894
func RunCompletion(out io.Writer, boilerPlate string, cmd *cobra.Command, args []string) error {
	if len(args) == 0 {
		return cmdutil.UsageErrorf(cmd, "Shell not specified.")
	}
	if len(args) > 1 {
		return cmdutil.UsageErrorf(cmd, "Too many arguments. Expected only the shell type.")
	}
	run, found := completionShells[args[0]]
	if !found {
		return cmdutil.UsageErrorf(cmd, "Unsupported shell type %q.", args[0])
	}

	return run(out, boilerPlate, cmd.Parent())
}
170356
func (s *Action) CompletionZSH(c *cli.Context, a *cli.App) error {
	comp, err := zshcomp.GetCompletion(a)
	if err != nil {
		return err
	}

	fmt.Fprintln(stdout, comp)
	return nil
}
14781
func (o *CanIOptions) Complete(f cmdutil.Factory, args []string) error {
	if o.List {
		if len(args) != 0 {
			return errors.New("list option must be specified with no arguments")
		}
	} else {
		if o.Quiet {
			o.Out = ioutil.Discard
		}

		switch len(args) {
		case 2:
			o.Verb = args[0]
			if strings.HasPrefix(args[1], "/") {
				o.NonResourceURL = args[1]
				break
			}
			resourceTokens := strings.SplitN(args[1], "/", 2)
			restMapper, err := f.ToRESTMapper()
			if err != nil {
				return err
			}
			o.Resource = o.resourceFor(restMapper, resourceTokens[0])
			if len(resourceTokens) > 1 {
				o.ResourceName = resourceTokens[1]
			}
		default:
			return errors.New("you must specify two or three arguments: verb, resource, and optional resourceName")
		}
	}

	var err error
	client, err := f.KubernetesClientSet()
	if err != nil {
		return err
	}
	o.AuthClient = client.AuthorizationV1()
	o.DiscoveryClient = client.Discovery()
	o.Namespace = ""
	if !o.AllNamespaces {
		o.Namespace, _, err = f.ToRawKubeConfigLoader().Namespace()
		if err != nil {
			return err
		}
	}

	return nil
}
215069
func (o *BuildOptions) Complete(baseName, commandName string, f kcmdutil.Factory, cmd *cobra.Command, args []string) error {
	err := o.ObjectGeneratorOptions.Complete(baseName, commandName, f, cmd, args)
	if err != nil {
		return err
	}

	if o.ObjectGeneratorOptions.Config.Dockerfile == "-" {
		data, err := ioutil.ReadAll(o.In)
		if err != nil {
			return err
		}
		o.ObjectGeneratorOptions.Config.Dockerfile = string(data)
	}

	return nil
}
84658
func (o *ObjectGeneratorOptions) Complete(baseName, commandName string, f kcmdutil.Factory, c *cobra.Command, args []string) error {
	cmdutil.WarnAboutCommaSeparation(o.ErrOut, o.Config.Environment, "--env")
	cmdutil.WarnAboutCommaSeparation(o.ErrOut, o.Config.BuildEnvironment, "--build-env")

	o.Action.IOStreams = o.IOStreams

	if o.PrintFlags.OutputFormat != nil {
		o.Action.Output = *o.PrintFlags.OutputFormat
	}

	// Only output="" should print descriptions of intermediate steps. Everything
	// else should print only some specific output (json, yaml, go-template, ...)
	o.Config.In = o.In
	if len(o.Action.Output) == 0 {
		o.Config.Out = o.Out
	} else {
		o.Config.Out = ioutil.Discard
	}
	o.Config.ErrOut = o.ErrOut

	clientConfig, err := f.ToRESTConfig()
	if err != nil {
		return err
	}
	mapper, err := f.ToRESTMapper()
	if err != nil {
		return err
	}
	dynamicClient, err := dynamic.NewForConfig(clientConfig)
	if err != nil {
		return err
	}

	o.Action.Bulk.Scheme = legacyscheme.Scheme
	o.Action.Bulk.Op = bulk.Creator{Client: dynamicClient, RESTMapper: mapper}.Create
	// Retry is used to support previous versions of the API server that will
	// consider the presence of an unknown trigger type to be an error.
	o.Action.Bulk.Retry = retryBuildConfig

	o.Config.DryRun = o.Action.DryRun
	o.CommandPath = c.CommandPath()
	o.BaseName = baseName
	o.CommandName = commandName

	o.LogsForObject = polymorphichelpers.LogsForObjectFn
	o.Printer, err = o.PrintFlags.ToPrinter()
	if err != nil {
		return err
	}

	if err := CompleteAppConfig(o.Config, f, c, args); err != nil {
		return err
	}
	if err := setAppConfigLabels(c, o.Config); err != nil {
		return err
	}
	return nil
}
1291677
func ListServices() ([]string, error) {
	// TODO(ericsnow) conn.ListUnits misses some inactive units, so we
	// would need conn.ListUnitFiles. Such a method has been requested.
	// (see https://github.com/coreos/go-systemd/issues/76). In the
	// meantime we use systemctl at the shell to list the services.
	// Once that is addressed upstream we can just call listServices here.
	names, err := Cmdline{}.ListAll()
	if err != nil {
		return nil, errors.Trace(err)
	}
	return names, nil
}
1045533
func (c *ServicedCli) cmdSnapshotList(ctx *cli.Context) {
	showTags := ctx.Bool("show-tags")
	var (
		snapshots []dao.SnapshotInfo
		err       error
	)
	if len(ctx.Args()) > 0 {
		serviceID := ctx.Args().First()
		if snapshots, err = c.driver.GetSnapshotsByServiceID(serviceID); err != nil {
			fmt.Fprintln(os.Stderr, err)
			return
		}
	} else {
		if snapshots, err = c.driver.GetSnapshots(); err != nil {
			fmt.Fprintln(os.Stderr, err)
			return
		}
	}

	if snapshots == nil || len(snapshots) == 0 {
		fmt.Fprintln(os.Stderr, "no snapshots found")
	} else {
		if showTags { //print a table of snapshot, description, tag list
			t := NewTable("Snapshot,Description,Tags")
			for _, s := range snapshots {
				//build a comma-delimited list of the tags
				tags := strings.Join(s.Tags, ",")
				snapshotID := s.SnapshotID
				if s.Invalid {
					snapshotID += " [DEPRECATED]"
				}

				//make the row and add it to the table
				row := make(map[string]interface{})
				row["Snapshot"] = snapshotID
				row["Description"] = s.Description
				row["Tags"] = tags
				t.Padding = 6
				t.AddRow(row)
			}
			//print the table
			t.Print()
		} else { //just print a list of snapshots
			for _, s := range snapshots {
				fmt.Println(s)
			}
		}
	}
	return
}
588563
func ListServices() ([]string, error) {
	fis, err := ioutil.ReadDir(InitDir)
	if err != nil {
		return nil, errors.Trace(err)
	}

	var services []string
	for _, fi := range fis {
		if groups := servicesRe.FindStringSubmatch(fi.Name()); len(groups) > 0 {
			services = append(services, groups[1])
		}
	}
	return services, nil
}
1324815
func (o *ServiceExternalNameOpts) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
	name, err := NameFromCommandArgs(cmd, args)
	if err != nil {
		return err
	}

	var generator generate.StructuredGenerator
	switch generatorName := cmdutil.GetFlagString(cmd, "generator"); generatorName {
	case generateversioned.ServiceExternalNameGeneratorV1Name:
		generator = &generateversioned.ServiceCommonGeneratorV1{
			Name:         name,
			Type:         v1.ServiceTypeExternalName,
			ExternalName: cmdutil.GetFlagString(cmd, "external-name"),
			ClusterIP:    "",
		}
	default:
		return errUnsupportedGenerator(cmd, generatorName)
	}

	return o.CreateSubcommandOptions.Complete(f, cmd, args, generator)
}
1139960
func (s *Action) CompletionBash(c *cli.Context) error {
	out := `_gopass_bash_autocomplete() {
     local cur opts base
     COMPREPLY=()
     cur="${COMP_WORDS[COMP_CWORD]}"
     opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )
     local IFS=$'\n'
     COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
     return 0
 }

`
	out += "complete -F _gopass_bash_autocomplete " + s.Name
	if runtime.GOOS == "windows" {
		out += "\ncomplete -F _gopass_bash_autocomplete " + s.Name + ".exe"
	}
	fmt.Fprintln(stdout, out)

	return nil
}
110482
func (c *ServicedCli) printServicesFirst(ctx *cli.Context) {
	if len(ctx.Args()) > 0 {
		return
	}
	fmt.Println(strings.Join(c.services(), "\n"))
}
651148
func (o *ServiceNodePortOpts) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
	name, err := NameFromCommandArgs(cmd, args)
	if err != nil {
		return err
	}

	var generator generate.StructuredGenerator
	switch generatorName := cmdutil.GetFlagString(cmd, "generator"); generatorName {
	case generateversioned.ServiceNodePortGeneratorV1Name:
		generator = &generateversioned.ServiceCommonGeneratorV1{
			Name:      name,
			TCP:       cmdutil.GetFlagStringSlice(cmd, "tcp"),
			Type:      v1.ServiceTypeNodePort,
			ClusterIP: "",
			NodePort:  cmdutil.GetFlagInt(cmd, "node-port"),
		}
	default:
		return errUnsupportedGenerator(cmd, generatorName)
	}

	return o.CreateSubcommandOptions.Complete(f, cmd, args, generator)
}
465906
func (o *DrainCmdOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
	var err error

	if len(args) == 0 && !cmd.Flags().Changed("selector") {
		return cmdutil.UsageErrorf(cmd, fmt.Sprintf("USAGE: %s [flags]", cmd.Use))
	}
	if len(args) > 0 && len(o.drainer.Selector) > 0 {
		return cmdutil.UsageErrorf(cmd, "error: cannot specify both a node name and a --selector option")
	}

	o.drainer.DryRun = cmdutil.GetDryRunFlag(cmd)

	if o.drainer.Client, err = f.KubernetesClientSet(); err != nil {
		return err
	}

	if len(o.drainer.PodSelector) > 0 {
		if _, err := labels.Parse(o.drainer.PodSelector); err != nil {
			return errors.New("--pod-selector=<pod_selector> must be a valid label selector")
		}
	}

	o.nodeInfos = []*resource.Info{}

	o.Namespace, _, err = f.ToRawKubeConfigLoader().Namespace()
	if err != nil {
		return err
	}

	o.ToPrinter = func(operation string) (printers.ResourcePrinterFunc, error) {
		o.PrintFlags.NamePrintFlags.Operation = operation
		if o.drainer.DryRun {
			o.PrintFlags.Complete("%s (dry run)")
		}

		printer, err := o.PrintFlags.ToPrinter()
		if err != nil {
			return nil, err
		}

		return printer.PrintObj, nil
	}

	builder := f.NewBuilder().
		WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...).
		NamespaceParam(o.Namespace).DefaultNamespace().
		ResourceNames("nodes", args...).
		SingleResourceType().
		Flatten()

	if len(o.drainer.Selector) > 0 {
		builder = builder.LabelSelectorParam(o.drainer.Selector).
			ResourceTypes("nodes")
	}

	r := builder.Do()

	if err = r.Err(); err != nil {
		return err
	}

	return r.Visit(func(info *resource.Info, err error) error {
		if err != nil {
			return err
		}
		if info.Mapping.Resource.GroupResource() != (schema.GroupResource{Group: "", Resource: "nodes"}) {
			return fmt.Errorf("error: expected resource of type node, got %q", info.Mapping.Resource)
		}

		o.nodeInfos = append(o.nodeInfos, info)
		return nil
	})
}