Title: Retrieving command being executed by WP-CLI
Last modified: October 27, 2023

---

# Retrieving command being executed by WP-CLI

 *  Resolved [faridjc](https://wordpress.org/support/users/faridjc/)
 * (@faridjc)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/retrieving-command-being-executed-by-wp-cli/)
 * I’m trying to find a way to retrieve the command being executed by WP-CLI (or
   the list of arguments) from a plugin.
 * Is that possible? I searched the WP-CLI API documentation but couldn’t find a
   function that made is possible.
    -  This topic was modified 2 years, 5 months ago by [faridjc](https://wordpress.org/support/users/faridjc/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Moderator [Jose Castaneda](https://wordpress.org/support/users/jcastaneda/)
 * (@jcastaneda)
 * THEME COFFEE MONKEY
 * [2 years, 5 months ago](https://wordpress.org/support/topic/retrieving-command-being-executed-by-wp-cli/#post-17156234)
 * Hi there!
 * My initial question on this would be what are you actually trying to do?
 *  Thread Starter [faridjc](https://wordpress.org/support/users/faridjc/)
 * (@faridjc)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/retrieving-command-being-executed-by-wp-cli/#post-17156787)
 * Hello there!
 * I’m trying to prevent a function from continue its execution if the current request
   comes from WP-CLI and the command is neither “plugin list” or “plugin update”
 * I came up with this solution, it could be cleaner, but it works:
 *     ```wp-block-code
       if ( defined( 'WP_CLI' ) ) {
            $args = $GLOBALS['argv'] ?? array();
            $exit = true;
   
            foreach ( $args as $i => $argument ) {
   
                 if ( 'plugin' === $argument && ( 'list' === $args[ $i + 1 ] || 'update' === $args[ $i + 1 ] ) ) {
   
                      $exit = false;
   
                      break;
   
                  }
   
            }
   
            if ( $exit ) {
                 return;
            }
       }
       ```
   
    -  This reply was modified 2 years, 5 months ago by [faridjc](https://wordpress.org/support/users/faridjc/).

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Retrieving command being executed by WP-CLI’ is closed to new replies.

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)
 * [command](https://wordpress.org/support/topic-tag/command/)
 * [wp-cli](https://wordpress.org/support/topic-tag/wp-cli/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 2 replies
 * 2 participants
 * Last reply from: [faridjc](https://wordpress.org/support/users/faridjc/)
 * Last activity: [2 years, 5 months ago](https://wordpress.org/support/topic/retrieving-command-being-executed-by-wp-cli/#post-17156787)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
