MCPcopy
hub / github.com/larksuite/cli / newReadCmd

Function newReadCmd

cmd/skill/skill.go:102–157  ·  view source on GitHub ↗
(f *cmdutil.Factory)

Source from the content-addressed store, hash-verified

100}
101
102func newReadCmd(f *cmdutil.Factory) *cobra.Command {
103 var asJSON bool
104 cmd := &cobra.Command{
105 Use: "read <name>[/<path>] [path]",
106 Short: "Print a skill's SKILL.md, or a file under the skill (raw markdown by default)",
107 Example: ` lark-cli skills read lark-doc # the skill's SKILL.md
108 lark-cli skills read lark-doc references/lark-doc-fetch.md # a file under the skill
109 lark-cli skills read lark-doc/references/lark-doc-fetch.md # same, slash form
110 lark-cli skills read lark-doc --json # JSON envelope`,
111 Args: cobra.ArbitraryArgs,
112 RunE: func(cmd *cobra.Command, args []string) error {
113 name, relpath, err := parseReadTarget(args)
114 if err != nil {
115 return err
116 }
117 r, err := newReader(f)
118 if err != nil {
119 return err
120 }
121
122 var content []byte
123 var pathOut string
124 if relpath == "" {
125 content, err = r.ReadSkill(name)
126 pathOut = "SKILL.md"
127 } else {
128 content, pathOut, err = r.ReadReference(name, relpath)
129 }
130 if err != nil {
131 return err
132 }
133
134 isMain := pathOut == "SKILL.md"
135 if asJSON {
136 env := readEnvelope{Skill: name, Path: pathOut, Content: string(content)}
137 if isMain {
138 env.Guidance = readGuidance(name)
139 }
140 output.PrintJson(f.IOStreams.Out, env)
141 return nil
142 }
143 // Raw stdout stays byte-identical to the file; guidance goes to stderr.
144 if _, err := f.IOStreams.Out.Write(content); err != nil {
145 return errs.NewInternalError(errs.SubtypeFileIO, "failed to write output: %v", err)
146 }
147 if isMain {
148 fmt.Fprintln(f.IOStreams.ErrOut, readGuidance(name))
149 }
150 return nil
151 },
152 }
153 cmd.Flags().BoolVar(&asJSON, "json", false, "output as a JSON envelope instead of raw markdown")
154 cmdutil.SetRisk(cmd, "read")
155 cmdutil.DisableAuthCheck(cmd)
156 return cmd
157}
158
159// parseReadTarget maps 1-or-2 positional args to (name, relpath); a lone

Callers 1

NewCmdSkillFunction · 0.85

Calls 10

PrintJsonFunction · 0.92
NewInternalErrorFunction · 0.92
SetRiskFunction · 0.92
DisableAuthCheckFunction · 0.92
parseReadTargetFunction · 0.85
newReaderFunction · 0.85
readGuidanceFunction · 0.85
ReadSkillMethod · 0.80
ReadReferenceMethod · 0.80
WriteMethod · 0.65

Tested by

no test coverage detected