MCPcopy Create free account
hub / github.com/compozy/agh / readAuthoredBody

Function readAuthoredBody

internal/cli/authored_context.go:788–814  ·  view source on GitHub ↗
(cmd *cobra.Command, input authoredBodyInput, required bool)

Source from the content-addressed store, hash-verified

786}
787
788func readAuthoredBody(cmd *cobra.Command, input authoredBodyInput, required bool) (string, error) {
789 if cmd.Flags().Changed("file") && input.stdin {
790 return "", errors.New("cli: --file and --stdin cannot be combined")
791 }
792 if input.stdin {
793 body, err := io.ReadAll(cmd.InOrStdin())
794 if err != nil {
795 return "", fmt.Errorf("cli: read authored body from stdin: %w", err)
796 }
797 return string(body), nil
798 }
799 if cmd.Flags().Changed("file") {
800 path := strings.TrimSpace(input.file)
801 if path == "" {
802 return "", errors.New("cli: --file cannot be empty")
803 }
804 body, err := os.ReadFile(path)
805 if err != nil {
806 return "", fmt.Errorf("cli: read authored body file: %w", err)
807 }
808 return string(body), nil
809 }
810 if required {
811 return "", errors.New("cli: provide authored body with --file or --stdin")
812 }
813 return "", nil
814}
815
816func changedStringFlag(cmd *cobra.Command, name string, value string) (string, error) {
817 if !cmd.Flags().Changed(name) {

Calls 1

ReadFileMethod · 0.65

Tested by

no test coverage detected