MCPcopy
hub / github.com/cli/cli / NewCmdView

Function NewCmdView

pkg/cmd/gist/view/view.go:38–74  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*ViewOptions) error)

Source from the content-addressed store, hash-verified

36}
37
38func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Command {
39 opts := &ViewOptions{
40 IO: f.IOStreams,
41 Config: f.Config,
42 HttpClient: f.HttpClient,
43 Browser: f.Browser,
44 Prompter: f.Prompter,
45 }
46
47 cmd := &cobra.Command{
48 Use: "view [<id> | <url>]",
49 Short: "View a gist",
50 Long: `View the given gist or select from recent gists.`,
51 Args: cobra.MaximumNArgs(1),
52 RunE: func(cmd *cobra.Command, args []string) error {
53 if len(args) == 1 {
54 opts.Selector = args[0]
55 }
56
57 if !opts.IO.IsStdoutTTY() {
58 opts.Raw = true
59 }
60
61 if runF != nil {
62 return runF(opts)
63 }
64 return viewRun(opts)
65 },
66 }
67
68 cmd.Flags().BoolVarP(&opts.Raw, "raw", "r", false, "Print raw instead of rendered gist contents")
69 cmd.Flags().BoolVarP(&opts.Web, "web", "w", false, "Open gist in the browser")
70 cmd.Flags().BoolVar(&opts.ListFiles, "files", false, "List file names from the gist")
71 cmd.Flags().StringVarP(&opts.Filename, "filename", "f", "", "Display a single file from the gist")
72
73 return cmd
74}
75
76func viewRun(opts *ViewOptions) error {
77 gistID := opts.Selector

Callers 1

TestNewCmdViewFunction · 0.70

Calls 2

IsStdoutTTYMethod · 0.80
viewRunFunction · 0.70

Tested by 1

TestNewCmdViewFunction · 0.56