MCPcopy
hub / github.com/docker/compose / AdaptCmd

Function AdaptCmd

cmd/compose/compose.go:107–131  ·  cmd/compose/compose.go::AdaptCmd

AdaptCmd adapt a CobraCommand func to cobra library

(fn CobraCommand)

Source from the content-addressed store, hash-verified

105
106// AdaptCmd adapt a CobraCommand func to cobra library
107func AdaptCmd(fn CobraCommand) func(cmd *cobra.Command, args []string) error {
108 return func(cmd *cobra.Command, args []string) error {
109 ctx, cancel := context.WithCancel(cmd.Context())
110
111 s := make(chan os.Signal, 1)
112 signal.Notify(s, syscall.SIGTERM, syscall.SIGINT)
113 go func() {
114 <-s
115 cancel()
116 signal.Stop(s)
117 close(s)
118 }()
119
120 err := fn(ctx, cmd, args)
121 if api.IsErrCanceled(err) || errors.Is(ctx.Err(), context.Canceled) {
122 err = dockercli.StatusError{
123 StatusCode: 130,
124 }
125 }
126 if display.Mode == display.ModeJSON {
127 err = makeJSONError(err)
128 }
129 return err
130 }
131}
132
133// Adapt a Command func to cobra library
134func Adapt(fn Command) func(cmd *cobra.Command, args []string) error {

Callers 8

copyCommandFunction · 0.85
upCommandFunction · 0.85
AdaptFunction · 0.85
watchCommandFunction · 0.85
buildCommandFunction · 0.85
runCommandFunction · 0.85
createCommandFunction · 0.85
downCommandFunction · 0.85

Calls 4

IsErrCanceledFunction · 0.92
makeJSONErrorFunction · 0.85
StopMethod · 0.65
ErrMethod · 0.65

Tested by

no test coverage detected