Skip to content

Commit 1fbe382

Browse files
markfisherglyn
authored andcommitted
add output option for function create
1 parent 66bf7b1 commit 1fbe382

File tree

1 file changed

+45
-14
lines changed

1 file changed

+45
-14
lines changed

cmd/commands/function.go

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ func Function() *cobra.Command {
3939

4040
func FunctionCreate(fcTool *core.Client) *cobra.Command {
4141

42-
createChannelOptions := core.CreateChannelOptions{}
42+
createInputChannelOptions := core.CreateChannelOptions{}
43+
createOutputChannelOptions := core.CreateChannelOptions{}
4344
createFunctionOptions := core.CreateFunctionOptions{}
4445
createSubscriptionOptions := core.CreateSubscriptionOptions{}
4546

@@ -51,7 +52,7 @@ func FunctionCreate(fcTool *core.Client) *cobra.Command {
5152

5253
command := &cobra.Command{
5354
Use: "create",
54-
Short: "Create a new function resource, with optional input binding",
55+
Short: "Create a new function resource, with optional input and output channels",
5556
Long: `Create a new function resource from the content of the provided Git repo/revision.
5657
5758
The INVOKER arg defines the language invoker that is added to the function code in the build step. The resulting image is
@@ -73,6 +74,7 @@ From then on you can use the sub-commands for the 'service' command to interact
7374
FlagsValidationConjunction(
7475
FlagsDependency(Set("input"), exactlyOneOfBusOrClusterBus),
7576
FlagsDependency(NotSet("input"), NoneOf("bus", "cluster-bus")),
77+
FlagsDependency(NotSet("input"), NoneOf("output")),
7678
),
7779
),
7880
RunE: func(cmd *cobra.Command, args []string) error {
@@ -93,12 +95,18 @@ From then on you can use the sub-commands for the 'service' command to interact
9395

9496
var c *v1alpha1.Channel
9597
var subscr *v1alpha1.Subscription
96-
if createChannelOptions.Name != "" {
97-
c, err = (*fcTool).CreateChannel(createChannelOptions)
98+
if createInputChannelOptions.Name != "" {
99+
c, err = (*fcTool).CreateChannel(createInputChannelOptions)
98100
if err != nil {
99101
return err
100102
}
101103

104+
if createOutputChannelOptions.Name != "" {
105+
c, err = (*fcTool).CreateChannel(createOutputChannelOptions)
106+
if err != nil {
107+
return err
108+
}
109+
}
102110
createSubscriptionOptions.Name = subscriptionNameFromService(fnName)
103111
createSubscriptionOptions.Subscriber = subscriberNameFromService(fnName)
104112
subscr, err = (*fcTool).CreateSubscription(createSubscriptionOptions)
@@ -135,38 +143,61 @@ From then on you can use the sub-commands for the 'service' command to interact
135143
command.Flags().VarP(
136144
BroadcastStringValue("",
137145
&createFunctionOptions.Namespace,
138-
&createChannelOptions.Namespace,
146+
&createInputChannelOptions.Namespace,
147+
&createOutputChannelOptions.Namespace,
139148
&createSubscriptionOptions.Namespace,
140149
),
141150
"namespace", "n", "the `namespace` of the subscription, channel, and function",
142151
)
143152

144153
command.Flags().VarP(
145154
BroadcastStringValue("",
146-
&createChannelOptions.Name,
155+
&createInputChannelOptions.Name,
147156
&createSubscriptionOptions.Channel,
148157
),
149158
"input", "i", "name of the function's input `channel`, if any",
150159
)
151160

161+
command.Flags().VarP(
162+
BroadcastStringValue("",
163+
&createOutputChannelOptions.Name,
164+
&createSubscriptionOptions.ReplyTo,
165+
),
166+
"output", "o", "name of the function's output `channel`, if any",
167+
)
168+
152169
command.Flags().VarPF(
153170
BroadcastBoolValue(false,
154171
&createFunctionOptions.DryRun,
155-
&createChannelOptions.DryRun,
172+
&createInputChannelOptions.DryRun,
173+
&createOutputChannelOptions.DryRun,
156174
&createSubscriptionOptions.DryRun,
157175
),
158176
"dry-run", "", dryRunUsage,
159177
).NoOptDefVal = "true"
160178

161-
command.Flags().VarPF(
162-
BroadcastBoolValue(false,
163-
&createFunctionOptions.Verbose,
179+
command.Flags().VarPF(
180+
BroadcastBoolValue(false,
181+
&createFunctionOptions.Verbose,
182+
),
183+
"verbose", "v", verboseUsage,
184+
).NoOptDefVal = "true"
185+
186+
command.Flags().Var(
187+
BroadcastStringValue("",
188+
&createInputChannelOptions.Bus,
189+
&createOutputChannelOptions.Bus,
164190
),
165-
"verbose", "v", verboseUsage,
166-
).NoOptDefVal = "true"
191+
"bus", busUsage,
192+
)
167193

168-
command.Flags().StringVar(&createChannelOptions.Bus, "bus", "", busUsage)
169-
command.Flags().StringVar(&createChannelOptions.ClusterBus, "cluster-bus", "", clusterBusUsage)
194+
command.Flags().Var(
195+
BroadcastStringValue("",
196+
&createInputChannelOptions.ClusterBus,
197+
&createOutputChannelOptions.ClusterBus,
198+
),
199+
"cluster-bus", clusterBusUsage,
200+
)
170201

171202
command.Flags().StringVar(&createFunctionOptions.Image, "image", "", "the name of the image to build; must be a writable `repository/image[:tag]` with credentials configured")
172203
command.MarkFlagRequired("image")

0 commit comments

Comments
 (0)