$value) { $this->{$key} = $value; } } else { $this->name = $name; $this->short = $short; $this->help = $help; $this->boolean = $boolean; $this->default = $default; $this->choices = $choices; } } /** * Generate the help for this this option. * * @param int $width The width to make the name of the option. * @return string */ public function help($width = 0) { $default = $short = ''; if (!empty($this->default) && $this->default !== true) { $default = sprintf(__(' (default: %s)'), $this->default); } if (!empty($this->short)) { $short = ', -' . $this->short; } $name = sprintf('--%s%s', $this->name, $short); if (strlen($name) < $width) { $name = str_pad($name, $width, ' '); } return sprintf('%s%s%s', $name, $this->help, $default); } /** * Get the usage value for this option * * @return string */ public function usage() { $name = empty($this->short) ? '--' . $this->name : '-' . $this->short; $default = ''; if (!empty($this->default) && $this->default !== true) { $default = ' ' . $this->default; } return sprintf('[%s%s]', $name, $default); } /** * Get the default value for this option * * @return void */ public function defaultValue() { return $this->default; } /** * Check if this option is a boolean option * * @return boolean */ public function isBoolean() { return (bool) $this->boolean; } }