MCPcopy
hub / github.com/cli/cli / NewCmdMarkTemplate

Function NewCmdMarkTemplate

pkg/cmd/project/mark-template/mark_template.go:41–87  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(config markTemplateConfig) error)

Source from the content-addressed store, hash-verified

39}
40
41func NewCmdMarkTemplate(f *cmdutil.Factory, runF func(config markTemplateConfig) error) *cobra.Command {
42 opts := markTemplateOpts{}
43 markTemplateCmd := &cobra.Command{
44 Short: "Mark a project as a template",
45 Use: "mark-template [<number>]",
46 Example: heredoc.Doc(`
47 # Mark the github org's project "1" as a template
48 $ gh project mark-template 1 --owner "github"
49
50 # Unmark the github org's project "1" as a template
51 $ gh project mark-template 1 --owner "github" --undo
52 `),
53 Args: cobra.MaximumNArgs(1),
54 RunE: func(cmd *cobra.Command, args []string) error {
55 client, err := client.New(f)
56 if err != nil {
57 return err
58 }
59
60 if len(args) == 1 {
61 num, err := strconv.ParseInt(args[0], 10, 32)
62 if err != nil {
63 return cmdutil.FlagErrorf("invalid number: %v", args[0])
64 }
65 opts.number = int32(num)
66 }
67
68 config := markTemplateConfig{
69 client: client,
70 opts: opts,
71 io: f.IOStreams,
72 }
73
74 // allow testing of the command without actually running it
75 if runF != nil {
76 return runF(config)
77 }
78 return runMarkTemplate(config)
79 },
80 }
81
82 markTemplateCmd.Flags().StringVar(&opts.owner, "owner", "", "Login of the org owner.")
83 markTemplateCmd.Flags().BoolVar(&opts.undo, "undo", false, "Unmark the project as a template.")
84 cmdutil.AddFormatFlags(markTemplateCmd, &opts.exporter)
85
86 return markTemplateCmd
87}
88
89func runMarkTemplate(config markTemplateConfig) error {
90 canPrompt := config.io.CanPrompt()

Callers 1

TestNewCmdMarkTemplateFunction · 0.85

Calls 4

NewFunction · 0.92
FlagErrorfFunction · 0.92
AddFormatFlagsFunction · 0.92
runMarkTemplateFunction · 0.85

Tested by 1

TestNewCmdMarkTemplateFunction · 0.68