Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.6.1"
".": "0.7.0"
}
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## 0.7.0 (2025-12-23)

Full Changelog: [v0.6.1...v0.7.0](https://github.com/onkernel/hypeman-cli/compare/v0.6.1...v0.7.0)

### Features

* add cp command for file copy to/from instances ([#18](https://github.com/onkernel/hypeman-cli/issues/18)) ([f67ad7b](https://github.com/onkernel/hypeman-cli/commit/f67ad7bcb6fbbe0a9409574fababab862da87840))


### Chores

* **internal:** codegen related update ([a6c6588](https://github.com/onkernel/hypeman-cli/commit/a6c6588d42a6981b65f5144d033f040afc29a959))

## 0.6.1 (2025-12-11)

Full Changelog: [v0.6.0...v0.6.1](https://github.com/onkernel/hypeman-cli/compare/v0.6.0...v0.6.1)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/onkernel/hypeman-go v0.8.0
github.com/tidwall/gjson v1.18.0
github.com/tidwall/pretty v1.2.1
github.com/tidwall/sjson v1.2.5
github.com/urfave/cli-docs/v3 v3.0.0-alpha6
github.com/urfave/cli/v3 v3.3.2
golang.org/x/sys v0.38.0
Expand Down Expand Up @@ -60,7 +61,6 @@ require (
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
github.com/vbatts/tar-split v0.12.2 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
Expand Down
14 changes: 7 additions & 7 deletions pkg/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ func init() {
&runCmd,
&psCmd,
&logsCmd,
&rmCmd,
&stopCmd,
&startCmd,
&standbyCmd,
&restoreCmd,
&ingressCmd,
{
&rmCmd,
&stopCmd,
&startCmd,
&standbyCmd,
&restoreCmd,
&ingressCmd,
{
Name: "health",
Category: "API RESOURCE",
Commands: []*cli.Command{
Expand Down
149 changes: 149 additions & 0 deletions pkg/cmd/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package cmd

import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"net/http/httputil"
"os"
"reflect"
"strings"

"github.com/onkernel/hypeman-go/option"

"github.com/tidwall/sjson"
"github.com/urfave/cli/v3"
)


type fileReader struct {
Value io.Reader
Base64Encoded bool
}

func (f *fileReader) Set(filename string) error {
reader, err := os.Open(filename)
if err != nil {
return fmt.Errorf("failed to read file %q: %w", filename, err)
}
f.Value = reader
return nil
}

func (f *fileReader) String() string {
if f.Value == nil {
return ""
}
buf := new(bytes.Buffer)
buf.ReadFrom(f.Value)
if f.Base64Encoded {
return base64.StdEncoding.EncodeToString(buf.Bytes())
}
return buf.String()
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Reader consumed on first access returns empty thereafter

The fileReader.String() method calls buf.ReadFrom(f.Value) which fully consumes the underlying io.Reader. Since Get() delegates to String(), any subsequent call to either method returns an empty string. CLI frameworks often access flag values multiple times (for help text, validation, actual usage), causing silent data loss after the first read.

Fix in Cursor Fix in Web


func (f *fileReader) Get() any {
return f.String()
}

func unmarshalWithReaders(data []byte, v any) error {
var fields map[string]json.RawMessage
if err := json.Unmarshal(data, &fields); err != nil {
return err
}

rv := reflect.ValueOf(v).Elem()
rt := rv.Type()

for i := 0; i < rv.NumField(); i++ {
fv := rv.Field(i)
ft := rt.Field(i)

jsonKey := ft.Tag.Get("json")
if jsonKey == "" {
jsonKey = ft.Name
} else if idx := strings.Index(jsonKey, ","); idx != -1 {
jsonKey = jsonKey[:idx]
}

rawVal, ok := fields[jsonKey]
if !ok {
continue
}

if ft.Type == reflect.TypeOf((*io.Reader)(nil)).Elem() {
var s string
if err := json.Unmarshal(rawVal, &s); err != nil {
return fmt.Errorf("field %s: %w", ft.Name, err)
}
fv.Set(reflect.ValueOf(strings.NewReader(s)))
} else {
ptr := fv.Addr().Interface()
if err := json.Unmarshal(rawVal, ptr); err != nil {
return fmt.Errorf("field %s: %w", ft.Name, err)
}
}
}

return nil
}

func unmarshalStdinWithFlags(cmd *cli.Command, flags map[string]string, target any) error {
var data []byte
if isInputPiped() {
var err error
if data, err = io.ReadAll(os.Stdin); err != nil {
return err
}
}

// Merge CLI flags into the body
for flag, path := range flags {
if cmd.IsSet(flag) {
var err error
data, err = sjson.SetBytes(data, path, cmd.Value(flag))
if err != nil {
return err
}
}
}

if data != nil {
if err := unmarshalWithReaders(data, target); err != nil {
return fmt.Errorf("failed to unmarshal JSON: %w", err)
}
}

return nil
}

func debugMiddleware(debug bool) option.Middleware {
return func(r *http.Request, mn option.MiddlewareNext) (*http.Response, error) {
if debug {
logger := log.Default()

if reqBytes, err := httputil.DumpRequest(r, true); err == nil {
logger.Printf("Request Content:\n%s\n", reqBytes)
}

resp, err := mn(r)
if err != nil {
return resp, err
}

if respBytes, err := httputil.DumpResponse(resp, true); err == nil {
logger.Printf("Response Content:\n%s\n", respBytes)
}

return resp, err
}

return mn(r)
}
}
2 changes: 1 addition & 1 deletion pkg/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

package cmd

const Version = "0.6.1" // x-release-please-version
const Version = "0.7.0" // x-release-please-version
Loading