Skip to content
This repository has been archived by the owner on Dec 10, 2020. It is now read-only.

Latest commit

 

History

History
821 lines (502 loc) · 8.38 KB

deck.mdx

File metadata and controls

821 lines (502 loc) · 8.38 KB

import { Split, Appear, Head, FullScreenCode, Image, } from 'mdx-deck' import { code, prism } from '@mdx-deck/themes'

export const themes = [ code, prism ]

import iterm from './images/iterm.png'

<title>CLI Tools at VIP</title>

CLI Tools at VIP

Alexis Kulash

Nick Daugherty


CLI

Command Line Interface


"...a means of interacting with a computer program where the user issues commands to the program in the form of successive lines of text."

Why CLI?


  • Control
  • Repeatable
  • Automation
  • Shareable
  • Speed
  • Development Speed

Game Plan


  • Basic Examples
  • Shell Tricks
  • WP CLI
  • VIP CLI
  • VIP Go CLI
  • Q & A

Basic Examples


List files


$ ls

$ ls
README.md		node_modules		now.json		package.json
deck.mdx		notes.md		package-lock.json	theme.js

Arguments


$ ls content

$ ls content
camels.mp4	camels.txt	cats.gif	otters.jpg

Exercise

List all the files on your desktop via CLI


Options


$ ls -l content

$ ls -l content
total 11624
-rw-rw-rw-@ 1 vip  staff   431015 Oct 15 16:35 camels.mp4
-rw-r--r--  1 vip  staff    10155 Oct 15 16:55 camels.txt
-rw-rw-rw-@ 1 vip  staff  4693925 Oct 15 16:33 cats.gif
-rw-rw-rw-@ 1 vip  staff   141734 Oct 15 16:40 otters.jpg

$ ls -a content

$ ls -a content
.		..		.hidden-file	camels.mp4	camels.txt  cats.gif	otters.jpg

Combining options


$ ls -la content

$ ls -la content
total 11624
drwxr-xr-x   6 vip  staff  192 Oct 15 16:28 .
drwxr-xr-x  13 vip  staff  416 Oct 15 16:27 ..
-rw-r--r--   1 vip  staff    0 Oct 15 16:28 .hidden-file
-rw-r--r--   1 vip  staff    0 Oct 15 16:26 camels.mp4
-rw-r--r--   1 vip  staff    10155 Oct 15 16:55 camels.txt
-rw-r--r--   1 vip  staff    0 Oct 15 16:26 cats.gif
-rw-r--r--   1 vip  staff    0 Oct 15 16:26 otters.jpg

Sending output to a file


$ ls content > files.txt

Where's my output???


$ cat files.txt

$ cat files.txt
camels.mp4
cats.gif
otters.jpg

Reading input from a file


$ less < content/camels.txt

$ less < content/camels.txt
A camel is an even-toed ungulate...
:

$ less < content/camels.txt
A camel is an even-toed ungulate...
The word camel is derived via Latin
:

Input from another command


$ cat content/camels.txt | less

$ cat content/camels.txt | less
A camel is an even-toed ungulate...
:

$ cat content/camels.txt | less
A camel is an even-toed ungulate...
The word camel is derived via Latin
:

Building from another command


$ find content -name "*.mp4" | xargs -I % open %

$ find content -name "*.mp4" | xargs -tI % open %

Shell Tricks


Tab completion

Save typing with filename autocomplete


$ cat content/

$ cat content/

$ cat content/
.hidden-file  camels.mp4    camels.txt    cats.gif      otters.jpg

$ cat content/ca

$ cat content/ca
camels.mp4  camels.txt  cats.gif

$ cat content/camels.t

$ cat content/camels.txt

History

Use up/down arrows to access previous commands


man pages

Manual pages with commmand info


$ man curl

Multiple windows


<Image src={ iterm } />


WP CLI


Control WP from the command line

developer.wordpress.org/cli/commands


Get sandboxed


$ vipgo sandbox start vip-test.go-vip.co

$ wp help

$ wp help

NAME

  wp

DESCRIPTION

  Manage WordPress through the command-line.

SYNOPSIS

  wp <command>

SUBCOMMANDS

  akismet                      Filter spam comments.
  cache                        Adds, removes, fetches, and flushes the WP Object Cache object.
  cap                          Adds, removes, and lists capabilities of a user role.
  cli                          Review current WP-CLI info, check for updates, or see defined aliases.
  co-authors-plus              Co-Authors Plus commands for the WP-CLI framework
:

$ wp help post

Exercise

Save the ID and title of all posts as a CSV in post_ids.csv


wp post generate

Create new posts with dummy data


$ wp help post generate

wp user create

Create new users


$ wp help user create

wp site list

List all sites in a multisite environment


$ wp help site list

Exercise

List the themes for each site on multisite-demo.go-vip.co using xargs


wp shell

Execute arbitrary PHP code


$ wp shell

$ wp shell
wp>

$ wp shell
wp> get_post( 2323 );

$ wp shell
wp> get_post( 2323 );
class WP_Post#3083 (24) {
  public $ID =>
  int(2323)
  public $post_author =>
  string(1) "0"
  public $post_date =>
  string(19) "1999-01-19 18:01:13"
  public $post_date_gmt =>
  string(19) "1970-01-01 00:00:00"
  public $post_content =>

vip CLI


Control VIP from the command line


Run WP CLI without sandboxing


$ vip @297.testing -- wp post get 2323

Pseudo-shell


$ vip @297.testing -- wp

$ vip @297.testing -- wp
Welcome to the WP CLI shell for the testing environment of vip-test (vip-test.go-vip.co)!
vip-test.testing:~$

$ vip @297.testing -- wp
Welcome to the WP CLI shell for the testing environment of vip-test (vip-test.go-vip.co)!
vip-test.testing:~$ wp post list

Exercise

Using vip, get the value cached for the key "alloptions" in the "options" group on site 297 (vip-test.go-vip.co)


vipgo CLI


Control VIP from the command line


$ vipgo -h

$ vipgo api -h

API Requests


$ vipgo api get "/sites?search=test&pagesize=3"

Database Queries


$ vipgo db vip-test.go-vip.co

Probes


$ vipgo probe memcached --container=42088

$ vipgo probe node --container=59291

$ vipgo probe list --type memcached --site 297

Questions?