|
| 1 | +# Command-line Interface (CLI) Concepts |
| 2 | + |
| 3 | +Planet's command-line interface is built of composable pieces that combine in powerful ways. |
| 4 | +To take full advantage of all that Planet's CLI offers there are a few concepts and tools |
| 5 | +that are worth explaining. |
| 6 | + |
| 7 | +**NOTE:** This document is still a work in progress, but we'll work to flesh it out. We'll |
| 8 | +leave it up since there's still a bit of good information. |
| 9 | + |
| 10 | +## Core Unix Concepts |
| 11 | + |
| 12 | +If you are completely new to the command-line we recommend starting with a real introductory |
| 13 | +guide like (TODO, link to a good guide). But we wanted to go over a few key concepts that |
| 14 | +are a bit more 'advanced', as they allow you to get the most out of Planet's CLI. These are |
| 15 | +all built into any unix command-line, including Linux and the Mac terminal. If you're on |
| 16 | +Windows you can use [Windows Subsytem for Linux](https://docs.microsoft.com/en-us/windows/wsl/about) |
| 17 | +or [Cygwin](https://www.cygwin.com/). |
| 18 | + |
| 19 | +### Piping & Redirection |
| 20 | + |
| 21 | +Several commands in the Planet CLI are used to create files that are used as input to |
| 22 | +other commands. The default of these commands is to just print the output on your screen. |
| 23 | +Seeing it on the screen can be useful for making sure it's right, but you'll most likely |
| 24 | +want to make use of it. This is where the concept of 'redirection' comes in. If you use the |
| 25 | +`>` character and then specify a file name the command-line will save its output to that file. |
| 26 | +So if you say: |
| 27 | + |
| 28 | +``` |
| 29 | + planet data filter --range cloud_percent lt 10 > filter.json |
| 30 | +``` |
| 31 | + |
| 32 | +Then the output will be saved. This output is referred to as STDOUT, or 'standard output'. |
| 33 | +There is much more in this vein that you can do, like use `>>` to append to an existing |
| 34 | +file, or `<` to send what's in the file as input for a command. |
| 35 | + |
| 36 | +One of the most powerful concepts that we use extensively in the Planet CLI is 'piping'. |
| 37 | +The `|` is the pipe symbol, and it's a special command that lets you pass the output from |
| 38 | +one command to be the input for the next one. So instead of having to save to a file and |
| 39 | +then referring to it you can just do it all in one call: |
| 40 | + |
| 41 | +``` |
| 42 | +planet data filter --range cloud_percent lt 10 | planet data search-quick PSScene - |
| 43 | +``` |
| 44 | + |
| 45 | +The pipe says to take the output of the first command and pass it to the input of |
| 46 | +the second. You'll notice that the planet command has a dash (`-`), this is a convention |
| 47 | +that is often used by different CLI programs to explicitly say 'read from |
| 48 | +standard out'. Most Planet CLI commands require it, but one or two will implicitly |
| 49 | +read from standard out if it's not explicitly included. Using the dash to mean |
| 50 | +'read from standard out' is a general convention used by many programs, but it's |
| 51 | +not universal, so check the docs of the program you're using as to how it reads |
| 52 | +from piped input. For example GDAL/OGR uses a specific `/vsistdin/` convention to |
| 53 | +read from a pipe. |
| 54 | + |
| 55 | +If you'd like to learn more about these topics then check out |
| 56 | +[this tutorial](https://ryanstutorials.net/linuxtutorial/piping.php). And if you'd |
| 57 | +like to learn more about the dash (`-`) see |
| 58 | +[this tutorial](https://www.baeldung.com/linux/dash-in-command-line-parameters). |
| 59 | + |
| 60 | + |
| 61 | +### head & tail |
| 62 | + |
| 63 | +Also less/more? |
| 64 | + |
| 65 | +### Running a command within another |
| 66 | + |
| 67 | +### variables |
| 68 | + |
| 69 | +## JQ |
| 70 | + |
| 71 | +## curl |
| 72 | + |
| 73 | +## sed |
| 74 | + |
0 commit comments