(p *ProjectOptions, dockerCli command.Cli, backendOptions *BackendOptions)
| 43 | } |
| 44 | |
| 45 | func logsCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *BackendOptions) *cobra.Command { |
| 46 | opts := logsOptions{ |
| 47 | ProjectOptions: p, |
| 48 | } |
| 49 | logsCmd := &cobra.Command{ |
| 50 | Use: "logs [OPTIONS] [SERVICE...]", |
| 51 | Short: "View output from containers", |
| 52 | RunE: Adapt(func(ctx context.Context, args []string) error { |
| 53 | return runLogs(ctx, dockerCli, backendOptions, opts, args) |
| 54 | }), |
| 55 | PreRunE: func(cmd *cobra.Command, args []string) error { |
| 56 | if opts.index > 0 && len(args) != 1 { |
| 57 | return errors.New("--index requires one service to be selected") |
| 58 | } |
| 59 | return nil |
| 60 | }, |
| 61 | ValidArgsFunction: completeServiceNames(dockerCli, p), |
| 62 | } |
| 63 | flags := logsCmd.Flags() |
| 64 | flags.BoolVarP(&opts.follow, "follow", "f", false, "Follow log output") |
| 65 | flags.SetAnnotation("follow", annotation.ExternalURL, []string{"https://docs.docker.com/reference/cli/docker/container/logs/#follow"}) //nolint:errcheck |
| 66 | flags.IntVar(&opts.index, "index", 0, "index of the container if service has multiple replicas") |
| 67 | flags.StringVar(&opts.since, "since", "", "Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)") |
| 68 | flags.SetAnnotation("since", annotation.ExternalURL, []string{"https://docs.docker.com/reference/cli/docker/container/logs/#since"}) //nolint:errcheck |
| 69 | flags.StringVar(&opts.until, "until", "", "Show logs before a timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)") |
| 70 | flags.SetAnnotation("until", annotation.ExternalURL, []string{"https://docs.docker.com/reference/cli/docker/container/logs/#until"}) //nolint:errcheck |
| 71 | flags.BoolVar(&opts.noColor, "no-color", false, "Produce monochrome output") |
| 72 | flags.BoolVar(&opts.noPrefix, "no-log-prefix", false, "Don't print prefix in logs") |
| 73 | flags.BoolVarP(&opts.timestamps, "timestamps", "t", false, "Show timestamps") |
| 74 | flags.SetAnnotation("timestamps", annotation.ExternalURL, []string{"https://docs.docker.com/reference/cli/docker/container/logs/#timestamps"}) //nolint:errcheck |
| 75 | flags.StringVarP(&opts.tail, "tail", "n", "all", "Number of lines to show from the end of the logs for each container") |
| 76 | flags.SetAnnotation("tail", annotation.ExternalURL, []string{"https://docs.docker.com/reference/cli/docker/container/logs/#tail"}) //nolint:errcheck |
| 77 | return logsCmd |
| 78 | } |
| 79 | |
| 80 | func runLogs(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOptions, opts logsOptions, services []string) error { |
| 81 | project, name, err := opts.projectOrName(ctx, dockerCli, services...) |
no test coverage detected