@@ -19,9 +19,9 @@ import (
19
19
20
20
func speedtest () * cobra.Command {
21
21
var (
22
- direct bool
23
- duration time.Duration
24
- reverse bool
22
+ direct bool
23
+ duration time.Duration
24
+ direction string
25
25
)
26
26
cmd := & cobra.Command {
27
27
Annotations : workspaceCommand ,
@@ -48,7 +48,7 @@ func speedtest() *cobra.Command {
48
48
return client .WorkspaceAgent (ctx , workspaceAgent .ID )
49
49
},
50
50
})
51
- if err != nil {
51
+ if err != nil && ! xerrors . Is ( err , cliui . AgentStartError ) {
52
52
return xerrors .Errorf ("await agent: %w" , err )
53
53
}
54
54
logger := slog .Make (sloghuman .Sink (cmd .ErrOrStderr ()))
@@ -94,25 +94,29 @@ func speedtest() *cobra.Command {
94
94
} else {
95
95
conn .AwaitReachable (ctx )
96
96
}
97
- dir := tsspeedtest .Download
98
- if reverse {
99
- dir = tsspeedtest .Upload
97
+ var tsDir tsspeedtest.Direction
98
+ switch direction {
99
+ case "up" :
100
+ tsDir = tsspeedtest .Upload
101
+ case "down" :
102
+ tsDir = tsspeedtest .Download
103
+ default :
104
+ return xerrors .Errorf ("invalid direction: %q" , direction )
100
105
}
101
- cmd .Printf ("Starting a %ds %s test...\n " , int (duration .Seconds ()), dir )
102
- results , err := conn .Speedtest (ctx , dir , duration )
106
+ cmd .Printf ("Starting a %ds %s test...\n " , int (duration .Seconds ()), tsDir )
107
+ results , err := conn .Speedtest (ctx , tsDir , duration )
103
108
if err != nil {
104
109
return err
105
110
}
106
111
tableWriter := cliui .Table ()
107
- tableWriter .AppendHeader (table.Row {"Interval" , "Transfer" , "Bandwidth " })
112
+ tableWriter .AppendHeader (table.Row {"Interval" , "Throughput " })
108
113
startTime := results [0 ].IntervalStart
109
114
for _ , r := range results {
110
115
if r .Total {
111
116
tableWriter .AppendSeparator ()
112
117
}
113
118
tableWriter .AppendRow (table.Row {
114
119
fmt .Sprintf ("%.2f-%.2f sec" , r .IntervalStart .Sub (startTime ).Seconds (), r .IntervalEnd .Sub (startTime ).Seconds ()),
115
- fmt .Sprintf ("%.4f MBits" , r .MegaBits ()),
116
120
fmt .Sprintf ("%.4f Mbits/sec" , r .MBitsPerSecond ()),
117
121
})
118
122
}
@@ -122,8 +126,9 @@ func speedtest() *cobra.Command {
122
126
}
123
127
cliflag .BoolVarP (cmd .Flags (), & direct , "direct" , "d" , "" , false ,
124
128
"Specifies whether to wait for a direct connection before testing speed." )
125
- cliflag .BoolVarP (cmd .Flags (), & reverse , "reverse" , "r" , "" , false ,
126
- "Specifies whether to run in reverse mode where the client receives and the server sends." )
129
+ cliflag .StringVarP (cmd .Flags (), & direction , "direction" , "" , "" , "down" ,
130
+ "Specifies whether to run in reverse mode where the client receives and the server sends. (up|down)" ,
131
+ )
127
132
cmd .Flags ().DurationVarP (& duration , "time" , "t" , tsspeedtest .DefaultDuration ,
128
133
"Specifies the duration to monitor traffic." )
129
134
return cmd
0 commit comments