Skip to content

Commit ea6fa60

Browse files
committed
Moving variable near their usage location
1 parent 750a673 commit ea6fa60

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

internal/cli/monitor/monitor.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,6 @@ func runMonitorCmd(
9090
quiet = true
9191
}
9292

93-
var (
94-
inst *rpc.Instance
95-
profile *rpc.SketchProfile
96-
fqbn string
97-
defaultPort, defaultProtocol string
98-
)
99-
10093
// Flags takes maximum precedence over sketch.yaml
10194
// If {--port --fqbn --profile} are set we ignore the profile.
10295
// If both {--port --profile} are set we read the fqbn in the following order: profile -> default_fqbn -> discovery
@@ -111,9 +104,9 @@ func runMonitorCmd(
111104
)
112105
}
113106
sketch := resp.GetSketch()
114-
if sketch != nil {
115-
defaultPort, defaultProtocol = sketch.GetDefaultPort(), sketch.GetDefaultProtocol()
116-
}
107+
108+
var inst *rpc.Instance
109+
var profile *rpc.SketchProfile
117110
if fqbnArg.String() == "" {
118111
if profileArg.Get() == "" {
119112
inst, profile = instance.CreateAndInitWithProfile(ctx, srv, sketch.GetDefaultProfile().GetName(), sketchPath)
@@ -130,6 +123,7 @@ func runMonitorCmd(
130123
// 2. from profile
131124
// 3. from default_fqbn specified in the sketch.yaml
132125
// 4. try to detect from the port
126+
var fqbn string
133127
switch {
134128
case fqbnArg.String() != "":
135129
fqbn = fqbnArg.String()
@@ -141,6 +135,10 @@ func runMonitorCmd(
141135
fqbn, _, _ = portArgs.DetectFQBN(ctx, inst, srv)
142136
}
143137

138+
var defaultPort, defaultProtocol string
139+
if sketch != nil {
140+
defaultPort, defaultProtocol = sketch.GetDefaultPort(), sketch.GetDefaultProtocol()
141+
}
144142
portAddress, portProtocol, err := portArgs.GetPortAddressAndProtocol(ctx, inst, srv, defaultPort, defaultProtocol)
145143
if err != nil {
146144
feedback.FatalError(err, feedback.ErrGeneric)

0 commit comments

Comments
 (0)