#!/bin/bash
MODE=$1
if [[ -z $2 ]];then HEADTAIL_LIMIT=0; else HEADTAIL_LIMIT=$2;fi
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/../.."
source scripts/funcs

echo "## Running a task locally

In this section, we will learn how to run a task with handoff locally,
using project 01_word_count.
"

Prompt "Ready? (Hit q at prompt to quit anytime. Any other key to proceed.)"

echo "
Each project directory contains:
"

ListDir "01_word_count" 

Prompt

echo "
project.yml looks like:
"

Cat "01_word_count/project.yml" 

Prompt

echo '
Here,

- `commands` lists the commands and arguments.
- `envs` lists the environment varaibles.
'

echo "
The example from 01_word_count runs a command line equivalent of:
"

Code "cat ./files/the_great_dictator_speech.txt | wc -w" 

echo "
Now let's run. Try entering this command below:
"

Command "handoff --project 01_word_count --workspace workspace run local" 

Prompt

echo "
If you see the output that looks like:
"

Code "\n
INFO - 2020-08-03 04:51:01,971 - handoff.config - Reading configurations from 01_word_count/project.yml\n
...\n
INFO - 2020-08-03 04:51:02,690 - handoff.config - Processed in 0:00:00.005756\n
" 

Prompt

echo "
Then great! You just ran the first local test. It created a workspace
directory that looks like:
"

ListDir workspace 

echo "
And the word count is stored at workspace/artifacts/state. Here is the content:
"

Cat " workspace/artifacts/state" 

Prompt

echo "
By the way, the example text is from the awesome speech by Charlie Chaplin's
in the movie the Great Dictator.

Here is a link to the famous speech scene.
Check out on YouTube: https://www.youtube.com/watch?v=J7GY1Xg6X20
"

Prompt

echo "
And here is the first few paragraphs of the text:
"

Run "head -n 4 01_word_count/files/the_great_dictator_speech.txt" $BLUE 0

Prompt

echo "
Now to the second example. This time project.yml looks like:
"

Cat 02_collect_stats/project.yml 

Prompt

echo "
...which is shell equivalent to
"

Code "cat ./files/the_great_dictator_speech.txt | python ./files/stats_collector.py | wc -w" 

echo "
The script for the second command stats_collector.py can be found in
02_collect_stats/files directory and it is a Python script that looks like:
"

Prompt

Cat "02_collect_stats/files/stats_collector.py" 

echo "
The script reads from stdin and counts the lines while passing the raw input to stdout.
The raw text is then processed by the third command (wc -w) and it conts the number of words.
"

Prompt

echo "
Now let's run. Try entering this command below:
"

Command "handoff --project 02_collect_stats --workspace workspace run local" $DIM 0

echo "
Let's check out the contents of the second command:
"

Prompt

Cat "workspace/artifacts/collect_stats.json" $DIM 0

Prompt

Thanks

echo "
In the next section, we will try pullin the currency exchange rate data.
You will also learn how to create Python virtual enviroments for each command
and pip-install commands.
"

Continue scripts/aws_get_started/02_exchange_rates
