Skip to content

Commit

Permalink
Fix typo
Browse files Browse the repository at this point in the history
Signed-off-by: Joana Hrotko <[email protected]>
  • Loading branch information
jhrotko committed Mar 22, 2024
1 parent 0c09cc9 commit 4ed8a30
Show file tree
Hide file tree
Showing 16 changed files with 220 additions and 145 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ RUN --mount=type=bind,target=. \
FROM build-base AS test
ARG CGO_ENABLED=0
ARG BUILD_TAGS
ENV COMPOSE_MENU=FALSE
RUN --mount=type=bind,target=. \
--mount=type=cache,target=/root/.cache \
--mount=type=cache,target=/go/pkg/mod \
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

PKG := github.com/docker/compose/v2
export COMPOSE_MENU = FALSE
VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.m' --always --tags)

GO_LDFLAGS ?= -w -X ${PKG}/internal.Version=${VERSION}
Expand Down
14 changes: 13 additions & 1 deletion cmd/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const (
ComposeIgnoreOrphans = "COMPOSE_IGNORE_ORPHANS"
// ComposeEnvFiles defines the env files to use if --env-file isn't used
ComposeEnvFiles = "COMPOSE_ENV_FILES"
// ComposeMenu defines if the navigation menu should be rendered. Can be also set via --navigation-menu
// ComposeMenu defines if the navigation menu should be rendered. Can be also set via --menu
ComposeMenu = "COMPOSE_MENU"
)

Expand Down Expand Up @@ -622,3 +622,15 @@ var printerModes = []string{
ui.ModePlain,
ui.ModeQuiet,
}

func SetUnchangedOption(name string, experimentalFlag bool) bool {
var value bool
// If the var is defined we use that value first
if envVar, ok := os.LookupEnv(name); ok {
value = utils.StringToBool(envVar)
} else {
// if not, we try to get it from experimental feature flag
value = experimentalFlag
}
return value
}
64 changes: 33 additions & 31 deletions cmd/compose/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,22 @@ type composeOptions struct {

type upOptions struct {
*composeOptions
Detach bool
noStart bool
noDeps bool
cascadeStop bool
exitCodeFrom string
noColor bool
noPrefix bool
attachDependencies bool
attach []string
noAttach []string
timestamp bool
wait bool
waitTimeout int
watch bool
navigationMenu bool
Detach bool
noStart bool
noDeps bool
cascadeStop bool
exitCodeFrom string
noColor bool
noPrefix bool
attachDependencies bool
attach []string
noAttach []string
timestamp bool
wait bool
waitTimeout int
watch bool
navigationMenu bool
navigationMenuChanged bool
}

func (opts upOptions) apply(project *types.Project, services []string) (*types.Project, error) {
Expand Down Expand Up @@ -88,6 +89,7 @@ func upCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service, ex
PreRunE: AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error {
create.pullChanged = cmd.Flags().Changed("pull")
create.timeChanged = cmd.Flags().Changed("timeout")
up.navigationMenuChanged = cmd.Flags().Changed("menu")
return validateFlags(&up, &create)
}),
RunE: p.WithServices(dockerCli, func(ctx context.Context, project *types.Project, services []string) error {
Expand Down Expand Up @@ -129,11 +131,8 @@ func upCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service, ex
flags.BoolVar(&up.wait, "wait", false, "Wait for services to be running|healthy. Implies detached mode.")
flags.IntVar(&up.waitTimeout, "wait-timeout", 0, "Maximum duration to wait for the project to be running|healthy")
flags.BoolVarP(&up.watch, "watch", "w", false, "Watch source code and rebuild/refresh containers when files are updated.")
composeMenu := true
if os.Getenv(ComposeMenu) != "" {
composeMenu = utils.StringToBool(os.Getenv(ComposeMenu))
}
flags.BoolVar(&up.navigationMenu, "navigation-menu", composeMenu, "While running in attach mode, enable shortcuts and shortcuts info bar.")
flags.BoolVar(&up.navigationMenu, "menu", false, "Enable interactive shortcuts when running attached (Experimental). Incompatible with --detach.")
flags.MarkHidden("menu") //nolint:errcheck

return upCmd
}
Expand Down Expand Up @@ -167,7 +166,7 @@ func runUp(
ctx context.Context,
dockerCli command.Cli,
backend api.Service,
_ *experimental.State,
experimentals *experimental.State,
createOptions createOptions,
upOptions upOptions,
buildOptions buildOptions,
Expand All @@ -187,6 +186,9 @@ func runUp(
if err != nil {
return err
}
if !upOptions.navigationMenuChanged {
upOptions.navigationMenu = SetUnchangedOption(ComposeMenu, experimentals.NavBar())
}

var build *api.BuildOptions
if !createOptions.noBuild {
Expand Down Expand Up @@ -259,16 +261,16 @@ func runUp(
return backend.Up(ctx, project, api.UpOptions{
Create: create,
Start: api.StartOptions{
Project: project,
Attach: consumer,
AttachTo: attach,
ExitCodeFrom: upOptions.exitCodeFrom,
CascadeStop: upOptions.cascadeStop,
Wait: upOptions.wait,
WaitTimeout: timeout,
Watch: upOptions.watch,
Services: services,
NavigationBar: upOptions.navigationMenu,
Project: project,
Attach: consumer,
AttachTo: attach,
ExitCodeFrom: upOptions.exitCodeFrom,
CascadeStop: upOptions.cascadeStop,
Wait: upOptions.wait,
WaitTimeout: timeout,
Watch: upOptions.watch,
Services: services,
NavigationMenu: upOptions.navigationMenu,
},
})
}
Expand Down
24 changes: 20 additions & 4 deletions cmd/formatter/colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ var names = []string{
"white",
}

const (
BOLD = "1"
FAINT = "2"
ITALIC = "3"
UNDERLINE = "4"
)

const (
RESET = "0"
CYAN = "36"
)

const (
// Never use ANSI codes
Never = "never"
Expand Down Expand Up @@ -72,13 +84,17 @@ var monochrome = func(s string) string {
return s
}

func ansiColor(code, s string) string {
return fmt.Sprintf("%s%s%s", ansiColorCode(code), s, ansiColorCode("0"))
func ansiColor(code, s string, formatOpts ...string) string {
return fmt.Sprintf("%s%s%s", ansiColorCode(code, formatOpts...), s, ansiColorCode("0"))
}

// Everything about ansiColorCode color https://hyperskill.org/learn/step/18193
func ansiColorCode(code string) string {
return fmt.Sprintf("\033[%sm", code)
func ansiColorCode(code string, formatOpts ...string) string {
res := "\033["
for _, c := range formatOpts {
res = fmt.Sprintf("%s%s;", res, c)
}
return fmt.Sprintf("%s%sm", res, code)
}

func makeColorFunc(code string) colorFunc {
Expand Down
11 changes: 6 additions & 5 deletions cmd/formatter/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,22 @@ func (l *logConsumer) write(w io.Writer, container, message string) {
if l.ctx.Err() != nil {
return
}
print := func() {
printFn := func() {
p := l.getPresenter(container)
timestamp := time.Now().Format(jsonmessage.RFC3339NanoFixed)
for _, line := range strings.Split(message, "\n") {
ClearLine()
if l.timestamp {
fmt.Fprintf(w, "\033[2K%s%s%s\n", p.prefix, timestamp, line)
fmt.Fprintf(w, "%s%s%s\n", p.prefix, timestamp, line)
} else {
fmt.Fprintf(w, "\033[2K%s%s\n", p.prefix, line)
fmt.Fprintf(w, "%s%s\n", p.prefix, line)
}
}
}
if KeyboardManager != nil {
KeyboardManager.PrintKeyboardInfo(print)
KeyboardManager.PrintKeyboardInfo(printFn)
} else {
print()
printFn()
}
}

Expand Down
Loading

0 comments on commit 4ed8a30

Please sign in to comment.