Skip to content

Commit 59a855d

Browse files
authored
Merge pull request #323 from dgageot/print
Print canonical configuration
2 parents b61e705 + e78a6cc commit 59a855d

3 files changed

Lines changed: 49 additions & 1 deletion

File tree

cmd/root/print.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package root
2+
3+
import (
4+
"fmt"
5+
"path/filepath"
6+
"strings"
7+
8+
"github.com/goccy/go-yaml"
9+
"github.com/spf13/cobra"
10+
11+
"github.com/docker/cagent/pkg/config"
12+
"github.com/docker/cagent/pkg/telemetry"
13+
)
14+
15+
func NewPrintCmd() *cobra.Command {
16+
return &cobra.Command{
17+
Use: "print <agent-name>",
18+
Short: "Print the canonical configuration of an agent",
19+
Args: cobra.ExactArgs(1),
20+
RunE: printCommand,
21+
Hidden: true,
22+
}
23+
}
24+
25+
func printCommand(cmd *cobra.Command, args []string) error {
26+
telemetry.TrackCommand("print", args)
27+
28+
agentFilename := args[0]
29+
30+
ext := strings.ToLower(filepath.Ext(agentFilename))
31+
if ext == ".yaml" || ext == ".yml" || strings.HasPrefix(agentFilename, "/dev/fd/") {
32+
cfg, err := config.LoadConfigSecure(filepath.Base(agentFilename), filepath.Dir(agentFilename))
33+
if err != nil {
34+
return err
35+
}
36+
37+
buf, err := yaml.Marshal(cfg)
38+
if err != nil {
39+
return err
40+
}
41+
42+
fmt.Println(string(buf))
43+
}
44+
45+
return nil
46+
}

cmd/root/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func NewRootCmd() *cobra.Command {
107107
cmd.AddCommand(NewFeedbackCmd())
108108
cmd.AddCommand(NewCatalogCmd())
109109
cmd.AddCommand(NewBuildCmd())
110+
cmd.AddCommand(NewPrintCmd())
110111

111112
return cmd
112113
}

pkg/runtime/runtime_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import (
77
"reflect"
88
"testing"
99

10+
"github.com/stretchr/testify/require"
11+
1012
"github.com/docker/cagent/pkg/agent"
1113
"github.com/docker/cagent/pkg/chat"
1214
"github.com/docker/cagent/pkg/modelsdev"
1315
"github.com/docker/cagent/pkg/session"
1416
"github.com/docker/cagent/pkg/team"
1517
"github.com/docker/cagent/pkg/tools"
16-
"github.com/stretchr/testify/require"
1718
)
1819

1920
type mockStream struct {

0 commit comments

Comments
 (0)