Skip to content

CLI tutorials #642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 35 commits into from
Jul 21, 2022
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a353d3a
first crack at commands
cholmes Jun 16, 2022
8e81085
Revert "first crack at commands"
cholmes Jun 16, 2022
742434a
first crack at commands
cholmes Jun 16, 2022
f69775f
more examples
cholmes Jun 21, 2022
1ea9408
first commit, mostly placeholder
cholmes Jun 21, 2022
28dcb77
more additions
cholmes Jun 22, 2022
b62b0b5
another thing to add
cholmes Jun 22, 2022
5ce0a71
Merge branch 'main' into cli-tutorial
cholmes Jun 27, 2022
4bbb895
Merge branch 'main' into cli-tutorial
cholmes Jun 27, 2022
8a291c4
more improvements
cholmes Jun 28, 2022
8aaea27
initial commit of more advanced tutorial stuff
cholmes Jun 28, 2022
4650354
minor changes
cholmes Jun 29, 2022
828f19f
added a nice way to not copy/paste order ids
cholmes Jul 1, 2022
d9dc58f
Merge branch 'main' into cli-tutorial
cholmes Jul 12, 2022
fe2b23f
more updates
cholmes Jul 15, 2022
18e49ca
improvements
cholmes Jul 16, 2022
eb63965
finishing off the first pass
cholmes Jul 17, 2022
4696700
more improvements
cholmes Jul 17, 2022
5e5a524
more kepler info
cholmes Jul 18, 2022
b998300
small fixes
cholmes Jul 18, 2022
518130e
more improvements
cholmes Jul 19, 2022
087770b
changed quick-search to search, updates
cholmes Jul 19, 2022
302ab93
added warning messages, more info
cholmes Jul 20, 2022
0e02559
added note to add centroid with gdal
cholmes Jul 20, 2022
11865a6
Merge branch 'main' into cli-tutorial
cholmes Jul 20, 2022
50916aa
Update docs/cli-concepts.md
cholmes Jul 20, 2022
db90a03
Update docs/cli-tutorial.md
cholmes Jul 20, 2022
7839a5b
Update docs/cli-concepts.md
cholmes Jul 20, 2022
a2d97ae
Update docs/cli-plus-tutorial.md
cholmes Jul 20, 2022
fef2254
added to ToC, improvements
cholmes Jul 21, 2022
ba11ed2
added request geojson to be in this repo
cholmes Jul 21, 2022
444e4e2
added clip-composite request
cholmes Jul 21, 2022
14459a4
update paths
cholmes Jul 21, 2022
3c0bbbb
moved to data directory
cholmes Jul 21, 2022
dcdc4c6
Merge branch 'main' into cli-tutorial
cholmes Jul 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions docs/cli-concepts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Command-line Interface (CLI) Concepts

Planet's command-line interface is built of composable pieces that combine in powerful ways.
To take full advantage of all that Planet's CLI offers there are a few concepts and tools
that are worth explaining.

**NOTE:** This document is still a work in progress, but we'll work to flesh it out. We'll
leave it up since there's still a bit of good information.

## Core Unix Concepts

If you are completely new to the command-line we recommend starting with a real introductory
guide like (TODO, link to a good guide). But we wanted to go over a few key concepts that
are a bit more 'advanced', as they allow you to get the most out of Planet's CLI. These are
all built into any unix command-line, including Linux and the Mac terminal. If you're on
Windows you can use [Windows Subsytem for Linux](https://docs.microsoft.com/en-us/windows/wsl/about)
or [Cygwin](https://www.cygwin.com/).

### Piping & Redirection

Several commands in the Planet CLI are used to create files that are used as input to
other commands. The default of these commands is to just print the output on your screen.
Seeing it on the screen can be useful for making sure it's right, but you'll most likely
want to make use of it. This is where the concept of 'redirection' comes in. If you use the
`>` character and then specify a file name the command-line will save its output to that file.
So if you say:

```
planet data filter --range cloud_percent lt 10 > filter.json
```

Then the output will be saved. This output is referred to as STDOUT, or 'standard output'.
There is much more in this vein that you can do, like use `>>` to append to an existing
file, or `<` to send what's in the file as input for a command.

One of the most powerful concepts that we use extensively in the Planet CLI is 'piping'.
The `|` is the pipe symbol, and it's a special command that lets you pass the output from
one command to be the input for the next one. So instead of having to save to a file and
then referring to it you can just do it all in one call:

```
planet data filter --range cloud_percent lt 10 | planet data search-quick PSScene -
```

The pipe says to take the output of the first command and pass it to the input of
the second. You'll notice that the planet command has a dash (`-`), this is a convention
that is often used by different CLI programs to explicitly say 'read from
standard out'. Most Planet CLI commands require it, but one or two will implicitly
read from standard out if it's not explicitly included. Using the dash to mean
'read from standard out' is a general convention used by many programs, but it's
not universal, so check the docs of the program you're using as to how it reads
from piped input. For example GDAL/OGR uses a specific `/vsistdin/` convention to
read from a pipe.

If you'd like to learn more about these topics then check out
[this tutorial](https://ryanstutorials.net/linuxtutorial/piping.php). And if you'd
like to learn more about the dash (`-`) see
[this tutorial](https://www.baeldung.com/linux/dash-in-command-line-parameters).


### head & tail

Also less/more?

### Running a command within another

### variables

## JQ

## curl

## sed

Loading