File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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
1920type mockStream struct {
You can’t perform that action at this time.
0 commit comments