(cmd *cobra.Command, args []string)
| 35 | } |
| 36 | |
| 37 | func (f *pullFlags) runPullCommand(cmd *cobra.Command, args []string) (commandErr error) { |
| 38 | ctx := cmd.Context() |
| 39 | telemetry.TrackCommand(ctx, "share", append([]string{"pull"}, args...)) |
| 40 | defer func() { // do not inline this defer so that commandErr is not resolved early |
| 41 | telemetry.TrackCommandError(ctx, "share", append([]string{"pull"}, args...), commandErr) |
| 42 | }() |
| 43 | |
| 44 | out := cli.NewPrinter(cmd.OutOrStdout()) |
| 45 | registryRef := args[0] |
| 46 | slog.DebugContext(ctx, "Starting pull", "registry_ref", registryRef) |
| 47 | |
| 48 | out.Println("Pulling agent", registryRef) |
| 49 | |
| 50 | _, err := remote.Pull(ctx, registryRef, f.force) |
| 51 | if err != nil { |
| 52 | return fmt.Errorf("failed to pull artifact: %w", err) |
| 53 | } |
| 54 | |
| 55 | store, err := content.NewStore() |
| 56 | if err != nil { |
| 57 | return fmt.Errorf("failed to open content store: %w", err) |
| 58 | } |
| 59 | yamlFile, err := store.GetArtifact(registryRef) |
| 60 | if err != nil { |
| 61 | return fmt.Errorf("failed to get agent yaml: %w", err) |
| 62 | } |
| 63 | |
| 64 | agentName := strings.ReplaceAll(registryRef, "/", "_") |
| 65 | fileName := agentName + ".yaml" |
| 66 | |
| 67 | if err := os.WriteFile(fileName, []byte(yamlFile), 0o644); err != nil { //nolint:gosec // pulled agent yaml is meant to be readable |
| 68 | return err |
| 69 | } |
| 70 | |
| 71 | out.Printf("Agent saved to %s\n", fileName) |
| 72 | |
| 73 | return nil |
| 74 | } |
nothing calls this directly
no test coverage detected