compose.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. /*
  2. Copyright 2020 Docker Compose CLI authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package compose
  14. import (
  15. "context"
  16. "errors"
  17. "fmt"
  18. "os"
  19. "os/signal"
  20. "path/filepath"
  21. "strconv"
  22. "strings"
  23. "syscall"
  24. "github.com/compose-spec/compose-go/v2/cli"
  25. "github.com/compose-spec/compose-go/v2/dotenv"
  26. "github.com/compose-spec/compose-go/v2/loader"
  27. "github.com/compose-spec/compose-go/v2/types"
  28. composegoutils "github.com/compose-spec/compose-go/v2/utils"
  29. "github.com/docker/buildx/util/logutil"
  30. dockercli "github.com/docker/cli/cli"
  31. "github.com/docker/cli/cli-plugins/manager"
  32. "github.com/docker/cli/cli/command"
  33. "github.com/docker/compose/v2/cmd/formatter"
  34. "github.com/docker/compose/v2/internal/tracing"
  35. "github.com/docker/compose/v2/pkg/api"
  36. "github.com/docker/compose/v2/pkg/compose"
  37. ui "github.com/docker/compose/v2/pkg/progress"
  38. "github.com/docker/compose/v2/pkg/remote"
  39. "github.com/docker/compose/v2/pkg/utils"
  40. buildkit "github.com/moby/buildkit/util/progress/progressui"
  41. "github.com/morikuni/aec"
  42. "github.com/sirupsen/logrus"
  43. "github.com/spf13/cobra"
  44. "github.com/spf13/pflag"
  45. )
  46. const (
  47. // ComposeParallelLimit set the limit running concurrent operation on docker engine
  48. ComposeParallelLimit = "COMPOSE_PARALLEL_LIMIT"
  49. // ComposeProjectName define the project name to be used, instead of guessing from parent directory
  50. ComposeProjectName = "COMPOSE_PROJECT_NAME"
  51. // ComposeCompatibility try to mimic compose v1 as much as possible
  52. ComposeCompatibility = "COMPOSE_COMPATIBILITY"
  53. // ComposeRemoveOrphans remove “orphaned" containers, i.e. containers tagged for current project but not declared as service
  54. ComposeRemoveOrphans = "COMPOSE_REMOVE_ORPHANS"
  55. // ComposeIgnoreOrphans ignore "orphaned" containers
  56. ComposeIgnoreOrphans = "COMPOSE_IGNORE_ORPHANS"
  57. // ComposeEnvFiles defines the env files to use if --env-file isn't used
  58. ComposeEnvFiles = "COMPOSE_ENV_FILES"
  59. )
  60. // Command defines a compose CLI command as a func with args
  61. type Command func(context.Context, []string) error
  62. // CobraCommand defines a cobra command function
  63. type CobraCommand func(context.Context, *cobra.Command, []string) error
  64. // AdaptCmd adapt a CobraCommand func to cobra library
  65. func AdaptCmd(fn CobraCommand) func(cmd *cobra.Command, args []string) error {
  66. return func(cmd *cobra.Command, args []string) error {
  67. ctx, cancel := context.WithCancel(cmd.Context())
  68. s := make(chan os.Signal, 1)
  69. signal.Notify(s, syscall.SIGTERM, syscall.SIGINT)
  70. go func() {
  71. <-s
  72. cancel()
  73. signal.Stop(s)
  74. close(s)
  75. }()
  76. err := fn(ctx, cmd, args)
  77. var composeErr compose.Error
  78. if api.IsErrCanceled(err) || errors.Is(ctx.Err(), context.Canceled) {
  79. err = dockercli.StatusError{
  80. StatusCode: 130,
  81. Status: compose.CanceledStatus,
  82. }
  83. }
  84. if errors.As(err, &composeErr) {
  85. err = dockercli.StatusError{
  86. StatusCode: composeErr.GetMetricsFailureCategory().ExitCode,
  87. Status: err.Error(),
  88. }
  89. }
  90. return err
  91. }
  92. }
  93. // Adapt a Command func to cobra library
  94. func Adapt(fn Command) func(cmd *cobra.Command, args []string) error {
  95. return AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error {
  96. return fn(ctx, args)
  97. })
  98. }
  99. type ProjectOptions struct {
  100. ProjectName string
  101. Profiles []string
  102. ConfigPaths []string
  103. WorkDir string
  104. ProjectDir string
  105. EnvFiles []string
  106. Compatibility bool
  107. Progress string
  108. Offline bool
  109. }
  110. // ProjectFunc does stuff within a types.Project
  111. type ProjectFunc func(ctx context.Context, project *types.Project) error
  112. // ProjectServicesFunc does stuff within a types.Project and a selection of services
  113. type ProjectServicesFunc func(ctx context.Context, project *types.Project, services []string) error
  114. // WithProject creates a cobra run command from a ProjectFunc based on configured project options and selected services
  115. func (o *ProjectOptions) WithProject(fn ProjectFunc, dockerCli command.Cli) func(cmd *cobra.Command, args []string) error {
  116. return o.WithServices(dockerCli, func(ctx context.Context, project *types.Project, services []string) error {
  117. return fn(ctx, project)
  118. })
  119. }
  120. // WithServices creates a cobra run command from a ProjectFunc based on configured project options and selected services
  121. func (o *ProjectOptions) WithServices(dockerCli command.Cli, fn ProjectServicesFunc) func(cmd *cobra.Command, args []string) error {
  122. return Adapt(func(ctx context.Context, args []string) error {
  123. options := []cli.ProjectOptionsFn{
  124. cli.WithResolvedPaths(true),
  125. cli.WithDiscardEnvFile,
  126. }
  127. project, metrics, err := o.ToProject(ctx, dockerCli, args, options...)
  128. if err != nil {
  129. return err
  130. }
  131. ctx = context.WithValue(ctx, tracing.MetricsKey{}, metrics)
  132. return fn(ctx, project, args)
  133. })
  134. }
  135. func (o *ProjectOptions) addProjectFlags(f *pflag.FlagSet) {
  136. f.StringArrayVar(&o.Profiles, "profile", []string{}, "Specify a profile to enable")
  137. f.StringVarP(&o.ProjectName, "project-name", "p", "", "Project name")
  138. f.StringArrayVarP(&o.ConfigPaths, "file", "f", []string{}, "Compose configuration files")
  139. f.StringArrayVar(&o.EnvFiles, "env-file", nil, "Specify an alternate environment file")
  140. f.StringVar(&o.ProjectDir, "project-directory", "", "Specify an alternate working directory\n(default: the path of the, first specified, Compose file)")
  141. f.StringVar(&o.WorkDir, "workdir", "", "DEPRECATED! USE --project-directory INSTEAD.\nSpecify an alternate working directory\n(default: the path of the, first specified, Compose file)")
  142. f.BoolVar(&o.Compatibility, "compatibility", false, "Run compose in backward compatibility mode")
  143. f.StringVar(&o.Progress, "progress", string(buildkit.AutoMode), fmt.Sprintf(`Set type of progress output (%s)`, strings.Join(printerModes, ", ")))
  144. _ = f.MarkHidden("workdir")
  145. }
  146. func (o *ProjectOptions) projectOrName(ctx context.Context, dockerCli command.Cli, services ...string) (*types.Project, string, error) {
  147. name := o.ProjectName
  148. var project *types.Project
  149. if len(o.ConfigPaths) > 0 || o.ProjectName == "" {
  150. p, _, err := o.ToProject(ctx, dockerCli, services, cli.WithDiscardEnvFile)
  151. if err != nil {
  152. envProjectName := os.Getenv(ComposeProjectName)
  153. if envProjectName != "" {
  154. return nil, envProjectName, nil
  155. }
  156. return nil, "", err
  157. }
  158. project = p
  159. name = p.Name
  160. }
  161. return project, name, nil
  162. }
  163. func (o *ProjectOptions) toProjectName(ctx context.Context, dockerCli command.Cli) (string, error) {
  164. if o.ProjectName != "" {
  165. return o.ProjectName, nil
  166. }
  167. envProjectName := os.Getenv(ComposeProjectName)
  168. if envProjectName != "" {
  169. return envProjectName, nil
  170. }
  171. project, _, err := o.ToProject(ctx, dockerCli, nil)
  172. if err != nil {
  173. return "", err
  174. }
  175. return project.Name, nil
  176. }
  177. func (o *ProjectOptions) ToModel(ctx context.Context, dockerCli command.Cli, services []string, po ...cli.ProjectOptionsFn) (map[string]any, error) {
  178. remotes := o.remoteLoaders(dockerCli)
  179. for _, r := range remotes {
  180. po = append(po, cli.WithResourceLoader(r))
  181. }
  182. options, err := o.toProjectOptions(po...)
  183. if err != nil {
  184. return nil, err
  185. }
  186. if o.Compatibility || utils.StringToBool(options.Environment[ComposeCompatibility]) {
  187. api.Separator = "_"
  188. }
  189. return options.LoadModel(ctx)
  190. }
  191. func (o *ProjectOptions) ToProject(ctx context.Context, dockerCli command.Cli, services []string, po ...cli.ProjectOptionsFn) (*types.Project, tracing.Metrics, error) {
  192. var metrics tracing.Metrics
  193. remotes := o.remoteLoaders(dockerCli)
  194. for _, r := range remotes {
  195. po = append(po, cli.WithResourceLoader(r))
  196. }
  197. options, err := o.toProjectOptions(po...)
  198. if err != nil {
  199. return nil, metrics, compose.WrapComposeError(err)
  200. }
  201. options.WithListeners(func(event string, metadata map[string]any) {
  202. switch event {
  203. case "extends":
  204. metrics.CountExtends++
  205. case "include":
  206. paths := metadata["path"].(types.StringList)
  207. for _, path := range paths {
  208. var isRemote bool
  209. for _, r := range remotes {
  210. if r.Accept(path) {
  211. isRemote = true
  212. break
  213. }
  214. }
  215. if isRemote {
  216. metrics.CountIncludesRemote++
  217. } else {
  218. metrics.CountIncludesLocal++
  219. }
  220. }
  221. }
  222. })
  223. if o.Compatibility || utils.StringToBool(options.Environment[ComposeCompatibility]) {
  224. api.Separator = "_"
  225. }
  226. project, err := options.LoadProject(ctx)
  227. if err != nil {
  228. return nil, metrics, compose.WrapComposeError(err)
  229. }
  230. if project.Name == "" {
  231. return nil, metrics, errors.New("project name can't be empty. Use `--project-name` to set a valid name")
  232. }
  233. project, err = project.WithServicesEnabled(services...)
  234. if err != nil {
  235. return nil, metrics, err
  236. }
  237. for name, s := range project.Services {
  238. s.CustomLabels = map[string]string{
  239. api.ProjectLabel: project.Name,
  240. api.ServiceLabel: name,
  241. api.VersionLabel: api.ComposeVersion,
  242. api.WorkingDirLabel: project.WorkingDir,
  243. api.ConfigFilesLabel: strings.Join(project.ComposeFiles, ","),
  244. api.OneoffLabel: "False", // default, will be overridden by `run` command
  245. }
  246. if len(o.EnvFiles) != 0 {
  247. s.CustomLabels[api.EnvironmentFileLabel] = strings.Join(o.EnvFiles, ",")
  248. }
  249. project.Services[name] = s
  250. }
  251. project = project.WithoutUnnecessaryResources()
  252. project, err = project.WithSelectedServices(services)
  253. return project, metrics, err
  254. }
  255. func (o *ProjectOptions) remoteLoaders(dockerCli command.Cli) []loader.ResourceLoader {
  256. if o.Offline {
  257. return nil
  258. }
  259. git := remote.NewGitRemoteLoader(o.Offline)
  260. oci := remote.NewOCIRemoteLoader(dockerCli, o.Offline)
  261. return []loader.ResourceLoader{git, oci}
  262. }
  263. func (o *ProjectOptions) toProjectOptions(po ...cli.ProjectOptionsFn) (*cli.ProjectOptions, error) {
  264. return cli.NewProjectOptions(o.ConfigPaths,
  265. append(po,
  266. cli.WithWorkingDirectory(o.ProjectDir),
  267. cli.WithOsEnv,
  268. cli.WithConfigFileEnv,
  269. cli.WithDefaultConfigPath,
  270. cli.WithEnvFiles(o.EnvFiles...),
  271. cli.WithDotEnv,
  272. cli.WithDefaultProfiles(o.Profiles...),
  273. cli.WithName(o.ProjectName))...)
  274. }
  275. // PluginName is the name of the plugin
  276. const PluginName = "compose"
  277. // RunningAsStandalone detects when running as a standalone program
  278. func RunningAsStandalone() bool {
  279. return len(os.Args) < 2 || os.Args[1] != manager.MetadataSubcommandName && os.Args[1] != PluginName
  280. }
  281. // RootCommand returns the compose command with its child commands
  282. func RootCommand(dockerCli command.Cli, backend api.Service) *cobra.Command { //nolint:gocyclo
  283. // filter out useless commandConn.CloseWrite warning message that can occur
  284. // when using a remote context that is unreachable: "commandConn.CloseWrite: commandconn: failed to wait: signal: killed"
  285. // https://github.com/docker/cli/blob/e1f24d3c93df6752d3c27c8d61d18260f141310c/cli/connhelper/commandconn/commandconn.go#L203-L215
  286. logrus.AddHook(logutil.NewFilter([]logrus.Level{
  287. logrus.WarnLevel,
  288. },
  289. "commandConn.CloseWrite:",
  290. "commandConn.CloseRead:",
  291. ))
  292. opts := ProjectOptions{}
  293. var (
  294. ansi string
  295. noAnsi bool
  296. verbose bool
  297. version bool
  298. parallel int
  299. dryRun bool
  300. )
  301. c := &cobra.Command{
  302. Short: "Docker Compose",
  303. Long: "Define and run multi-container applications with Docker",
  304. Use: PluginName,
  305. TraverseChildren: true,
  306. // By default (no Run/RunE in parent c) for typos in subcommands, cobra displays the help of parent c but exit(0) !
  307. RunE: func(cmd *cobra.Command, args []string) error {
  308. if len(args) == 0 {
  309. return cmd.Help()
  310. }
  311. if version {
  312. return versionCommand(dockerCli).Execute()
  313. }
  314. _ = cmd.Help()
  315. return dockercli.StatusError{
  316. StatusCode: compose.CommandSyntaxFailure.ExitCode,
  317. Status: fmt.Sprintf("unknown docker command: %q", "compose "+args[0]),
  318. }
  319. },
  320. PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
  321. err := setEnvWithDotEnv(&opts)
  322. if err != nil {
  323. return err
  324. }
  325. parent := cmd.Root()
  326. if parent != nil {
  327. parentPrerun := parent.PersistentPreRunE
  328. if parentPrerun != nil {
  329. err := parentPrerun(cmd, args)
  330. if err != nil {
  331. return err
  332. }
  333. }
  334. }
  335. if noAnsi {
  336. if ansi != "auto" {
  337. return errors.New(`cannot specify DEPRECATED "--no-ansi" and "--ansi". Please use only "--ansi"`)
  338. }
  339. ansi = "never"
  340. fmt.Fprint(os.Stderr, "option '--no-ansi' is DEPRECATED ! Please use '--ansi' instead.\n")
  341. }
  342. if verbose {
  343. logrus.SetLevel(logrus.TraceLevel)
  344. }
  345. if v, ok := os.LookupEnv("COMPOSE_ANSI"); ok && !cmd.Flags().Changed("ansi") {
  346. ansi = v
  347. }
  348. formatter.SetANSIMode(dockerCli, ansi)
  349. if noColor, ok := os.LookupEnv("NO_COLOR"); ok && noColor != "" {
  350. ui.NoColor()
  351. formatter.SetANSIMode(dockerCli, formatter.Never)
  352. }
  353. switch ansi {
  354. case "never":
  355. ui.Mode = ui.ModePlain
  356. case "always":
  357. ui.Mode = ui.ModeTTY
  358. }
  359. switch opts.Progress {
  360. case ui.ModeAuto:
  361. ui.Mode = ui.ModeAuto
  362. if ansi == "never" {
  363. ui.Mode = ui.ModePlain
  364. }
  365. case ui.ModeTTY:
  366. if ansi == "never" {
  367. return fmt.Errorf("can't use --progress tty while ANSI support is disabled")
  368. }
  369. ui.Mode = ui.ModeTTY
  370. case ui.ModePlain:
  371. if ansi == "always" {
  372. return fmt.Errorf("can't use --progress plain while ANSI support is forced")
  373. }
  374. ui.Mode = ui.ModePlain
  375. case ui.ModeQuiet, "none":
  376. ui.Mode = ui.ModeQuiet
  377. default:
  378. return fmt.Errorf("unsupported --progress value %q", opts.Progress)
  379. }
  380. if opts.WorkDir != "" {
  381. if opts.ProjectDir != "" {
  382. return errors.New(`cannot specify DEPRECATED "--workdir" and "--project-directory". Please use only "--project-directory" instead`)
  383. }
  384. opts.ProjectDir = opts.WorkDir
  385. fmt.Fprint(os.Stderr, aec.Apply("option '--workdir' is DEPRECATED at root level! Please use '--project-directory' instead.\n", aec.RedF))
  386. }
  387. for i, file := range opts.EnvFiles {
  388. if !filepath.IsAbs(file) {
  389. file, err = filepath.Abs(file)
  390. if err != nil {
  391. return err
  392. }
  393. opts.EnvFiles[i] = file
  394. }
  395. }
  396. composeCmd := cmd
  397. for {
  398. if composeCmd.Name() == PluginName {
  399. break
  400. }
  401. if !composeCmd.HasParent() {
  402. return fmt.Errorf("error parsing command line, expected %q", PluginName)
  403. }
  404. composeCmd = composeCmd.Parent()
  405. }
  406. if v, ok := os.LookupEnv(ComposeParallelLimit); ok && !composeCmd.Flags().Changed("parallel") {
  407. i, err := strconv.Atoi(v)
  408. if err != nil {
  409. return fmt.Errorf("%s must be an integer (found: %q)", ComposeParallelLimit, v)
  410. }
  411. parallel = i
  412. }
  413. if parallel > 0 {
  414. backend.MaxConcurrency(parallel)
  415. }
  416. ctx, err := backend.DryRunMode(cmd.Context(), dryRun)
  417. if err != nil {
  418. return err
  419. }
  420. cmd.SetContext(ctx)
  421. return nil
  422. },
  423. }
  424. c.AddCommand(
  425. upCommand(&opts, dockerCli, backend),
  426. downCommand(&opts, dockerCli, backend),
  427. startCommand(&opts, dockerCli, backend),
  428. restartCommand(&opts, dockerCli, backend),
  429. stopCommand(&opts, dockerCli, backend),
  430. psCommand(&opts, dockerCli, backend),
  431. listCommand(dockerCli, backend),
  432. logsCommand(&opts, dockerCli, backend),
  433. configCommand(&opts, dockerCli),
  434. killCommand(&opts, dockerCli, backend),
  435. runCommand(&opts, dockerCli, backend),
  436. removeCommand(&opts, dockerCli, backend),
  437. execCommand(&opts, dockerCli, backend),
  438. attachCommand(&opts, dockerCli, backend),
  439. pauseCommand(&opts, dockerCli, backend),
  440. unpauseCommand(&opts, dockerCli, backend),
  441. topCommand(&opts, dockerCli, backend),
  442. eventsCommand(&opts, dockerCli, backend),
  443. portCommand(&opts, dockerCli, backend),
  444. imagesCommand(&opts, dockerCli, backend),
  445. versionCommand(dockerCli),
  446. buildCommand(&opts, dockerCli, backend),
  447. pushCommand(&opts, dockerCli, backend),
  448. pullCommand(&opts, dockerCli, backend),
  449. createCommand(&opts, dockerCli, backend),
  450. copyCommand(&opts, dockerCli, backend),
  451. waitCommand(&opts, dockerCli, backend),
  452. scaleCommand(&opts, dockerCli, backend),
  453. statsCommand(&opts, dockerCli),
  454. watchCommand(&opts, dockerCli, backend),
  455. alphaCommand(&opts, dockerCli, backend),
  456. )
  457. c.Flags().SetInterspersed(false)
  458. opts.addProjectFlags(c.Flags())
  459. c.RegisterFlagCompletionFunc( //nolint:errcheck
  460. "project-name",
  461. completeProjectNames(backend),
  462. )
  463. c.RegisterFlagCompletionFunc( //nolint:errcheck
  464. "project-directory",
  465. func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
  466. return []string{}, cobra.ShellCompDirectiveFilterDirs
  467. },
  468. )
  469. c.RegisterFlagCompletionFunc( //nolint:errcheck
  470. "file",
  471. func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
  472. return []string{"yaml", "yml"}, cobra.ShellCompDirectiveFilterFileExt
  473. },
  474. )
  475. c.RegisterFlagCompletionFunc( //nolint:errcheck
  476. "profile",
  477. completeProfileNames(dockerCli, &opts),
  478. )
  479. c.Flags().StringVar(&ansi, "ansi", "auto", `Control when to print ANSI control characters ("never"|"always"|"auto")`)
  480. c.Flags().IntVar(&parallel, "parallel", -1, `Control max parallelism, -1 for unlimited`)
  481. c.Flags().BoolVarP(&version, "version", "v", false, "Show the Docker Compose version information")
  482. c.PersistentFlags().BoolVar(&dryRun, "dry-run", false, "Execute command in dry run mode")
  483. c.Flags().MarkHidden("version") //nolint:errcheck
  484. c.Flags().BoolVar(&noAnsi, "no-ansi", false, `Do not print ANSI control characters (DEPRECATED)`)
  485. c.Flags().MarkHidden("no-ansi") //nolint:errcheck
  486. c.Flags().BoolVar(&verbose, "verbose", false, "Show more output")
  487. c.Flags().MarkHidden("verbose") //nolint:errcheck
  488. return c
  489. }
  490. func setEnvWithDotEnv(prjOpts *ProjectOptions) error {
  491. if len(prjOpts.EnvFiles) == 0 {
  492. if envFiles := os.Getenv(ComposeEnvFiles); envFiles != "" {
  493. prjOpts.EnvFiles = strings.Split(envFiles, ",")
  494. }
  495. }
  496. options, err := prjOpts.toProjectOptions()
  497. if err != nil {
  498. return compose.WrapComposeError(err)
  499. }
  500. envFromFile, err := dotenv.GetEnvFromFile(composegoutils.GetAsEqualsMap(os.Environ()), options.EnvFiles)
  501. if err != nil {
  502. return err
  503. }
  504. for k, v := range envFromFile {
  505. if _, ok := os.LookupEnv(k); !ok { // Precedence to OS Env
  506. if err := os.Setenv(k, v); err != nil {
  507. return err
  508. }
  509. }
  510. }
  511. return nil
  512. }
  513. var printerModes = []string{
  514. ui.ModeAuto,
  515. ui.ModeTTY,
  516. ui.ModePlain,
  517. ui.ModeQuiet,
  518. }