Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wp-cli-cron-control-offload
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
WP Plugins
wp-cli-cron-control-offload
Commits
5e015061
Commit
5e015061
authored
7 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Respect global versus local assoc args
parent
8631cab5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
includes/functions.php
+31
-13
31 additions, 13 deletions
includes/functions.php
with
31 additions
and
13 deletions
includes/functions.php
+
31
−
13
View file @
5e015061
...
@@ -144,10 +144,12 @@ function parse_command( $command ) {
...
@@ -144,10 +144,12 @@ function parse_command( $command ) {
return
new
WP_Error
(
'command-parse-failed'
,
__
(
'Failed to parse requested command'
,
'wp-cli-cron-control-offload'
)
);
return
new
WP_Error
(
'command-parse-failed'
,
__
(
'Failed to parse requested command'
,
'wp-cli-cron-control-offload'
)
);
}
}
// WP_CLI::runcommand doesn't need the `wp`.
// Don't care about existing keys, so reset to zero-indexed array.
$wp
=
array_search
(
'wp'
,
$command
);
$command
=
array_values
(
$command
);
if
(
false
!==
$wp
)
{
unset
(
$command
[
$wp
]
);
// `wp` is not part of the parsed command when WP-CLI is invoked.
if
(
'wp'
===
$command
[
0
]
)
{
unset
(
$command
[
0
]
);
}
}
// Match naming in what's borrowed from WP-CLI.
// Match naming in what's borrowed from WP-CLI.
...
@@ -208,16 +210,18 @@ function implode_parsed_command( $command ) {
...
@@ -208,16 +210,18 @@ function implode_parsed_command( $command ) {
return
new
WP_Error
(
'no-command-specified'
,
__
(
'No command was provided.'
,
'wp-cli-cron-control-offload'
)
);
return
new
WP_Error
(
'no-command-specified'
,
__
(
'No command was provided.'
,
'wp-cli-cron-control-offload'
)
);
}
}
$to_implode
=
$command
[
'positional_args'
]
;
$to_implode
=
array
()
;
if
(
!
empty
(
$command
[
'assoc_args'
]
)
)
{
if
(
!
empty
(
$command
[
'global_assoc'
]
)
)
{
foreach
(
$command
[
'assoc_args'
]
as
$assoc_arg
)
{
$global
=
array_map
(
__NAMESPACE__
.
'\_assoc_arg_array_to_string'
,
$command
[
'global_assoc'
]
);
if
(
true
===
$assoc_arg
[
1
]
)
{
$to_implode
=
array_merge
(
$to_implode
,
$global
);
$to_implode
[]
=
'--'
.
$assoc_arg
[
0
];
}
}
else
{
$to_implode
[]
=
sprintf
(
'--%1$s=%2$s'
,
$assoc_arg
[
0
],
$assoc_arg
[
1
]
);
$to_implode
=
array_merge
(
$to_implode
,
$command
[
'positional_args'
]
);
}
}
if
(
!
empty
(
$command
[
'local_assoc'
]
)
)
{
$local
=
array_map
(
__NAMESPACE__
.
'\_assoc_arg_array_to_string'
,
$command
[
'local_assoc'
]
);
$to_implode
=
array_merge
(
$to_implode
,
$local
);
}
}
$imploded
=
trim
(
implode
(
' '
,
$to_implode
)
);
$imploded
=
trim
(
implode
(
' '
,
$to_implode
)
);
...
@@ -228,3 +232,17 @@ function implode_parsed_command( $command ) {
...
@@ -228,3 +232,17 @@ function implode_parsed_command( $command ) {
return
$imploded
;
return
$imploded
;
}
}
/**
* Convert an associative arg's array representation to a string for WP-CLI
*
* @param array $assoc_arg Associative arg to convert.
* @return string
*/
function
_assoc_arg_array_to_string
(
$assoc_arg
)
{
if
(
true
===
$assoc_arg
[
1
]
)
{
return
'--'
.
$assoc_arg
[
0
];
}
else
{
return
sprintf
(
'--%1$s=%2$s'
,
$assoc_arg
[
0
],
$assoc_arg
[
1
]
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment