|
@@ -24,15 +24,18 @@ import (
|
|
|
|
|
|
|
|
"github.com/docker/compose-cli/api/client"
|
|
"github.com/docker/compose-cli/api/client"
|
|
|
"github.com/docker/compose-cli/api/compose"
|
|
"github.com/docker/compose-cli/api/compose"
|
|
|
|
|
+ "github.com/docker/compose-cli/api/context/store"
|
|
|
"github.com/docker/compose-cli/cli/formatter"
|
|
"github.com/docker/compose-cli/cli/formatter"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
type logsOptions struct {
|
|
type logsOptions struct {
|
|
|
*projectOptions
|
|
*projectOptions
|
|
|
composeOptions
|
|
composeOptions
|
|
|
|
|
+ follow bool
|
|
|
|
|
+ tail string
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func logsCommand(p *projectOptions) *cobra.Command {
|
|
|
|
|
|
|
+func logsCommand(p *projectOptions, contextType string) *cobra.Command {
|
|
|
opts := logsOptions{
|
|
opts := logsOptions{
|
|
|
projectOptions: p,
|
|
projectOptions: p,
|
|
|
}
|
|
}
|
|
@@ -43,6 +46,10 @@ func logsCommand(p *projectOptions) *cobra.Command {
|
|
|
return runLogs(cmd.Context(), opts, args)
|
|
return runLogs(cmd.Context(), opts, args)
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|
|
|
|
|
+ logsCmd.Flags().BoolVarP(&opts.follow, "follow", "f", false, "Follow log output.")
|
|
|
|
|
+ if contextType == store.DefaultContextType {
|
|
|
|
|
+ logsCmd.Flags().StringVar(&opts.tail, "tail", "all", "Number of lines to show from the end of the logs for each container.")
|
|
|
|
|
+ }
|
|
|
return logsCmd
|
|
return logsCmd
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -59,5 +66,7 @@ func runLogs(ctx context.Context, opts logsOptions, services []string) error {
|
|
|
consumer := formatter.NewLogConsumer(ctx, os.Stdout)
|
|
consumer := formatter.NewLogConsumer(ctx, os.Stdout)
|
|
|
return c.ComposeService().Logs(ctx, projectName, consumer, compose.LogOptions{
|
|
return c.ComposeService().Logs(ctx, projectName, consumer, compose.LogOptions{
|
|
|
Services: services,
|
|
Services: services,
|
|
|
|
|
+ Follow: opts.follow,
|
|
|
|
|
+ Tail: opts.tail,
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|