ARG_REQUIRED
ARG_REQUIRED
Command argument is required.
Generate a set of tables for storing EAV attributes and values. We create a single table for storing attribute definintions and a table for each supported "backend" or data type (i.e. varchar, text, decimal, int, and datetime).
To use this command, you must specify the database table name you'd like the EAV tables to link to:
./vendor/bin/dewdrop gen-eav --table-name widgets
$runner : \Dewdrop\Cli\Run
The \Dewdrop\Cli\Run instance that is managing this and other CLI commands.
$renderer : \Dewdrop\Cli\Renderer\RendererInterface
The renderer that should be used for all command output. No output should be rendered directly (i.e. with echo, print, printf, etc.), so that it is easier to capture and examine output during testing.
$paths : \Dewdrop\Paths
Paths utility to assist CLI commands in getting around the WP environment.
$command : string
The command name that should be used on the CLI to select this command class for execution. For example, when running the dewdrop CLI tool like this:
./vendor/bin/dewdrop command-name
\Dewdrop\Cli\Run will select the command class that has a command class that has a $command property value of "command-name"
$primaryArg : string
The name of the command's primary argument. The primary argument's value can be specified without naming the argument explicitly on the command line. Using popular version control system Subversion as an example, you can do a code checkout without specifying the name of the path argument like this:
svn checkout http://example.org/path
In that case, the path argument is the primary argument of SVN's checkout command.
In Dewdrop, if your command had a primary argument of "name" and the user supplied this input:
./vendor/bin/dewdrop my-command --folder=example "Example Name Value"
The argument parser would set the name argument's value to "Example Name Value" because that is the value expression not explicitly assigned to another argument name.
Users can still explicitly set the argument name for the primary argument, too, if they prefer:
./vendor/bin/dewdrop --name="Example Name Value"
$supportFallbackArgs : boolean
Whether this command supports passing along any unrecognized arguments to another command. For example, if your CLI command is a thin wrapper around phpunit, you could pass all unrecognized arguments to phpunit so that the Dewdrop user has the full capabilities of phpunit available to them.
$db : \Dewdrop\Db\Adapter
Reference to the DB adapter (used to load metadata for the entity table so we can determine its primary key).
__construct(\Dewdrop\Cli\Run $runner, \Dewdrop\Cli\Renderer\RendererInterface $renderer)
Instantiate command with a runner and renderer. After the command sub-class runs its init() method, check to ensure the required basic properties were set.
\Dewdrop\Cli\Run | $runner | |
\Dewdrop\Cli\Renderer\RendererInterface | $renderer |
parseArgs(array $args) : boolean
Parse the arguments passed to this command.
If the "--help" argument is present anywhere in the argument input, all further parsing will be aborted and the command's help content will be displayed.
For all argument names and their aliases, there are multiple acceptable formats of argument and value. For example, all of these inputs are equivalent:
./vendor/bin/dewdrop my-command --argument-name=value ./vendor/bin/dewdrop my-command --argument-name value ./vendor/bin/dewdrop my-command --argument-alias=value ./vendor/bin/dewdrop my-command -argument-alias=value ./vendor/bin/dewdrop my-command -argument-alias value
In short, you can use one or two dashes at the beginning of the argument name and you can separate the value from the name with either a space or an equals sign.
For every argument your command supports, you need to implement a setter method. For example, if you have an argument with the name "my-argument" then your command class needs a method called "setMyArgument()".
Also note that the command API supports the concept of a "primary argument". See the documentation for the $primaryArgument property for more information about that feature.
array | $args |
Whether args were fully parsed and command can be executed.
setDescription(string $description) : \Dewdrop\Cli\Command\CommandAbstract
Set a human-friendly description of this command's role
string | $description |
setCommand(string $command) : \Dewdrop\Cli\Command\CommandAbstract
Set the primary command that will be used to run this command. This value differs from aliases because it is displayed in the default help listings.
string | $command |
addAlias(string $alias) : \Dewdrop\Cli\Command\CommandAbstract
Register an alias for this command. This can be useful to provide the user other ways to execute the command. For example, you might provide a shortened version of the command name so that experienced users can avoid typing the full name once their comfortable with the command.
string | $alias |
addPrimaryArg(string $name, string $description, boolean $required, array $aliases = array()) : \Dewdrop\Cli\Command\CommandAbstract
Add an argument while also setting it as the primary arg for this command. For more information about the primary arg feature, read the docs on the $primaryArg property.
string | $name | |
string | $description | |
boolean | $required | |
array | $aliases |
addArg(string $name, string $description, boolean $required, array $aliases = array(), string $mode = self::VALUE_REQUIRED) : \Dewdrop\Cli\Command\CommandAbstract
Register a new argument allowed to be used with this command.
string | $name | |
string | $description | |
boolean | $required | |
array | $aliases | |
string | $mode |
setSupportFallbackArgs(boolean $supportFallbackArgs) : \Dewdrop\Cli\Command\CommandAbstract
Set whether this command supports fallback args.
boolean | $supportFallbackArgs |
addExample(string $description, string $command) : \Dewdrop\Cli\Command\CommandAbstract
Add an example usage for this command. These are displayed in the command's help content.
string | $description | |
string | $command |
help() : $this
Display help content for this command.
The basic command name and description, any avaialble aliases, and any avaialble examples are all included in the help display.
This content can be accessed by called "--help" on this command directly:
./vendor/bin/dewdrop my-command --help
Or, you can use the built-in help command to access it:
./vendor/bin/dewdrop help my-command
setTableName(string $tableName) : \Dewdrop\Cli\Command\GenEav
Set the name of the DB table you'd like to create EAV attribute and value tables for.
string | $tableName |
exec(string $command, array $output, integer $exitStatus) : void
Run a shell command using PHP's exec fucntion, which may be preferable to passthru() when you need to capture output. This is primarily present to make it easy to mock exec() during testing.
string | $command | |
array | $output | |
integer | $exitStatus |
evalPathArgument(string $path) : string
Change "~" prefix to the user's home folder.
Bash doesn't do "~" evaluation automatically for command arguments, so we do it here to avoid confusing developers by creating a "~" folder in their WP install instead.
string | $path |
autoDetectExecutable(string $name) : string
First, we check to see if the executable is present in Composer's "./vendor/bin/" folder. Then, we attempt to locate the named executable using "which", if it is available. Otherwise, just return the name and hope it is in the user's $PATH.
string | $name |
writeFile(string $path, string $contents) : \Dewdrop\Cli\Command\GenAdminComponent
Write a file at the specified path with the supplied contents.
This is a separate method so that it's easy to mock during testing.
string | $path | |
string | $contents |
generateMultiColumnPkeyIndexContent() : string
Generate the content for the {{multiColumnPrimaryKeyIndexes}} tempalte placeholder. When the root table has more than one column in its primary key, it's important that we explicitly add an index for all columns except the first because in a multi-column key, only the first column can use the key itself as an index. Adding these additional indexes, then, ensure we still have speedy value lookups when the root table has a multi-column primary key.
generatePkeyColumnListContent() : string
Generate the content for the {{primaryKeyColumnList}} tempalte placeholder. This placeholder is used to create a comma-separated list of columns corresponding the primary key columns from the root table for each in each EAV value table's primary key definition.
setArgValue(string $name, string $value) : \Dewdrop\Cli\Command\CommandAbstract
Set the valid of the specified argument.
The argument's name is inflected to form a setter name that will be called to set the value. If no setter is available, execution will be aborted.
string | $name | |
string | $value |