New creates a new Command object with the provided options. It applies each option to the config object and initializes the Command object with the configurations.
(opts ...Option)
| 262 | // New creates a new Command object with the provided options. |
| 263 | // It applies each option to the config object and initializes the Command object with the configurations. |
| 264 | func New(opts ...Option) *Command { |
| 265 | // Instantiate a new config object with default values |
| 266 | cfg := &config{} |
| 267 | |
| 268 | // Loop through each option passed as argument and apply it to the config object |
| 269 | for _, o := range opts { |
| 270 | o.apply(cfg) |
| 271 | } |
| 272 | |
| 273 | // Instantiate a new Command object with the configurations from the config object |
| 274 | cmd := &Command{ |
| 275 | diffUnified: cfg.diffUnified, |
| 276 | // Append the user-defined excludeList to the default excludeFromDiff |
| 277 | excludeList: append(excludeFromDiff, cfg.excludeList...), |
| 278 | isAmend: cfg.isAmend, |
| 279 | } |
| 280 | |
| 281 | return cmd |
| 282 | } |