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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/google/go-containerregistry v0.20.7
github.com/gorilla/websocket v1.5.3
github.com/itchyny/json2yaml v0.1.4
github.com/kernel/hypeman-go v0.15.0
github.com/kernel/hypeman-go v0.16.1-0.20260323172303-508a8c69feb3
github.com/knadh/koanf/parsers/yaml v1.1.0
github.com/knadh/koanf/providers/env v1.1.0
github.com/knadh/koanf/providers/file v1.2.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 h1:8Tjv8EJ+pM1xP8mK6egEbD1OgnV
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2/go.mod h1:pkJQ2tZHJ0aFOVEEot6oZmaVEZcRme73eIFmhiVuRWs=
github.com/itchyny/json2yaml v0.1.4 h1:/pErVOXGG5iTyXHi/QKR4y3uzhLjGTEmmJIy97YT+k8=
github.com/itchyny/json2yaml v0.1.4/go.mod h1:6iudhBZdarpjLFRNj+clWLAkGft+9uCcjAZYXUH9eGI=
github.com/kernel/hypeman-go v0.15.0 h1:igcd8tArES1FMbuzEGjQ9HqPF3Zwi6yAvHoE4dkKx4Y=
github.com/kernel/hypeman-go v0.15.0/go.mod h1:guRrhyP9QW/ebUS1UcZ0uZLLJeGAAhDNzSi68U4M9hI=
github.com/kernel/hypeman-go v0.16.1-0.20260323172303-508a8c69feb3 h1:g6qT9G/Qrxqqdl9gjqTnhDAHlePxV68OyQjlqXA6WX4=
github.com/kernel/hypeman-go v0.16.1-0.20260323172303-508a8c69feb3/go.mod h1:guRrhyP9QW/ebUS1UcZ0uZLLJeGAAhDNzSi68U4M9hI=
github.com/klauspost/compress v1.18.1 h1:bcSGx7UbpBqMChDtsF28Lw6v/G94LPrrbMbdC3JH2co=
github.com/klauspost/compress v1.18.1/go.mod h1:ZQFFVG+MdnR0P+l6wpXgIL4NTtwiKIdBnrBd8Nrxr+0=
github.com/knadh/koanf/maps v0.1.2 h1:RBfmAW5CnZT+PJ1CVc1QSJKf4Xu9kxfQgYVQSu8hpbo=
Expand Down
47 changes: 37 additions & 10 deletions pkg/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ Examples:
Name: "memory",
Usage: "Memory limit for builder VM in MB (default 2048)",
},
&cli.StringSliceFlag{
Name: "tag",
Usage: "Set build tag key-value pair (KEY=VALUE, can be repeated)",
},
},
Commands: []*cli.Command{
&buildListCmd,
Expand Down Expand Up @@ -186,6 +190,17 @@ func handleBuild(ctx context.Context, cmd *cli.Command) error {
if cmd.IsSet("memory") {
params.MemoryMB = hypeman.Opt(int64(cmd.Int("memory")))
}
tags, malformedTags := parseKeyValueSpecs(cmd.StringSlice("tag"))
for _, malformed := range malformedTags {
fmt.Fprintf(os.Stderr, "Warning: ignoring malformed tag: %s\n", malformed)
}
if len(tags) > 0 {
tagsJSON, err := marshalStringMap(tags)
if err != nil {
return fmt.Errorf("failed to encode tags: %w", err)
}
params.Tags = hypeman.Opt(tagsJSON)
}

// Start build
build, err := client.Builds.New(ctx, params, opts...)
Expand Down Expand Up @@ -359,24 +374,28 @@ var buildListCmd = cli.Command{
Aliases: []string{"q"},
Usage: "Only display build IDs",
},
&cli.StringSliceFlag{
Name: "tag",
Usage: "Filter by tag key-value pair (KEY=VALUE, can be repeated)",
},
},
Action: handleBuildList,
HideHelpCommand: true,
}

var buildGetCmd = cli.Command{
Name: "get",
Usage: "Get build details",
ArgsUsage: "<id>",
Action: handleBuildGet,
Name: "get",
Usage: "Get build details",
ArgsUsage: "<id>",
Action: handleBuildGet,
HideHelpCommand: true,
}

var buildCancelCmd = cli.Command{
Name: "cancel",
Usage: "Cancel a build",
ArgsUsage: "<id>",
Action: handleBuildCancel,
Name: "cancel",
Usage: "Cancel a build",
ArgsUsage: "<id>",
Action: handleBuildCancel,
HideHelpCommand: true,
}

Expand All @@ -390,19 +409,27 @@ func handleBuildList(ctx context.Context, cmd *cli.Command) error {

format := cmd.Root().String("format")
transform := cmd.Root().String("transform")
params := hypeman.BuildListParams{}
tags, malformedTags := parseKeyValueSpecs(cmd.StringSlice("tag"))
for _, malformed := range malformedTags {
fmt.Fprintf(os.Stderr, "Warning: ignoring malformed tag filter: %s\n", malformed)
}
if len(tags) > 0 {
params.Tags = tags
}

if format != "auto" {
var res []byte
opts = append(opts, option.WithResponseBodyInto(&res))
_, err := client.Builds.List(ctx, opts...)
_, err := client.Builds.List(ctx, params, opts...)
if err != nil {
return err
}
obj := gjson.ParseBytes(res)
return ShowJSON(os.Stdout, "build list", obj, format, transform)
}

builds, err := client.Builds.List(ctx, opts...)
builds, err := client.Builds.List(ctx, params, opts...)
if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func init() {
&pushCmd,
&runCmd,
&psCmd,
&statsCmd,
&updateCmd,
&inspectCmd,
&logsCmd,
&rmCmd,
Expand All @@ -85,6 +87,7 @@ func init() {
&forkCmd,
&imageCmd,
&ingressCmd,
&snapshotCmd,
&volumeCmd,
&resourcesCmd,
&deviceCmd,
Expand Down
25 changes: 25 additions & 0 deletions pkg/cmd/cmdutil.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"encoding/json"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -38,6 +39,30 @@ func getDefaultRequestOptions(cmd *cli.Command) []option.RequestOption {
return opts
}

func parseKeyValueSpecs(specs []string) (map[string]string, []string) {
values := make(map[string]string)
var malformed []string

for _, spec := range specs {
parts := strings.SplitN(spec, "=", 2)
if len(parts) != 2 || parts[0] == "" {
malformed = append(malformed, spec)
continue
}
values[parts[0]] = parts[1]
}

return values, malformed
}

func marshalStringMap(input map[string]string) (string, error) {
payload, err := json.Marshal(input)
if err != nil {
return "", err
}
return string(payload), nil
}

var debugMiddlewareOption = option.WithMiddleware(
func(r *http.Request, mn option.MiddlewareNext) (*http.Response, error) {
logger := log.Default()
Expand Down
3 changes: 0 additions & 3 deletions pkg/cmd/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,6 @@ func copyDirContentsToInstance(ctx context.Context, baseURL, apiKey, instanceID,
return nil
}


// createDirOnInstanceWithUidGid creates a directory on the instance with explicit uid/gid
func createDirOnInstanceWithUidGid(ctx context.Context, baseURL, apiKey, instanceID, dstPath string, mode fs.FileMode, uid, gid uint32) error {
wsURL, err := buildCpWsURL(baseURL, instanceID)
Expand Down Expand Up @@ -980,5 +979,3 @@ func copyFromInstanceToStdout(ctx context.Context, baseURL, apiKey, instanceID,
}
return nil
}


31 changes: 28 additions & 3 deletions pkg/cmd/devicecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,24 @@ Examples:
Name: "name",
Usage: "Optional name for the device (auto-generated if not provided)",
},
&cli.StringSliceFlag{
Name: "tag",
Usage: "Set device tag key-value pair (KEY=VALUE, can be repeated)",
},
},
Action: handleDeviceRegister,
HideHelpCommand: true,
}

var deviceListCmd = cli.Command{
Name: "list",
Usage: "List registered devices",
Name: "list",
Usage: "List registered devices",
Flags: []cli.Flag{
&cli.StringSliceFlag{
Name: "tag",
Usage: "Filter by tag key-value pair (KEY=VALUE, can be repeated)",
},
},
Action: handleDeviceList,
HideHelpCommand: true,
}
Expand Down Expand Up @@ -208,6 +218,13 @@ func handleDeviceRegister(ctx context.Context, cmd *cli.Command) error {
if name := cmd.String("name"); name != "" {
params.Name = hypeman.Opt(name)
}
tags, malformedTags := parseKeyValueSpecs(cmd.StringSlice("tag"))
for _, malformed := range malformedTags {
fmt.Fprintf(os.Stderr, "Warning: ignoring malformed tag: %s\n", malformed)
}
if len(tags) > 0 {
params.Tags = tags
}

var opts []option.RequestOption
if cmd.Root().Bool("debug") {
Expand Down Expand Up @@ -244,7 +261,15 @@ func handleDeviceList(ctx context.Context, cmd *cli.Command) error {

var res []byte
opts = append(opts, option.WithResponseBodyInto(&res))
_, err := client.Devices.List(ctx, opts...)
params := hypeman.DeviceListParams{}
tags, malformedTags := parseKeyValueSpecs(cmd.StringSlice("tag"))
for _, malformed := range malformedTags {
fmt.Fprintf(os.Stderr, "Warning: ignoring malformed tag filter: %s\n", malformed)
}
if len(tags) > 0 {
params.Tags = tags
}
_, err := client.Devices.List(ctx, params, opts...)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
type TableWriter struct {
w io.Writer
headers []string
widths []int // natural widths (max of header and cell values)
widths []int // natural widths (max of header and cell values)
rows [][]string

// TruncOrder specifies column indices in truncation priority order.
Expand Down Expand Up @@ -297,4 +297,3 @@ func ResolveInstance(ctx context.Context, client *hypeman.Client, identifier str
return "", fmt.Errorf("ambiguous instance identifier %q matches: %s", identifier, strings.Join(ids, ", "))
}
}

Loading
Loading