MCPcopy Create free account
hub / github.com/cli/cli / NewCmdView

Function NewCmdView

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

Source from the content-addressed store, hash-verified

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

Callers 1

TestNewCmdViewFunction · 0.70

Calls 2

IsStdoutTTYMethod · 0.80
viewRunFunction · 0.70

Tested by 1

TestNewCmdViewFunction · 0.56