Skip to content

Commit d0880ab

Browse files
committed
refactor(sd): use run to start the program
This commit allows the `run servicedirectory` command to start the program and register services on Service Directory by using the `run` function. Signed-off-by: Elis Lulja <[email protected]>
1 parent 4947fbd commit d0880ab

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

pkg/command/run/service_directory.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func getRunServiceDirectoryCommand(runOpts *RunOptions, fileOptsFlags *fileOrK8s
5959
cmd := &cobra.Command{
6060
Use: "servicedirectory [COMMAND] [OPTIONS]",
6161
Aliases: []string{"sd", "google-service-directory", "with-service-directory"},
62-
Short: "Run the program with Google Service Directory",
62+
Short: "Run the program with Google Service Directory.",
6363
PreRunE: func(cmd *cobra.Command, args []string) error {
6464
if err := parseServiceDirectoryCommand(runOpts.ServiceDirectoryOptions, fileOptsFlags, cmd); err != nil {
6565
return fmt.Errorf("error while parsing service directory options: %w", err)
@@ -90,7 +90,7 @@ func getRunServiceDirectoryCommand(runOpts *RunOptions, fileOptsFlags *fileOrK8s
9090
RunE: func(_ *cobra.Command, _ []string) error {
9191
return runWithServiceDirectory(runOpts)
9292
},
93-
Example: "servicedirectory --project-id my-project-id default-region us-east1",
93+
Example: "servicedirectory --project-id my-project-id --default-region us-east1",
9494
}
9595

9696
// -----------------------------
@@ -176,6 +176,13 @@ func parseServiceDirectoryCommand(sdOpts *ServiceDirectoryOptions, flagOpts *fil
176176

177177
func runWithServiceDirectory(opts *RunOptions) error {
178178
sdOpts := opts.ServiceDirectoryOptions
179+
180+
// TODO: when #81 is solved an merged this will be replaced
181+
// with zerolog
182+
l := ctrl.Log.WithName("ServiceDirectory")
183+
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
184+
l.Info("starting...")
185+
179186
ctx, canc := context.WithTimeout(context.Background(), 15*time.Second)
180187
defer canc()
181188

@@ -187,21 +194,15 @@ func runWithServiceDirectory(opts *RunOptions) error {
187194

188195
defer cli.Close()
189196

190-
// TODO: when #81 is solved an merged this will be replaced
191-
// with zerolog
192-
l := ctrl.Log.WithName("ServiceDirectory")
193-
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
194-
197+
// TODO: the context should be given by the run function, or explicitly
198+
// provide a context for each call. This will be fixed with the new API.
195199
sr := &sd.Handler{
196200
ProjectID: sdOpts.ProjectID,
197201
DefaultRegion: sdOpts.DefaultRegion,
198202
Log: l,
199-
Context: ctx,
203+
Context: context.Background(),
200204
Client: cli,
201205
}
202206

203-
// TODO: use the handler (in next commits)
204-
_ = sr
205-
206-
return nil
207+
return run(sr, opts)
207208
}

0 commit comments

Comments
 (0)