MCPcopy
hub / github.com/cli/cli / NewCmdLock

Function NewCmdLock

pkg/cmd/issue/lock/lock.go:132–178  ·  view source on GitHub ↗
(f *cmdutil.Factory, parentName string, runF func(string, *LockOptions) error)

Source from the content-addressed store, hash-verified

130}
131
132func NewCmdLock(f *cmdutil.Factory, parentName string, runF func(string, *LockOptions) error) *cobra.Command {
133 opts := &LockOptions{
134 ParentCmd: parentName,
135 Prompter: f.Prompter,
136 }
137
138 c := alias[opts.ParentCmd]
139 short := fmt.Sprintf("Lock %s conversation", strings.ToLower(c.FullName))
140
141 cmd := &cobra.Command{
142 Use: "lock {<number> | <url>}",
143 Short: short,
144 Args: cobra.ExactArgs(1),
145 RunE: func(cmd *cobra.Command, args []string) error {
146 if err := opts.setCommonOptions(f, args); err != nil {
147 return err
148 }
149
150 reasonProvided := cmd.Flags().Changed("reason")
151 if reasonProvided {
152 _, ok := reasonsMap[opts.Reason]
153 if !ok {
154 if opts.IO.IsStdoutTTY() {
155 cs := opts.IO.ColorScheme()
156
157 return cmdutil.FlagErrorf("%s Invalid reason: %v\n",
158 cs.FailureIconWithColor(cs.Red), opts.Reason)
159 } else {
160 return fmt.Errorf("invalid reason %s", opts.Reason)
161 }
162 }
163 } else if opts.IO.CanPrompt() {
164 opts.Interactive = true
165 }
166
167 if runF != nil {
168 return runF(Lock, opts)
169 }
170 return lockRun(Lock, opts)
171 },
172 }
173
174 msg := fmt.Sprintf("Optional reason for locking conversation (%v).", reasonsString)
175
176 cmd.Flags().StringVarP(&opts.Reason, "reason", "r", "", msg)
177 return cmd
178}
179
180func NewCmdUnlock(f *cmdutil.Factory, parentName string, runF func(string, *LockOptions) error) *cobra.Command {
181 opts := &LockOptions{ParentCmd: parentName}

Callers 1

Test_NewCmdLockFunction · 0.85

Calls 8

setCommonOptionsMethod · 0.95
FlagErrorfFunction · 0.92
lockRunFunction · 0.85
IsStdoutTTYMethod · 0.80
ColorSchemeMethod · 0.80
FailureIconWithColorMethod · 0.80
CanPromptMethod · 0.80
ErrorfMethod · 0.65

Tested by 1

Test_NewCmdLockFunction · 0.68