MCPcopy
hub / github.com/cli/cli / NewCmdPreview

Function NewCmdPreview

pkg/cmd/skills/preview/preview.go:44–126  ·  view source on GitHub ↗

NewCmdPreview creates the "skills preview" command.

(f *cmdutil.Factory, telemetry ghtelemetry.CommandRecorder, runF func(*PreviewOptions) error)

Source from the content-addressed store, hash-verified

42
43// NewCmdPreview creates the "skills preview" command.
44func NewCmdPreview(f *cmdutil.Factory, telemetry ghtelemetry.CommandRecorder, runF func(*PreviewOptions) error) *cobra.Command {
45 opts := &PreviewOptions{
46 IO: f.IOStreams,
47 Telemetry: telemetry,
48 HttpClient: f.HttpClient,
49 Prompter: f.Prompter,
50 ExecutablePath: f.ExecutablePath,
51 }
52 opts.RenderFile = func(filePath, content string) string {
53 return renderMarkdownPreview(opts.IO, filePath, content)
54 }
55
56 cmd := &cobra.Command{
57 Use: "preview <repository> [<skill>]",
58 Short: "Preview a skill from a GitHub repository (preview)",
59 Long: heredoc.Docf(`
60 Render a skill's %[1]sSKILL.md%[1]s content in the terminal. This fetches the
61 skill file from the repository and displays it using the configured
62 pager, without installing anything.
63
64 A file tree is shown first, followed by the rendered %[1]sSKILL.md%[1]s content.
65 When running interactively and the skill contains additional files
66 (scripts, references, etc.), a file picker lets you browse them
67 individually.
68
69 When run with only a repository argument, lists available skills and
70 prompts for selection.
71
72 The skill argument can be a name, a namespaced name (%[1]sauthor/skill%[1]s),
73 or an exact path within the repository (%[1]sskills/author/skill%[1]s,
74 %[1]spackages/agent-skills/code-review%[1]s, or any %[1]s.../SKILL.md%[1]s path).
75 Namespaced names with one slash are matched by name. Use a %[1]sSKILL.md%[1]s
76 suffix to force a one-directory path outside the standard conventions.
77
78 To preview a specific version of the skill, append %[1]s@VERSION%[1]s to the
79 skill name. The version is resolved as a git tag, branch, or commit SHA.
80 `, "`"),
81 Example: heredoc.Doc(`
82 # Preview a specific skill
83 $ gh skill preview github/awesome-copilot documentation-writer
84
85 # Preview a skill at a specific version
86 $ gh skill preview github/awesome-copilot documentation-writer@v1.2.0
87
88 # Preview a skill at a specific commit SHA
89 $ gh skill preview github/awesome-copilot documentation-writer@abc123def456
90
91 # Preview from a non-standard nested path (efficient, skips full discovery)
92 $ gh skill preview monalisa/skills-repo packages/agent-skills/code-review
93
94 # Browse and preview interactively
95 $ gh skill preview github/awesome-copilot
96 `),
97 Aliases: []string{"show"},
98 Args: cobra.RangeArgs(1, 2),
99 RunE: func(c *cobra.Command, args []string) error {
100 opts.RepoArg = args[0]
101 if len(args) == 2 {

Callers 2

NewCmdSkillsFunction · 0.92
TestNewCmdPreviewFunction · 0.70

Calls 3

FromFullNameFunction · 0.92
renderMarkdownPreviewFunction · 0.85
previewRunFunction · 0.85

Tested by 1

TestNewCmdPreviewFunction · 0.56