Skip to content

Commit fc0153e

Browse files
feat: Generate log streaming
1 parent 9530856 commit fc0153e

File tree

4 files changed

+55
-55
lines changed

4 files changed

+55
-55
lines changed

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 18
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fhypeman-5058541cc0e298a6fc3e9cda1af0e32586d1f39c5666946e15f546c1aedc18ea.yml
3-
openapi_spec_hash: 7f572ac0c7f9dc4f5fc7d9883a53d6c7
4-
config_hash: 35db4c99791f175865381f13a8ad6075
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fhypeman-ce51f144a3d2de556750203edbaa5bfeefe874660737c35a4fc37dfb30057dd5.yml
3+
openapi_spec_hash: 27663b6503056317abcb578ac7b67c06
4+
config_hash: b4e65d240d7bca1ba6162ee2098c8ac2

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/charmbracelet/x/term v0.2.1
1010
github.com/itchyny/json2yaml v0.1.4
1111
github.com/muesli/reflow v0.3.0
12-
github.com/onkernel/hypeman-go v0.2.0
12+
github.com/onkernel/hypeman-go v0.3.0
1313
github.com/tidwall/gjson v1.18.0
1414
github.com/tidwall/pretty v1.2.1
1515
github.com/tidwall/sjson v1.2.5

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
4545
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
4646
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
4747
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
48-
github.com/onkernel/hypeman-go v0.2.0 h1:wiDMSi7eGTKfVfdxhCg8vcFKa6xbXjWG2sSHk7EXi4Y=
49-
github.com/onkernel/hypeman-go v0.2.0/go.mod h1:pxRRFfVcLvafZpDD1O6IjwHnem3hKEuZTCClrnGiIKA=
48+
github.com/onkernel/hypeman-go v0.3.0 h1:/wABYiIBEAOhx4rogpLa/Aibc0HTKcwPcPIZC6hms6Y=
49+
github.com/onkernel/hypeman-go v0.3.0/go.mod h1:pxRRFfVcLvafZpDD1O6IjwHnem3hKEuZTCClrnGiIKA=
5050
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
5151
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5252
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=

pkg/cmd/instance.go

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -81,48 +81,48 @@ var instancesDelete = cli.Command{
8181
HideHelpCommand: true,
8282
}
8383

84-
var instancesPutInStandby = cli.Command{
85-
Name: "put-in-standby",
86-
Usage: "Put instance in standby (pause, snapshot, delete VMM)",
84+
var instancesLogs = cli.Command{
85+
Name: "logs",
86+
Usage: "Streams instance console logs as Server-Sent Events. Returns the last N lines\n(controlled by `tail` parameter), then optionally continues streaming new lines\nif `follow=true`.",
8787
Flags: []cli.Flag{
8888
&cli.StringFlag{
8989
Name: "id",
9090
},
91+
&cli.BoolFlag{
92+
Name: "follow",
93+
Usage: "Continue streaming new lines after initial output",
94+
},
95+
&cli.Int64Flag{
96+
Name: "tail",
97+
Usage: "Number of lines to return from end",
98+
Value: 100,
99+
},
91100
},
92-
Action: handleInstancesPutInStandby,
101+
Action: handleInstancesLogs,
93102
HideHelpCommand: true,
94103
}
95104

96-
var instancesRestoreFromStandby = cli.Command{
97-
Name: "restore-from-standby",
98-
Usage: "Restore instance from standby",
105+
var instancesPutInStandby = cli.Command{
106+
Name: "put-in-standby",
107+
Usage: "Put instance in standby (pause, snapshot, delete VMM)",
99108
Flags: []cli.Flag{
100109
&cli.StringFlag{
101110
Name: "id",
102111
},
103112
},
104-
Action: handleInstancesRestoreFromStandby,
113+
Action: handleInstancesPutInStandby,
105114
HideHelpCommand: true,
106115
}
107116

108-
var instancesStreamLogs = cli.Command{
109-
Name: "stream-logs",
110-
Usage: "Stream instance logs (SSE)",
117+
var instancesRestoreFromStandby = cli.Command{
118+
Name: "restore-from-standby",
119+
Usage: "Restore instance from standby",
111120
Flags: []cli.Flag{
112121
&cli.StringFlag{
113122
Name: "id",
114123
},
115-
&cli.BoolFlag{
116-
Name: "follow",
117-
Usage: "Follow logs (stream with SSE)",
118-
},
119-
&cli.Int64Flag{
120-
Name: "tail",
121-
Usage: "Number of lines to return from end",
122-
Value: 100,
123-
},
124124
},
125-
Action: handleInstancesStreamLogs,
125+
Action: handleInstancesRestoreFromStandby,
126126
HideHelpCommand: true,
127127
}
128128

@@ -226,7 +226,7 @@ func handleInstancesDelete(ctx context.Context, cmd *cli.Command) error {
226226
)
227227
}
228228

229-
func handleInstancesPutInStandby(ctx context.Context, cmd *cli.Command) error {
229+
func handleInstancesLogs(ctx context.Context, cmd *cli.Command) error {
230230
client := hypeman.NewClient(getDefaultRequestOptions(cmd)...)
231231
unusedArgs := cmd.Args().Slice()
232232
if !cmd.IsSet("id") && len(unusedArgs) > 0 {
@@ -236,24 +236,27 @@ func handleInstancesPutInStandby(ctx context.Context, cmd *cli.Command) error {
236236
if len(unusedArgs) > 0 {
237237
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
238238
}
239-
var res []byte
240-
_, err := client.Instances.PutInStandby(
239+
params := hypeman.InstanceLogsParams{}
240+
if cmd.IsSet("follow") {
241+
params.Follow = hypeman.Opt(cmd.Value("follow").(bool))
242+
}
243+
if cmd.IsSet("tail") {
244+
params.Tail = hypeman.Opt(cmd.Value("tail").(int64))
245+
}
246+
stream := client.Instances.LogsStreaming(
241247
ctx,
242248
cmd.Value("id").(string),
249+
params,
243250
option.WithMiddleware(debugMiddleware(cmd.Bool("debug"))),
244-
option.WithResponseBodyInto(&res),
245251
)
246-
if err != nil {
247-
return err
252+
defer stream.Close()
253+
for stream.Next() {
254+
fmt.Printf("%s\n", stream.Current())
248255
}
249-
250-
json := gjson.Parse(string(res))
251-
format := cmd.Root().String("format")
252-
transform := cmd.Root().String("transform")
253-
return ShowJSON("instances put-in-standby", json, format, transform)
256+
return stream.Err()
254257
}
255258

256-
func handleInstancesRestoreFromStandby(ctx context.Context, cmd *cli.Command) error {
259+
func handleInstancesPutInStandby(ctx context.Context, cmd *cli.Command) error {
257260
client := hypeman.NewClient(getDefaultRequestOptions(cmd)...)
258261
unusedArgs := cmd.Args().Slice()
259262
if !cmd.IsSet("id") && len(unusedArgs) > 0 {
@@ -264,7 +267,7 @@ func handleInstancesRestoreFromStandby(ctx context.Context, cmd *cli.Command) er
264267
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
265268
}
266269
var res []byte
267-
_, err := client.Instances.RestoreFromStandby(
270+
_, err := client.Instances.PutInStandby(
268271
ctx,
269272
cmd.Value("id").(string),
270273
option.WithMiddleware(debugMiddleware(cmd.Bool("debug"))),
@@ -277,10 +280,10 @@ func handleInstancesRestoreFromStandby(ctx context.Context, cmd *cli.Command) er
277280
json := gjson.Parse(string(res))
278281
format := cmd.Root().String("format")
279282
transform := cmd.Root().String("transform")
280-
return ShowJSON("instances restore-from-standby", json, format, transform)
283+
return ShowJSON("instances put-in-standby", json, format, transform)
281284
}
282285

283-
func handleInstancesStreamLogs(ctx context.Context, cmd *cli.Command) error {
286+
func handleInstancesRestoreFromStandby(ctx context.Context, cmd *cli.Command) error {
284287
client := hypeman.NewClient(getDefaultRequestOptions(cmd)...)
285288
unusedArgs := cmd.Args().Slice()
286289
if !cmd.IsSet("id") && len(unusedArgs) > 0 {
@@ -290,22 +293,19 @@ func handleInstancesStreamLogs(ctx context.Context, cmd *cli.Command) error {
290293
if len(unusedArgs) > 0 {
291294
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
292295
}
293-
params := hypeman.InstanceStreamLogsParams{}
294-
if cmd.IsSet("follow") {
295-
params.Follow = hypeman.Opt(cmd.Value("follow").(bool))
296-
}
297-
if cmd.IsSet("tail") {
298-
params.Tail = hypeman.Opt(cmd.Value("tail").(int64))
299-
}
300-
stream := client.Instances.StreamLogsStreaming(
296+
var res []byte
297+
_, err := client.Instances.RestoreFromStandby(
301298
ctx,
302299
cmd.Value("id").(string),
303-
params,
304300
option.WithMiddleware(debugMiddleware(cmd.Bool("debug"))),
301+
option.WithResponseBodyInto(&res),
305302
)
306-
defer stream.Close()
307-
for stream.Next() {
308-
fmt.Printf("%s\n", stream.Current())
303+
if err != nil {
304+
return err
309305
}
310-
return stream.Err()
306+
307+
json := gjson.Parse(string(res))
308+
format := cmd.Root().String("format")
309+
transform := cmd.Root().String("transform")
310+
return ShowJSON("instances restore-from-standby", json, format, transform)
311311
}

0 commit comments

Comments
 (0)