xwp / wp-cli-ssh

[OBSOLETE] Seamlessly run WP-CLI commands on a remote server via SSH
157 stars 14 forks source link

Quoting additional argument doesn't seem to work #21

Open danielpataki opened 9 years ago

danielpataki commented 9 years ago

I'm sure this is an error on my end since this would have been reported by now, but it seems I am unable to add parameters to a command. I would like to force install a theme which I am doing like this:

wp ssh "theme install wp-content/themes/theme.zip --force" --host=staging

The command produces the following error, as if the whole quoted string was the command name:

Error: 'theme install wp-content/themes/bitesizebio.zip --force' is not a registered wp command. See 'wp help'.

I tested the command on the server without wp-cli-ssh and theme install wp-content/themes/theme.zip --force works just fine. In addition, commands without parameters fail with the same error, eg: wp ssh 'plugin list' --host=staging

I am using the latest version of wp-cli-ssh and wp-cli itself.

Thanks so much for this awesome tool!

westonruter commented 9 years ago

You shouldn't need the quotes. It is designed to work without them.

davidallansson commented 9 years ago

@danielpataki did you resolve this issue? I'm facing the same right now.

The command i want to run works perfectly fine on the remote server, but when i execute it from my local environment i get the "is not a registered wp command."-error if i add a paramter or try to quote the command to be used.

In my case it happens when i add the --network parameter to the search-replace command. Trying to change the host used on a wpmu network.

wp ssh search-replace www.domain.com dev.domain.com --host=dev

This works fine. But it will only affect the main site.

wp ssh search-replace --network www.domain.com dev.domain.com --host=dev

This will not work. It complains that --network is a unknown parameter. Error: Parameter errors: unknown --network parameter

wp ssh "search-replace --network www.domain.com dev.domain.com" --host=dev

This should work accordingly to the documentation. But it dosen't. Connecting via ssh to host: dev Error: 'search-replace --network www.domain.com dev.domain.com' is not a registered wp command. See 'wp help'.

For me it looks like wp-cli-ssh dosen't work with quotes anymore. And the quotes will be needed if you want to add parameters to the remote command?

danielpataki commented 9 years ago

Hi there @davidallansson,

Sorry to @westonruter, I didn't notice his answer. I can't really try this out just now but I don't remember figuring it out. Since I can't try it out now I can't say but I get the feeling it wont work without quotes.

Daniel

lkraav commented 9 years ago

This definitely does not work right now, just like the OP says

$ [-] wp ssh plugin activate ewww-image-optimizer --network --host=production
Error: Parameter errors:
 unknown --network parameter
$ [-] wp cli info
PHP binary:     /usr/lib64/php5.6/bin/php
PHP version:    5.6.9-pl0-gentoo
php.ini used:   /etc/php/cli-php5.6/php.ini
WP-CLI root dir:        /home/leho/wp-cli
WP-CLI global config:   /home/leho/.wp-cli/config.yml
WP-CLI project config:  /home/warmpress/wp-cli.yml
WP-CLI version: 0.19.1
lkraav commented 9 years ago

Anybody here have any idea about how to go about debugging this? Secondary parameters not working are essentially killing all ability to wp ssh.

jonathanbardo commented 9 years ago

@lkraav I think I found the little issue. Please test my pull request and tell me if it works for you.

A little tweak in the synopsis was all it tooks. Sorry it took me so long to get to it!

lkraav commented 9 years ago

It worksssssssss. Ty sir!

Probably not fully on topic here, but is bash-completion not supposed to work for wp-cli-ssh? Everything up to wp ssh --host completes, but host definitions can not be completed, nor anything after.

jonathanbardo commented 9 years ago

The nature of the plugin makes it difficult to have bash completion since we are proxying the request to somewhere else. Would be a good improvement though :wink:

westonruter commented 9 years ago

Yeah, Bash completion would really only be feasible if we were able to figure out #15, caching an SSH connection to speed up calls.

aj-adl commented 8 years ago

I'd just like to raise that this issue is still a problem, doing some digging in xDebug, it originally stems from the way you are accessing arguments at the beginning of __invoke.

The loop of

 foreach ( array_slice( $GLOBALS['argv'], 2 ) as  $arg ) {}

will result in an array like

$cli_args = [ 
    0 => 'search-replace foo bar --skip-tables'
];

where as the desired outcome would be

$cli_args = [ 
    0 => 'search-replace', 
    1 => 'foo',
    2 => 'bar',
    3 => '--skip-tables'
];

While the commands do get concatenated back together as a string later, this incorrect grouping means that the call to escapeshellarg will wrap the whole command in quotes, so WP-CLI on the remote server will try and execute a command called wp 'search-replace foo bar --skip-tables'

I'm evaluating a few different options to fix, I'll submit a PR for review when done. Originally I tried just exploding the string on spaces, and it worked for my particular use case - but there will be some commands that will have 'legitimate' spaces inside quotes so a regexp solution is looking likely.

My first attempt worked but has one too many layers of escapeshellarg called on the single quotes so you end up with values like plugin name: 'my plugin name'