mirror of
https://github.com/docker/compose.git
synced 2026-08-04 14:47:40 +00:00
(re)attach to container after restart
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
4c592700ee
commit
9c4d8ab158
13 changed files with 199 additions and 54 deletions
|
|
@ -27,6 +27,7 @@ import (
|
|||
"github.com/spf13/pflag"
|
||||
|
||||
"github.com/docker/compose-cli/api/context/store"
|
||||
"github.com/docker/compose-cli/cli/formatter"
|
||||
)
|
||||
|
||||
// Warning is a global warning to be displayed to user on command failure
|
||||
|
|
@ -100,11 +101,13 @@ func (o *projectOptions) toProjectOptions() (*cli.ProjectOptions, error) {
|
|||
// Command returns the compose command with its child commands
|
||||
func Command(contextType string) *cobra.Command {
|
||||
opts := projectOptions{}
|
||||
var ansi string
|
||||
command := &cobra.Command{
|
||||
Short: "Docker Compose",
|
||||
Use: "compose",
|
||||
TraverseChildren: true,
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
formatter.SetANSIMode(ansi)
|
||||
if opts.WorkDir != "" {
|
||||
if opts.ProjectDir != "" {
|
||||
return errors.New(aec.Apply(`cannot specify DEPRECATED "--workdir" and "--project-directory". Please use only "--project-directory" instead.`, aec.RedF))
|
||||
|
|
@ -149,5 +152,6 @@ func Command(contextType string) *cobra.Command {
|
|||
}
|
||||
command.Flags().SetInterspersed(false)
|
||||
opts.addProjectFlags(command.Flags())
|
||||
command.Flags().StringVar(&ansi, "ansi", "auto", `Control when to print ANSI control characters ("never"|"always"|"auto")`)
|
||||
return command
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,10 @@ package formatter
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/mattn/go-isatty"
|
||||
)
|
||||
|
||||
var names = []string{
|
||||
|
|
@ -32,6 +35,36 @@ var names = []string{
|
|||
"white",
|
||||
}
|
||||
|
||||
const (
|
||||
// Never use ANSI codes
|
||||
Never = "never"
|
||||
|
||||
// Always use ANSI codes
|
||||
Always = "always"
|
||||
|
||||
// Auto detect terminal is a tty and can use ANSI codes
|
||||
Auto = "auto"
|
||||
)
|
||||
|
||||
// SetANSIMode configure formatter for colored output on ANSI-compliant console
|
||||
func SetANSIMode(ansi string) {
|
||||
if !useAnsi(ansi) {
|
||||
nextColor = func() colorFunc {
|
||||
return monochrome
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func useAnsi(ansi string) bool {
|
||||
switch ansi {
|
||||
case Always:
|
||||
return true
|
||||
case Auto:
|
||||
return isatty.IsTerminal(os.Stdout.Fd())
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// colorFunc use ANSI codes to render colored text on console
|
||||
type colorFunc func(s string) string
|
||||
|
||||
|
|
@ -53,6 +86,12 @@ func makeColorFunc(code string) colorFunc {
|
|||
}
|
||||
}
|
||||
|
||||
var nextColor func() colorFunc = rainbowColor
|
||||
|
||||
func rainbowColor() colorFunc {
|
||||
return <-loop
|
||||
}
|
||||
|
||||
var loop = make(chan colorFunc)
|
||||
|
||||
func init() {
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ func (l *logConsumer) Register(name string, id string) {
|
|||
func (l *logConsumer) register(name string, id string) *presenter {
|
||||
cf := monochrome
|
||||
if l.color {
|
||||
cf = <-loop
|
||||
cf = nextColor()
|
||||
}
|
||||
p := &presenter{
|
||||
colors: cf,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue