| 130 | } |
| 131 | |
| 132 | func 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 | |
| 180 | func NewCmdUnlock(f *cmdutil.Factory, parentName string, runF func(string, *LockOptions) error) *cobra.Command { |
| 181 | opts := &LockOptions{ParentCmd: parentName} |